diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2025-12-27 13:05:42 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2025-12-27 13:05:42 +0800 |
| commit | 023ea62a08492d9dda680cee3e706a988b1ae6f0 (patch) | |
| tree | 96bbf7ee6eb91ca33b98b63539e29394f194b441 | |
| parent | 196cf07dff3e16f6c44bb2a6cca10c0af3652fe9 (diff) | |
| download | www-023ea62a08492d9dda680cee3e706a988b1ae6f0.tar.gz | |
Arduino due post.
| -rw-r--r-- | _log/arduino-due.md | 103 | ||||
| -rw-r--r-- | _site/feed.xml | 2 | ||||
| -rw-r--r-- | _site/index.html | 2 | ||||
| -rw-r--r-- | _site/log/arduino-due/index.html | 98 | ||||
| -rw-r--r-- | _site/log/index.html | 2 | ||||
| -rw-r--r-- | _site/posts.xml | 2 |
6 files changed, 80 insertions, 129 deletions
diff --git a/_log/arduino-due.md b/_log/arduino-due.md index 2cbd2f4..0d4f495 100644 --- a/_log/arduino-due.md +++ b/_log/arduino-due.md @@ -1,43 +1,27 @@ --- -title: How to set up ATSAM3X8E microcontrollers for bare-metal programming in C +title: ATSAM3X8E bare-metal programming date: 2024-09-16 layout: post --- -This article is a step-by-step guide for programming bare-metal ATSAM3X8E chips -found on Arduino Due boards. It also includes notes on the chip's memory layout -relevant for writing linker scripts. The steps described in this article were -tested on an OpenBSD workstation. +Notes on programming ATSAM3X8E chips (Arduino Due) without bootloader. Tested +on OpenBSD. ## Toolchain -To interact directly with a bare-metal ATSAM3X8E chips, we must bypass the -embedded bootloader. To do that, we need a hardware programmer capable of -communicating with the chip over the Serial Wire Debug (SWD) protocol. Since -the workstation we upload the program from presumably doesn't speak SWD, the -hardware programmer acts as a SWD-USB adapter. The <a -href="https://www.st.com/en/development-tools/st-link-v2.html" class="external" -target="_blank" rel="noopener noreferrer">ST-LINK/V2</a> programmer fits this -bill. - -The <a href="https://openocd.org/" class="external" target="_blank" -rel="noopener noreferrer">OpenOCD</a> on-chip debugger software supports -ATSAM3X8E chips. OpenOCD, on startup, runs a telnet server that we can connect to -to issue commands to the ATSAM3X8E chip. OpenOCD translates plain-text commands -into the binary sequences the chip understands, and sends them over the wire. - -Finally, we need the <a -href="https://developer.arm.com/Tools%20and%20Software/GNU%20Toolchain" -class="external" target="_blank" rel="noopener noreferrer">ARM GNU Compiler -Toolchain</a> to compile C programs for the chip. The ARM GNU compiler -toolchain and OpenOCD, as a consequence of being free software, are available -on every conceivable platform, including OpenBSD. +Need to bypass embedded bootloader—requires hardware programmer that speaks +Serial Wire Debug (SWD). ST-LINK/V2 works as SWD-USB adapter. + +OpenOCD translates commands to binary sequences the chip understands. Runs +telnet server on startup for issuing commands. + +ARM GNU Compiler Toolchain for compiling C programs. Both OpenOCD and ARM +toolchain available on OpenBSD. ## Electrical connections -The following photos illustrate the electrical connections between the Arduino -Due, PC, and the ST-LINK/V2 programmer required to transfer a compiled program -from a PC to the MCU. +Arduino Due exposes ATSAM3X8E's SWD interface via DEBUG port. ST-LINK/V2 +connects there. <table style="border: none; width: 100%;"> <tr style="border: none;"> @@ -55,11 +39,10 @@ from a PC to the MCU. 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. -## Uploading the program +## Upload procedure -The source.tar.gz tarball at the end of this page contains a sample C program -(the classic LED blink program) with OpenOCD configuration and linker scripts. -First, use the following command to build it: +Sample LED blink program with OpenOCD config and linker scripts in tarball +below. ``` $ arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -T script.ld \ @@ -68,8 +51,7 @@ $ arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -T script.ld \ -o a.elf main.c ``` -Then, open a telnet session with OpenOCD and issue the following sequence of -commands to configure the chip and upload the compiled program to it: +Upload: ``` $ openocd -f openocd-due.cfg @@ -81,42 +63,33 @@ $ telnet localhost 4444 $ openocd -f openocd-due.cfg -c "program a.elf verify reset exit" ``` -The first of the above commands starts OpenOCD. In the telnet session, the -first command halts the chip in preparation for receiving commands. Next, we -inspect the current GPNVM bit setting (more on this later). If the bit is unset -(the gpnvm show command returns 0), we set it to 1 and verify the update. - -The final command, issued from outside the telnet session, uploads the program -to the chip. Those are the bare minimum set of commands required to program the -chip. The AT91SAM3 flash driver section of the OpenOCD manual lists all -available commands for the ATSAM3X8E chip. +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. ## GPNVM bits -By design, ARM chips boot into address 0x00000. ATSAM3X8E's memory consists of -a ROM and a dual-banked flash (flash0 and flash1), residing in different -locations of the chip's address space. The GPNVM bits control which of them -maps to 0x00000. When GPNVM1 is cleared (the default), the chip boots from the ROM, -which contains Atmel's SAM-BA bootloader. +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. + +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. + +Program goes in flash0, so set GPNVM1=1 to boot our code instead of bootloader. -Conversely, when the GPNVM1 bit is 1 (and the GPNVM2 bit is 0), flash0 at -address 0x80000 maps to 0x00000. When both GPNVM bits are 0, flash1 maps to -0x00000. Since we place our program in flash0 in the linker script, we set the -GPNVM1 bit and leave the GPNVM2 bit unchanged to ensure the chip -executes our program instead of the embedded bootloader at startup. +## Linker script notes -## Linker script +Vector table must be at first flash address--mandatory for ARM chips unless +using VTOR register for relocation. -At a minimum, the linker script must place the vector table at the first -address of the flash. This is mandatory for ARM chips unless we relocate the -vector table using the VTOR register. +First vector table entry: stack pointer. Initialize to highest memory location +(ATSAM3X8E has descending stack). -The first entry of the vector table must be the stack pointer. The stack -pointer must be initialized to the highest memory location available to -accommodate the ATSAM3X8E's descending stack. +Second entry: reset vector. Place initialization code here (zero memory, set +registers) before jumping to main(). -The second entry of the vector table must be the reset vector. In the reset -vector, we can perform tasks such as zeroing out memory and initializing -registers before passing control to the main program. +Commit: +[3184969](https://git.asciimx.com/bare-metal-arduino-due/commit/?id=318496925ca76668dd9d63c3d060376f489276f8) -Files: [source.tar.gz](source.tar.gz) diff --git a/_site/feed.xml b/_site/feed.xml index 2f1bab9..de57fda 100644 --- a/_site/feed.xml +++ b/_site/feed.xml @@ -1 +1 @@ -<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="/feed.xml" rel="self" type="application/atom+xml" /><link href="/" rel="alternate" type="text/html" /><updated>2025-12-27T12:40:20+08:00</updated><id>/feed.xml</id><title type="html">ASCIIMX | Log</title><author><name>W. D. Sadeep Madurange</name></author><entry><title type="html">Matrix Rain: 2025 refactor</title><link href="/log/matrix-digital-rain/" rel="alternate" type="text/html" title="Matrix Rain: 2025 refactor" /><published>2025-12-21T00:00:00+08:00</published><updated>2025-12-21T00:00:00+08:00</updated><id>/log/matrix-digital-rain</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[The 2022 version worked but had some loose ends. Unicode support was inflexible–couldn’t mix ASCII with Katakana; Phosphor decay was stored in a separate array when it should’ve been packed with RGB; Code was harder to read than it needed to be.]]></summary></entry><entry><title type="html">Fingerprint door lock (LP)</title><link href="/log/fpm-door-lock-lp/" rel="alternate" type="text/html" title="Fingerprint door lock (LP)" /><published>2025-08-18T00:00:00+08:00</published><updated>2025-08-18T00:00:00+08:00</updated><id>/log/fpm-door-lock-lp</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Second iteration of the RF door lock. Old version worked but drew too much quiescent current. Sensor and servo pulled 13.8mA and 4.6mA idle. Linear regulators were a disaster. Battery didn’t last 24 hours.]]></summary></entry><entry><title type="html">High-side MOSFET switching</title><link href="/log/mosfet-switches/" rel="alternate" type="text/html" title="High-side MOSFET switching" /><published>2025-06-22T00:00:00+08:00</published><updated>2025-06-22T00:00:00+08:00</updated><id>/log/mosfet-switches</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Needed low-power switching for the fingerprint door lock. Servo and FPM draw high quiescent current–had to cut power electronically during sleep. MOSFETs can do this.]]></summary></entry><entry><title type="html">ATmega328P at 3.3V and 5V</title><link href="/log/arduino-uno/" rel="alternate" type="text/html" title="ATmega328P at 3.3V and 5V" /><published>2025-06-10T00:00:00+08:00</published><updated>2025-06-10T00:00:00+08:00</updated><id>/log/arduino-uno</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Quick reference for wiring ATmega328P ICs at 5V and 3.3V. 5V uses 16MHz crystal, 3.3V uses 8MHz.]]></summary></entry><entry><title type="html">Fingerprint door lock (RF)</title><link href="/log/fpm-door-lock-rf/" rel="alternate" type="text/html" title="Fingerprint door lock (RF)" /><published>2025-06-05T00:00:00+08:00</published><updated>2025-06-05T00:00:00+08:00</updated><id>/log/fpm-door-lock-rf</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Wanted to unlock door with fingerprint, wirelessly to avoid drilling.]]></summary></entry><entry><title type="html">Bumblebee: browser automation</title><link href="/log/bumblebee/" rel="alternate" type="text/html" title="Bumblebee: browser automation" /><published>2025-04-02T00:00:00+08:00</published><updated>2025-04-02T00:00:00+08:00</updated><id>/log/bumblebee</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Bumblebee is a tool I built for one of my employers to automate the generation of web scraping scripts.]]></summary></entry><entry><title type="html">How to set up ATSAM3X8E microcontrollers for bare-metal programming in C</title><link href="/log/arduino-due/" rel="alternate" type="text/html" title="How to set up ATSAM3X8E microcontrollers for bare-metal programming in C" /><published>2024-09-16T00:00:00+08:00</published><updated>2024-09-16T00:00:00+08:00</updated><id>/log/arduino-due</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[This article is a step-by-step guide for programming bare-metal ATSAM3X8E chips found on Arduino Due boards. It also includes notes on the chip’s memory layout relevant for writing linker scripts. The steps described in this article were tested on an OpenBSD workstation.]]></summary></entry><entry><title type="html">Etlas: e-paper dashboard</title><link href="/log/etlas/" rel="alternate" type="text/html" title="Etlas: e-paper dashboard" /><published>2024-09-05T00:00:00+08:00</published><updated>2024-09-05T00:00:00+08:00</updated><id>/log/etlas</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Etlas is a news, stock market, and weather tracker powered by an ESP32 NodeMCU D1, featuring a 7.5-inch Waveshare e-paper display and a DHT22 sensor module.]]></summary></entry><entry><title type="html">Experimental e-reader</title><link href="/log/e-reader/" rel="alternate" type="text/html" title="Experimental e-reader" /><published>2023-10-24T00:00:00+08:00</published><updated>2023-10-24T00:00:00+08:00</updated><id>/log/e-reader</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[This project features an experimental e-reader powered by an ESP-WROOM-32 development board and a 7.5-inch Waveshare e-paper display built with the intention of learning about e-paper displays.]]></summary></entry><entry><title type="html">Neo4J A* search</title><link href="/log/neo4j-a-star-search/" rel="alternate" type="text/html" title="Neo4J A* search" /><published>2018-03-06T00:00:00+08:00</published><updated>2018-03-06T00:00:00+08:00</updated><id>/log/neo4j-a-star-search</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Back in 2018, we used Neo4J graph database to track the movement of marine vessels. We were interested in the shortest path a ship could take through a network of about 13,000 route points. Graph theoretic algorithms provide optimal solutions to such problems, and the set of route points lends itself well to graph-based modelling.]]></summary></entry></feed>
\ No newline at end of file +<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="/feed.xml" rel="self" type="application/atom+xml" /><link href="/" rel="alternate" type="text/html" /><updated>2025-12-27T13:04:53+08:00</updated><id>/feed.xml</id><title type="html">ASCIIMX | Log</title><author><name>W. D. Sadeep Madurange</name></author><entry><title type="html">Matrix Rain: 2025 refactor</title><link href="/log/matrix-digital-rain/" rel="alternate" type="text/html" title="Matrix Rain: 2025 refactor" /><published>2025-12-21T00:00:00+08:00</published><updated>2025-12-21T00:00:00+08:00</updated><id>/log/matrix-digital-rain</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[The 2022 version worked but had some loose ends. Unicode support was inflexible–couldn’t mix ASCII with Katakana; Phosphor decay was stored in a separate array when it should’ve been packed with RGB; Code was harder to read than it needed to be.]]></summary></entry><entry><title type="html">Fingerprint door lock (LP)</title><link href="/log/fpm-door-lock-lp/" rel="alternate" type="text/html" title="Fingerprint door lock (LP)" /><published>2025-08-18T00:00:00+08:00</published><updated>2025-08-18T00:00:00+08:00</updated><id>/log/fpm-door-lock-lp</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Second iteration of the RF door lock. Old version worked but drew too much quiescent current. Sensor and servo pulled 13.8mA and 4.6mA idle. Linear regulators were a disaster. Battery didn’t last 24 hours.]]></summary></entry><entry><title type="html">High-side MOSFET switching</title><link href="/log/mosfet-switches/" rel="alternate" type="text/html" title="High-side MOSFET switching" /><published>2025-06-22T00:00:00+08:00</published><updated>2025-06-22T00:00:00+08:00</updated><id>/log/mosfet-switches</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Needed low-power switching for the fingerprint door lock. Servo and FPM draw high quiescent current–had to cut power electronically during sleep. MOSFETs can do this.]]></summary></entry><entry><title type="html">ATmega328P at 3.3V and 5V</title><link href="/log/arduino-uno/" rel="alternate" type="text/html" title="ATmega328P at 3.3V and 5V" /><published>2025-06-10T00:00:00+08:00</published><updated>2025-06-10T00:00:00+08:00</updated><id>/log/arduino-uno</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Quick reference for wiring ATmega328P ICs at 5V and 3.3V. 5V uses 16MHz crystal, 3.3V uses 8MHz.]]></summary></entry><entry><title type="html">Fingerprint door lock (RF)</title><link href="/log/fpm-door-lock-rf/" rel="alternate" type="text/html" title="Fingerprint door lock (RF)" /><published>2025-06-05T00:00:00+08:00</published><updated>2025-06-05T00:00:00+08:00</updated><id>/log/fpm-door-lock-rf</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Wanted to unlock door with fingerprint, wirelessly to avoid drilling.]]></summary></entry><entry><title type="html">Bumblebee: browser automation</title><link href="/log/bumblebee/" rel="alternate" type="text/html" title="Bumblebee: browser automation" /><published>2025-04-02T00:00:00+08:00</published><updated>2025-04-02T00:00:00+08:00</updated><id>/log/bumblebee</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Bumblebee is a tool I built for one of my employers to automate the generation of web scraping scripts.]]></summary></entry><entry><title type="html">ATSAM3X8E bare-metal programming</title><link href="/log/arduino-due/" rel="alternate" type="text/html" title="ATSAM3X8E bare-metal programming" /><published>2024-09-16T00:00:00+08:00</published><updated>2024-09-16T00:00:00+08:00</updated><id>/log/arduino-due</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Notes on programming ATSAM3X8E chips (Arduino Due) without bootloader. Tested on OpenBSD.]]></summary></entry><entry><title type="html">Etlas: e-paper dashboard</title><link href="/log/etlas/" rel="alternate" type="text/html" title="Etlas: e-paper dashboard" /><published>2024-09-05T00:00:00+08:00</published><updated>2024-09-05T00:00:00+08:00</updated><id>/log/etlas</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Etlas is a news, stock market, and weather tracker powered by an ESP32 NodeMCU D1, featuring a 7.5-inch Waveshare e-paper display and a DHT22 sensor module.]]></summary></entry><entry><title type="html">Experimental e-reader</title><link href="/log/e-reader/" rel="alternate" type="text/html" title="Experimental e-reader" /><published>2023-10-24T00:00:00+08:00</published><updated>2023-10-24T00:00:00+08:00</updated><id>/log/e-reader</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[This project features an experimental e-reader powered by an ESP-WROOM-32 development board and a 7.5-inch Waveshare e-paper display built with the intention of learning about e-paper displays.]]></summary></entry><entry><title type="html">Neo4J A* search</title><link href="/log/neo4j-a-star-search/" rel="alternate" type="text/html" title="Neo4J A* search" /><published>2018-03-06T00:00:00+08:00</published><updated>2018-03-06T00:00:00+08:00</updated><id>/log/neo4j-a-star-search</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Back in 2018, we used Neo4J graph database to track the movement of marine vessels. We were interested in the shortest path a ship could take through a network of about 13,000 route points. Graph theoretic algorithms provide optimal solutions to such problems, and the set of route points lends itself well to graph-based modelling.]]></summary></entry></feed>
\ No newline at end of file diff --git a/_site/index.html b/_site/index.html index 0bc5788..b544a60 100644 --- a/_site/index.html +++ b/_site/index.html @@ -134,7 +134,7 @@ <tr> <td class="posts-td posts-td-link"> - <a href="/log/arduino-due/" class="link-decor-none">How to set up ATSAM3X8E microcontrollers for bare-metal programming in C</a> + <a href="/log/arduino-due/" class="link-decor-none">ATSAM3X8E bare-metal programming</a> </td> <td class="posts-td posts-td-time"> <span class="post-meta"> diff --git a/_site/log/arduino-due/index.html b/_site/log/arduino-due/index.html index d2248bc..0916c6f 100644 --- a/_site/log/arduino-due/index.html +++ b/_site/log/arduino-due/index.html @@ -2,12 +2,12 @@ <html> <head> <meta charset="utf-8"> - <title>How to set up ATSAM3X8E microcontrollers for bare-metal programming in C</title> + <title>ATSAM3X8E bare-metal programming</title> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> - <title>How to set up ATSAM3X8E microcontrollers for bare-metal programming in C</title> + <title>ATSAM3X8E bare-metal programming</title> <link rel="stylesheet" href="/assets/css/main.css"> <link rel="stylesheet" href="/assets/css/skeleton.css"> </head> @@ -41,38 +41,27 @@ <main> <div class="container"> <div class="container-2"> - <h2 class="center" id="title">HOW TO SET UP ATSAM3X8E MICROCONTROLLERS FOR BARE-METAL PROGRAMMING IN C</h2> + <h2 class="center" id="title">ATSAM3X8E BARE-METAL PROGRAMMING</h2> <h6 class="center">16 SEPTEMBER 2024</h5> <br> - <div class="twocol justify"><p>This article is a step-by-step guide for programming bare-metal ATSAM3X8E chips -found on Arduino Due boards. It also includes notes on the chip’s memory layout -relevant for writing linker scripts. The steps described in this article were -tested on an OpenBSD workstation.</p> + <div class="twocol justify"><p>Notes on programming ATSAM3X8E chips (Arduino Due) without bootloader. Tested +on OpenBSD.</p> <h2 id="toolchain">Toolchain</h2> -<p>To interact directly with a bare-metal ATSAM3X8E chips, we must bypass the -embedded bootloader. To do that, we need a hardware programmer capable of -communicating with the chip over the Serial Wire Debug (SWD) protocol. Since -the workstation we upload the program from presumably doesn’t speak SWD, the -hardware programmer acts as a SWD-USB adapter. The <a href="https://www.st.com/en/development-tools/st-link-v2.html" class="external" target="_blank" rel="noopener noreferrer">ST-LINK/V2</a> programmer fits this -bill.</p> +<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>The <a href="https://openocd.org/" class="external" target="_blank" rel="noopener noreferrer">OpenOCD</a> on-chip debugger software supports -ATSAM3X8E chips. OpenOCD, on startup, runs a telnet server that we can connect to -to issue commands to the ATSAM3X8E chip. OpenOCD translates plain-text commands -into the binary sequences the chip understands, and sends them over the wire.</p> +<p>OpenOCD translates commands to binary sequences the chip understands. Runs +telnet server on startup for issuing commands.</p> -<p>Finally, we need the <a href="https://developer.arm.com/Tools%20and%20Software/GNU%20Toolchain" class="external" target="_blank" rel="noopener noreferrer">ARM GNU Compiler -Toolchain</a> to compile C programs for the chip. The ARM GNU compiler -toolchain and OpenOCD, as a consequence of being free software, are available -on every conceivable platform, including OpenBSD.</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>The following photos illustrate the electrical connections between the Arduino -Due, PC, and the ST-LINK/V2 programmer required to transfer a compiled program -from a PC to the MCU.</p> +<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;"> @@ -90,11 +79,10 @@ from a PC to the MCU.</p> <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="uploading-the-program">Uploading the program</h2> +<h2 id="upload-procedure">Upload procedure</h2> -<p>The source.tar.gz tarball at the end of this page contains a sample C program -(the classic LED blink program) with OpenOCD configuration and linker scripts. -First, use the following command to build it:</p> +<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 \ @@ -102,8 +90,7 @@ First, use the following command to build it:</p> -o a.elf main.c </code></pre></div></div> -<p>Then, open a telnet session with OpenOCD and issue the following sequence of -commands to configure the chip and upload the compiled program to it:</p> +<p>Upload:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ openocd -f openocd-due.cfg $ telnet localhost 4444 @@ -114,45 +101,36 @@ $ telnet localhost 4444 $ openocd -f openocd-due.cfg -c "program a.elf verify reset exit" </code></pre></div></div> -<p>The first of the above commands starts OpenOCD. In the telnet session, the -first command halts the chip in preparation for receiving commands. Next, we -inspect the current GPNVM bit setting (more on this later). If the bit is unset -(the gpnvm show command returns 0), we set it to 1 and verify the update.</p> - -<p>The final command, issued from outside the telnet session, uploads the program -to the chip. Those are the bare minimum set of commands required to program the -chip. The AT91SAM3 flash driver section of the OpenOCD manual lists all -available commands for the ATSAM3X8E chip.</p> +<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>By design, ARM chips boot into address 0x00000. ATSAM3X8E’s memory consists of -a ROM and a dual-banked flash (flash0 and flash1), residing in different -locations of the chip’s address space. The GPNVM bits control which of them -maps to 0x00000. When GPNVM1 is cleared (the default), the chip boots from the ROM, -which contains Atmel’s SAM-BA bootloader.</p> +<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> -<p>Conversely, when the GPNVM1 bit is 1 (and the GPNVM2 bit is 0), flash0 at -address 0x80000 maps to 0x00000. When both GPNVM bits are 0, flash1 maps to -0x00000. Since we place our program in flash0 in the linker script, we set the -GPNVM1 bit and leave the GPNVM2 bit unchanged to ensure the chip -executes our program instead of the embedded bootloader at startup.</p> +<h2 id="linker-script-notes">Linker script notes</h2> -<h2 id="linker-script">Linker script</h2> +<p>Vector table must be at first flash address–mandatory for ARM chips unless +using VTOR register for relocation.</p> -<p>At a minimum, the linker script must place the vector table at the first -address of the flash. This is mandatory for ARM chips unless we relocate the -vector table using the VTOR register.</p> +<p>First vector table entry: stack pointer. Initialize to highest memory location +(ATSAM3X8E has descending stack).</p> -<p>The first entry of the vector table must be the stack pointer. The stack -pointer must be initialized to the highest memory location available to -accommodate the ATSAM3X8E’s descending stack.</p> +<p>Second entry: reset vector. Place initialization code here (zero memory, set +registers) before jumping to main().</p> -<p>The second entry of the vector table must be the reset vector. In the reset -vector, we can perform tasks such as zeroing out memory and initializing -registers before passing control to the main program.</p> +<p>Commit: +<a href="https://git.asciimx.com/bare-metal-arduino-due/commit/?id=318496925ca76668dd9d63c3d060376f489276f8">3184969</a></p> -<p>Files: <a href="source.tar.gz">source.tar.gz</a></p> </div> <p class="post-author right">by W. D. Sadeep Madurange</p> </div> diff --git a/_site/log/index.html b/_site/log/index.html index 0fcfc51..645a982 100644 --- a/_site/log/index.html +++ b/_site/log/index.html @@ -124,7 +124,7 @@ <tr> <td class="posts-td posts-td-link"> - <a href="/log/arduino-due/" class="link-decor-none">How to set up ATSAM3X8E microcontrollers for bare-metal programming in C</a> + <a href="/log/arduino-due/" class="link-decor-none">ATSAM3X8E bare-metal programming</a> </td> <td class="posts-td posts-td-time"> <span class="post-meta"> diff --git a/_site/posts.xml b/_site/posts.xml index 53b0ad5..043fc0d 100644 --- a/_site/posts.xml +++ b/_site/posts.xml @@ -1 +1 @@ -<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="/posts.xml" rel="self" type="application/atom+xml" /><link href="/" rel="alternate" type="text/html" /><updated>2025-12-27T12:40:20+08:00</updated><id>/posts.xml</id><title type="html">ASCIIMX</title><author><name>W. D. Sadeep Madurange</name></author></feed>
\ No newline at end of file +<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="/posts.xml" rel="self" type="application/atom+xml" /><link href="/" rel="alternate" type="text/html" /><updated>2025-12-27T13:04:53+08:00</updated><id>/posts.xml</id><title type="html">ASCIIMX</title><author><name>W. D. Sadeep Madurange</name></author></feed>
\ No newline at end of file |
