blob: 0916c6f9341d61eb95dd9e876927a603ac26dee1 (
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ATSAM3X8E bare-metal programming</title>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ATSAM3X8E bare-metal programming</title>
<link rel="stylesheet" href="/assets/css/main.css">
<link rel="stylesheet" href="/assets/css/skeleton.css">
</head>
</head>
<body>
<div id="nav-container" class="container">
<ul id="navlist" class="left">
<li >
<a href="/" class="link-decor-none">hme</a>
</li>
<li class="active">
<a href="/log/" class="link-decor-none">log</a>
</li>
<li >
<a href="/projects/" class="link-decor-none">poc</a>
</li>
<li >
<a href="/about/" class="link-decor-none">abt</a>
</li>
<li><a href="/feed.xml" class="link-decor-none">rss</a></li>
</ul>
</div>
<main>
<div class="container">
<div class="container-2">
<h2 class="center" id="title">ATSAM3X8E BARE-METAL PROGRAMMING</h2>
<h6 class="center">16 SEPTEMBER 2024</h5>
<br>
<div class="twocol justify"><p>Notes on programming ATSAM3X8E chips (Arduino Due) without bootloader. Tested
on OpenBSD.</p>
<h2 id="toolchain">Toolchain</h2>
<p>Need to bypass embedded bootloader—requires hardware programmer that speaks
Serial Wire Debug (SWD). ST-LINK/V2 works as SWD-USB adapter.</p>
<p>OpenOCD translates commands to binary sequences the chip understands. Runs
telnet server on startup for issuing commands.</p>
<p>ARM GNU Compiler Toolchain for compiling C programs. Both OpenOCD and ARM
toolchain available on OpenBSD.</p>
<h2 id="electrical-connections">Electrical connections</h2>
<p>Arduino Due exposes ATSAM3X8E’s SWD interface via DEBUG port. ST-LINK/V2
connects there.</p>
<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>
<p>Arduino Due exposes the ATSAM3X8E’s SWD interface via its DEBUG port. The
ST-LINK/v2 programmer connects to that to communicate with the chip.</p>
<h2 id="upload-procedure">Upload procedure</h2>
<p>Sample LED blink program with OpenOCD config and linker scripts in tarball
below.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -T script.ld \
-nostartfiles \
-nostdlib \
-o a.elf main.c
</code></pre></div></div>
<p>Upload:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ openocd -f openocd-due.cfg
$ telnet localhost 4444
> halt
> at91sam3 gpnvm show
> at91sam3 gpnvm set 1
> at91sam3 gpnvm show
$ openocd -f openocd-due.cfg -c "program a.elf verify reset exit"
</code></pre></div></div>
<p>First command starts OpenOCD. Telnet session halts chip, checks GPNVM bit. If
unset (returns 0), set to 1 and verify. Final command uploads program. See
OpenOCD manual AT91SAM3 flash driver section for full command list.</p>
<h2 id="gpnvm-bits">GPNVM bits</h2>
<p>ARM chips boot into address 0x00000. ATSAM3X8E has ROM and dual-banked flash
(flash0/flash1) at different addresses. GPNVM bits control which maps to
0x00000.</p>
<p>GPNVM1 cleared (default): boots from ROM (Atmel SAM-BA bootloader). GPNVM1=1,
GPNVM2=0: flash0 (0x80000) maps to 0x00000. Both cleared: flash1 maps to
0x00000.</p>
<p>Program goes in flash0, so set GPNVM1=1 to boot our code instead of bootloader.</p>
<h2 id="linker-script-notes">Linker script notes</h2>
<p>Vector table must be at first flash address–mandatory for ARM chips unless
using VTOR register for relocation.</p>
<p>First vector table entry: stack pointer. Initialize to highest memory location
(ATSAM3X8E has descending stack).</p>
<p>Second entry: reset vector. Place initialization code here (zero memory, set
registers) before jumping to main().</p>
<p>Commit:
<a href="https://git.asciimx.com/bare-metal-arduino-due/commit/?id=318496925ca76668dd9d63c3d060376f489276f8">3184969</a></p>
</div>
<p class="post-author right">by W. D. Sadeep Madurange</p>
</div>
</div>
</main>
<div class="footer">
<div class="container">
<div class="twelve columns right container-2">
<p id="footer-text">© ASCIIMX - 2025</p>
</div>
</div>
</div>
</body>
</html>
|