summaryrefslogtreecommitdiffstats
path: root/_log/arduino-due.md
diff options
context:
space:
mode:
Diffstat (limited to '_log/arduino-due.md')
-rw-r--r--_log/arduino-due.md52
1 files changed, 10 insertions, 42 deletions
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:
-
<table style="border: none; width: 100%;">
<tr style="border: none;">
<td style="border: none; width: 50%; vertical-align: top; background-color: transparent;">
@@ -32,7 +19,10 @@ Connect ST-LINK/v2 to Arduino Due's DEBUG port:
</tr>
</table>
-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: