From a8d7508006db8309550755a72719de83bde3cdd9 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Fri, 5 Jun 2026 21:00:02 +0800 Subject: Improve writing. --- _log/arduino-due.md | 52 ++++++++++------------------------------------------ 1 file changed, 10 insertions(+), 42 deletions(-) (limited to '_log/arduino-due.md') diff --git a/_log/arduino-due.md b/_log/arduino-due.md index 1330dbf..a55122c 100644 --- a/_log/arduino-due.md +++ b/_log/arduino-due.md @@ -4,21 +4,8 @@ date: 2024-09-16 layout: post --- -Three on-chip memories: ROM, flash0, flash1. ARM Cortex-M chips boot into -0x00000. GPNVM bits map one of them to 0x00000: - - - GPNVM1=0 → ROM (default). - - GPNVM1=1 and GPNVM2=0 → flash0. - - 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 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. -Connect ST-LINK/v2 to Arduino Due's DEBUG port: -
@@ -32,7 +19,10 @@ Connect ST-LINK/v2 to Arduino Due's DEBUG port:
-Remap memory using OpenOCD: +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 @@ -43,32 +33,8 @@ $ telnet localhost 4444 > at91sam3 gpnvm show ``` -Full command list in OpenOCD manual AT91SAM3 (flash driver section). - -Initialize vector table with the stack pointer and the reset vector: - -``` -__attribute__((noreturn)) void _reset(void) -{ - unsigned long *dst, *src; - extern unsigned long _sbss, _ebss; - extern unsigned long _sdata, _edata, _sidata; - - for (dst = &_sbss; dst < &_ebss; dst++) - *dst = 0; - for (dst = &_sdata, src = &_sidata; dst < &_edata;) - *dst++ = *src++; - - main(); -} - -extern const unsigned int _sp; - -__attribute__ ((section(".vtor"))) const void* _tab[] = { &_sp, _reset }; -``` - -Linker script: Place the vector table at the start of flash0 and initialize the -stack pointer to the top of the RAM: +Place the vector table at the start of flash0 and initialize the stack pointer +to the top of the RAM: ``` MEMORY @@ -81,13 +47,15 @@ SECTIONS { .text : { - KEEP(*(.vtor)) + KEEP(*(.vtor)) /* Vector table defined in main.c */ *(.text*) *(.rodata*) } > rom + + /* Data, bss sections */ } -_sp = ORIGIN(ram) + LENGTH(ram); +_sp = ORIGIN(ram) + LENGTH(ram); /* Descending stack */ ``` Build and upload the program: -- cgit v1.2.3