--- title: Bare-metal ATSAM3X8E (Arduino Due) date: 2024-09-16 layout: post --- Toolchain: ST-LINK/V2 programmer, OpenOCD, ARM GNU Compiler Toolchain.
Pinout

Wiring

Circuit

Arduino Due

ATSAM3X8E boots into 0x00000, which is mapped to ROM. ROM contains the SAM-BA bootloader. Remap start address to flash0 (flash driver section, OpenOCD manual AT91SAM3): ``` $ openocd -f openocd-due.cfg $ telnet localhost 4444 > halt > at91sam3 gpnvm show > at91sam3 gpnvm set 1 > at91sam3 gpnvm show ``` Place the vector table at the start of flash0 and initialize the stack pointer to the top of the RAM: ``` MEMORY { rom (rx) : ORIGIN = 0x00080000, LENGTH = 512K ram (rwx) : ORIGIN = 0x20000000, LENGTH = 96K } SECTIONS { .text : { KEEP(*(.vtor)) /* Vector table defined in main.c */ *(.text*) *(.rodata*) } > rom /* Data, bss sections */ } _sp = ORIGIN(ram) + LENGTH(ram); /* Descending stack */ ``` Build and upload the program: ``` $ arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -T script.ld \ -nostartfiles \ -nostdlib \ -o a.elf main.c $ openocd -f openocd-due.cfg -c "program a.elf verify reset exit" ``` Commit: 3184969.