From a2cff11cb50dca70fb4869e6ed7188504a398e27 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Mon, 9 Sep 2024 20:18:14 +0800 Subject: Linker script and a bunch of important fixes. --- Makefile | 25 +++++++++---------------- README.txt | 5 +++++ main.c | 25 +++++++++++++++++++++++++ openocd-due.cfg | 12 ++++++++++++ script.ld | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 86 insertions(+), 16 deletions(-) create mode 100644 README.txt create mode 100644 main.c create mode 100644 openocd-due.cfg create mode 100644 script.ld diff --git a/Makefile b/Makefile index da8a267..846d463 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -CC = avr-gcc -MCU = atmega328p -TARGET = inmp +CC = arm-none-eabi-gcc +CPU = cortex-m3 +TARGET = due SRC = main.c OBJ = $(SRC:.c=.o) @@ -8,22 +8,15 @@ OBJ = $(SRC:.c=.o) CFLAGS = -std=gnu99 CFLAGS += -Os CFLAGS += -Wall -CFLAGS += -mmcu=$(MCU) -CFLAGS += -DBAUD=115200 -CFLAGS += -DF_CPU=16000000UL -CFLAGS += -ffunction-sections -fdata-sections +CFLAGS += -mcpu=$(CPU) +CFLAGS += -mthumb -LDFLAGS = -mmcu=$(MCU) +LDFLAGS = -mcpu=$(CPU) LDFLAGS += -Wl,--gc-sections HEX_FLAGS = -O ihex HEX_FLAGS += -j .text -j .data -AVRDUDE_FLAGS = -p $(MCU) -AVRDUDE_FLAGS += -c arduino -AVRDUDE_FLAGS += -P /dev/cuaU0 -AVRDUDE_FLAGS += -D -U - %.o: %.c $(CC) $(CFLAGS) -c -o $@ $< @@ -31,10 +24,10 @@ elf: $(OBJ) $(CC) $(LDFLAGS) $(OBJ) -o $(TARGET).elf hex: elf - avr-objcopy $(HEX_FLAGS) $(TARGET).elf $(TARGET).hex + arm-none-eabi-objcopy $(HEX_FLAGS) $(TARGET).elf $(TARGET).hex -upload: hex - avrdude $(AVRDUDE_FLAGS) flash:w:$(TARGET).hex:i +#upload: hex +# openocd -f openocd-due.cfg -c "program $(TARGET) verify reset exit" .PHONY: clean diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..ab93862 --- /dev/null +++ b/README.txt @@ -0,0 +1,5 @@ +Compile and upload + +$ arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -o a.elf main.c +$ arm-none-eabi-objcopy -O ihex -j .text -j .data a.elf a.hex +$ avrdude -c arduino -p atmel_sam3x8e -v -b 115200 -U flash:w:a.hex diff --git a/main.c b/main.c new file mode 100644 index 0000000..137e093 --- /dev/null +++ b/main.c @@ -0,0 +1,25 @@ +#define PIOC_PER *((volatile unsigned int *) 0x400E1200U) +#define PIOC_OER *((volatile unsigned int *) 0x400E1210U) +#define PIOC_IDR *((volatile unsigned int *) 0x400E1244U) +#define PIOC_CODR *((volatile unsigned int *) 0x400E1234U) +#define PIOC_IFDR *((volatile unsigned int *) 0x400E1224U) +#define PIOC_MDDR *((volatile unsigned int *) 0x400E1254U) +#define PIOC_ODSR *((volatile unsigned int *) 0x400E1238U) +#define PIOC_PUDR *((volatile unsigned int *) 0x400E1260U) +#define PIOC_OWDR *((volatile unsigned int *) 0x400E12A4U) + +int main(void) +{ + PIOC_PER = 0x00000001; + PIOC_OER = 0x00000001; + PIOC_IDR = 0x00000001; + PIOC_CODR = 0x00000001; + PIOC_IFDR = 0x00000001; + PIOC_MDDR = 0x00000001; + PIOC_PUDR = 0x00000001; + PIOC_OWDR = 0x00000001; + + PIOC_ODSR = 0x00000001; + + return 0; +} diff --git a/openocd-due.cfg b/openocd-due.cfg new file mode 100644 index 0000000..8fba185 --- /dev/null +++ b/openocd-due.cfg @@ -0,0 +1,12 @@ +source [find interface/stlink.cfg] + +#transport type SWD +transport select hla_swd + +#swd frequency +adapter speed 1800 + +#sam3x8e cpuid +set CPUTAPID 0x2ba01477 + +source [find target/at91sam3ax_8x.cfg] diff --git a/script.ld b/script.ld new file mode 100644 index 0000000..e8b0bb1 --- /dev/null +++ b/script.ld @@ -0,0 +1,35 @@ +MEMORY +{ + rom (rx) : ORIGIN = 0x00080000, LENGTH = 0x00080000 + ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00010000 +} + +SECTIONS +{ + . = ALIGN(4); + .text : + { + KEEP(*(.vectors .vectors.*)) + *(.text*) + *(.rodata*) + } > rom + + . = ALIGN(4); + .data : + { + *(.data*); + } > ram AT >rom + + . = ALIGN(4); + .bss (NOLOAD) : + { + __bss_start__ = . ; + *(.bss*) + *(COMMON) + __bss_end__ = . ; + } > ram + + _end = . ; + __end__ = _end ; + end = _end; +} -- cgit v1.2.3