blob: a55122cfb495aa2949f4d08af7bf59c6e47d5ba4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
---
title: Bare-metal ATSAM3X8E (Arduino Due)
date: 2024-09-16
layout: post
---
Toolchain: ST-LINK/V2 programmer, OpenOCD, ARM GNU Compiler Toolchain.
<table style="border: none; width: 100%;">
<tr style="border: none;">
<td style="border: none; width: 50%; vertical-align: top; background-color: transparent;">
<img src="schematic.png" alt="Pinout" style="width: 100%">
<p style="text-align: center;">Wiring</p>
</td>
<td style="border: none; width: 50%; vertical-align: top; background-color: transparent;">
<img src="connections.jpeg" alt="Circuit" style="width: 100%">
<p style="text-align: center;">Arduino Due</p>
</td>
</tr>
</table>
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: <a
href="https://git.asciimx.com/bare-metal-arduino-due/commit/?id=318496925ca76668dd9d63c3d060376f489276f8"
class="external" target="_blank" rel="noopener noreferrer">3184969</a>.
|