From 1b7fff91b4adf903fd1ee0485274e095a00af523 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Fri, 24 Apr 2026 21:25:29 +0800 Subject: Arduino Due post. --- _log/arduino-due.md | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/_log/arduino-due.md b/_log/arduino-due.md index 900098d..1330dbf 100644 --- a/_log/arduino-due.md +++ b/_log/arduino-due.md @@ -1,13 +1,9 @@ --- -title: Bare-metal ATSAM3X8E +title: Bare-metal ATSAM3X8E (Arduino Due) date: 2024-09-16 layout: post --- -Bought an Arduino Due to play with ARM Cortex chips. Locked out of the chip for -days—no dev tools (Arduino IDE, Microchip Studio) for OpenBSD. Need to find a -way to bring up the bare-metal ATSAM3X8E. - Three on-chip memories: ROM, flash0, flash1. ARM Cortex-M chips boot into 0x00000. GPNVM bits map one of them to 0x00000: @@ -16,8 +12,8 @@ Three on-chip memories: ROM, flash0, flash1. ARM Cortex-M chips boot into - GPNVM1=1 and GPNVM2=1 → flash1. On power-up, control jumps to ROM. Without a user program, Atmel's SAM-BA -bootloader traps execution in ROM. Must remap memory via SWD to force chip to -boot from flash, bypassing factory bootloader. +bootloader traps execution in the ROM. Must remap memory via SWD to force chip +to boot from flash, bypassing factory bootloader. Toolchain: ST-LINK/V2 programmer, OpenOCD, ARM GNU Compiler Toolchain. @@ -49,8 +45,7 @@ $ telnet localhost 4444 Full command list in OpenOCD manual AT91SAM3 (flash driver section). -At a minimum, vector table must be initialized with stack pointer and reset -vector: +Initialize vector table with the stack pointer and the reset vector: ``` __attribute__((noreturn)) void _reset(void) @@ -72,8 +67,8 @@ extern const unsigned int _sp; __attribute__ ((section(".vtor"))) const void* _tab[] = { &_sp, _reset }; ``` -Linker script places vector table at start of flash0 and initializes stack -pointer to top of RAM (descending stack): +Linker script: Place the vector table at the start of flash0 and initialize the +stack pointer to the top of the RAM: ``` MEMORY @@ -95,11 +90,7 @@ SECTIONS _sp = ORIGIN(ram) + LENGTH(ram); ``` -Getting linker script right wasn't easy—long hours with the datasheet, OpenOCD -manual. David Barrass from OpenBSD and folks at OpenOCD mailing lists (bless -them!) helped generously. - -Build and upload program: +Build and upload the program: ``` $ arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -T script.ld \ @@ -109,8 +100,6 @@ $ arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -T script.ld \ $ openocd -f openocd-due.cfg -c "program a.elf verify reset exit" ``` -Chip unlocked. I'm in. - Commit: 3184969. -- cgit v1.2.3