diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2024-09-09 20:18:14 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2024-09-09 20:18:14 +0800 |
| commit | a2cff11cb50dca70fb4869e6ed7188504a398e27 (patch) | |
| tree | e26877a65d4223b487c6d521f1b8d1c3e6f0c908 | |
| parent | ccbba4c08477e8944aa8e64abfe8c8cfd6b7c5c9 (diff) | |
| download | bare-metal-arduino-due-a2cff11cb50dca70fb4869e6ed7188504a398e27.tar.gz | |
Linker script and a bunch of important fixes.
| -rw-r--r-- | Makefile | 25 | ||||
| -rw-r--r-- | README.txt | 5 | ||||
| -rw-r--r-- | main.c | 25 | ||||
| -rw-r--r-- | openocd-due.cfg | 12 | ||||
| -rw-r--r-- | script.ld | 35 |
5 files changed, 86 insertions, 16 deletions
@@ -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 @@ -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; +} |
