The Arduino Due is a pretty impressive hardware platform for experimenting with the SAM3X8E ARM Cortex M3 controller. But I also like the flexibility of C++ and the comfort of Visual Studio. So lets do a away with the Arduino IDE and setup a lean embedded development station for some baremetal ARM development.
Blinking with debug output on Windows XP / Visual Studio 2008
The environment was setup around an application that blinks the LED on the Arduino Due board and uses the debug serial interface to send some debug output to a serial terminal trough the Arduino Due programming port.
I’ve set everything up using Windows XP and Visual Studio 2008 because this performs really great in a VM while providing all the functionality I need.
Download the source code to the blink project here.
To build the blink project these need to be available on the development system:
CMSIS headers and startup / system code and makefile
The headers and startup code where obtained from Atmel Studio 6. They are included in the blink application. But it may still be interesting to start Atmel Studio and create a new project for the SAM3X8E to see what Atmel Studio comes up with.
The general structure for the makefile as well as the sed commandline extract line numbers from GCC error messages that are recognized by Visual Studio is from this baremetal teensy 3.1 page.
Downloading program code using the SAM-BA bootloader
Arduino pulled some clever tricks to enable us to download program code to the SAM3X8E without requiring extra hardware. The SAM chips form Atmel all include the SAM-BA bootloader in a part of their ROM. This bootloader is not erasable and can be enabled on the UART pins of the SAM when the chip is empty and a special reset sequence is used.
The UART on the SAM3X8E can be reached from the development PC through a secondary microcontroller the Arduino Due guys added to their board. This is an ATmega16U2 that is programmed to provide a USB to serial interface. On Windows XP you will need an inf file to install the programming port as a virtual COM port.
To get the SAM-BA bootloader software active on the SAM3X8E you will need to open a connection to the virtual COM port at 1200 baud. The ATmega16U2 firmware detects this and immediately erases the SAM3X8E and performs the reset needed to enable the SAM-BA bootloader software on the UART pins.
To finally program the chip you will need some software to communicate with the SAM-BA bootloader. Arduino does this by using a customized version of the BOSSA software, since the official BOSSA application does not yet support the SAM3X8E. The customized version can be found by installing the Arduino software, downloading the blink example or just here.
So .. to download some code to the SAM3X8E from a makefile:
mode $(COMPORT) BAUD=1200 PARITY=n DATA=8 -ping 184.108.40.206 -n 1 -w 100 > nul -set /p x=""
\\.\$(COMPORT) $(PROGPATH)\bossac --port=$(COMPORT) -U false -e -w -b "$(PROJECT).bin" -R
- Set the comport in the variable $(COMPORT) to 1200 baud
- Abuse ping to wait 100ms. This is required when the COM port was configured with different settings
- Abuse set to send an empty string to the COM port
- Use the modified BOSSA commandline tool to send the binary file to the SAM3X8E
BOSSA will reset the CPU when its done. Next we can use our trusty old tera term to connect to the debug serial to what our own code is doing.