I'm trying to compile a simple project for a TM4C123GXL microcontroller using arm-none-eabi-gcc. Inside main
I call memcpy
just to test that it works as expected, but it causes a fault. Inside the disassembly of memcpy
one of the first instructions is b.n 0xc7a
, which takes the CPU to some unused segment of flash. It's as though memcpy
expects some other function to be at that location, but I can't figure out why that would be an issue. It compiles without any warnings or errors.
Here is the Makefile I'm using:
PROJECT = main
SRCS = $(wildcard src/*.c)
OBJ = obj/
OBJS = $(addprefix $(OBJ), $(notdir $(SRCS:.c=.o)))
INC = inc/
LD_SCRIPT = TM4C123GH6PM.ld
CC = arm-none-eabi-gcc
LD = arm-none-eabi-ld
OBJCOPY = arm-none-eabi-objcopy
RM = rm -rf
MKDIR = @mkdir -p $(@D)
CFLAGS = -ggdb3 -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16
CFLAGS += -mfloat-abi=softfp -MD -std=c99 -c -Wextra -Wall -Wno-missing-braces
all: bin/$(PROJECT).elf
$(OBJ)%.o: src/%.c
$(MKDIR)
$(CC) -o $@ $^ -I$(INC) $(CFLAGS)
bin/$(PROJECT).elf: $(OBJS)
$(MKDIR)
$(CC) -o $@ $^ -Wl,-T $(LD_SCRIPT) -Wl,-e Reset_Handler
$(OBJCOPY) -O binary $@ bin/$(PROJECT).bin
clean:
-$(RM) obj
-$(RM) bin
And my main
:
#include <stdint.h>
#include <string.h>
int main(void){
uint8_t x[] = {1,2,3};
uint8_t y[] = {0,0,0};
uint8_t *xptr = x;
uint8_t *yptr = y;
memcpy(yptr, xptr, 3);
while (1)
;
}
And my Reset_Handler
, for good measure:
void Reset_Handler(void)
{
int *src, *dest;
/* copying of the .data values into RAM */
src = &_etext;
for (dest = &_data; dest < &_edata;)
{
*dest++ = *src++;
}
/* initializing .bss values to zero*/
for (dest = &__bss_start__; dest < &__bss_end__;)
{
*dest++ = 0;
}
main();
}
Is there something else I need to do in order to use Newlib's standard C library?