Support for the Arduino Uno board. More...
Support for the Arduino Uno board.
The Arduino Uno is one of the cheapest board to start and discover with electronics and embedded coding. It is based on Atmel's AVR architecture and sports an ATmega328p MCU. It is like many Arduinos extensible by using shields.
|Timers||3 (2x 8bit, 1x 16bit)|
|ADCs||6 analog input pins|
|I2Cs||1 (called TWI)|
|Datasheet / Reference Manual||Datasheet and Reference Manual|
|Board Manual||Board Manual|
Flashing RIOT on the Arduino Uno is quite straight forward, just connect your Arduino Uno using the programming port to your host computer and type:
make BOARD=arduino-uno flash
This should take care of everything!
We use the open
avrdude tool to write the new code into the ATmega328p's flash
More pins can be used for hardware interrupts using the Pin Change Interrupt feature. See ATmega common for details.
Don't expect having a working network stack due to very limited resources.
On-Chip Debugging on the Arduino Uno is not supported via the usual JTAG interface used in ATmega MCUs with higher pin counts, but via debugWIRE. While debugWIRE has the advantage of only using the RESET pin to transfer data, the features provided are extremely limited. If the same issue can be reproduced on an Arduino Mega2560, which supports JTAG, it will be much easier and more productive to debug your code on the Arduino Mega2560. If the bug cannot be reproduced, limited on chip debugging is possible on the Arduino Uno nonetheless.
In order to be able to use On-Chip Debugging you will need the AVR Dragon, which is the ~~cheapest~~ least expensive programmer and debugger available that supports programming via SPI ("normal ISP"), High Voltage Serial Programming, and Parallel Programming, as well as debugging via JTAG, debugWIRE, PDI and aWire. So at least can use it for just about every AVR device.
On the Arduino Uno the RESET pin of the MCU is connected to a 100 nF capacitor, which in turn is connected to the ATmega16U2 (or an CH340 TTL Adapter in case of most clones). This allows the device to be automatically reset when you connected to the board via a serial. This is particularly useful during programming via the bootloader (without external ISP programmer), as avrdude can trigger the reset and, thus, start the bootloader without the user having to press a button.
In order to use on-chip debugging, the capacitor needs however to be disconnected from the reset pin. With the original Arduino Uno this can be done by cutting the solder jumper labeled "RESET EN". This can easily be resoldered to restore the original state. Most clones do not have this solder jumper and you will likely have to break off the usually surface mounted capacitor. A multimeter can be used to detect which capacitor is connected to the reset pin. Keep in mind that the capacitor will likely be destroyed when removed by force and it will be difficult to restore the auto-reset feature of the clones.
You need to have AVaRICE installed. Some distros have this packaged already. If you need to compile it by hand, go for the latest SVN revision. The latest release cannot be compiled on anything but historic platforms and contains bugs that prevent it from debugging the ATmega328P anyway.
In order to use On-Chip Debugging, the
DWEN bit in the high fuse needs to be enabled (set to zero). The exact fuse settings for debugging and the default fuse setting are these:
|Fuse||Default Setting||Debug Setting|
You can enable debugWIRE debugging by running (replace
<PROGRAMMER> by the name of your programmer, e.g.
dragon_isp in case of the AVR Dragon):
avrdude -p m328p -c <PROGRAMMER> -U hfuse:w:0x9e:m
And disable debugging via:
avrdude -p m328p -c <PROGRAMMER> -U hfuse:w:0xde:m
With the AVR Dragon, debugging is as simple as running:
make BOARD=arduino-uno debug
The memory map of the ELF file does not take the bootloader into account. The author of this text used an ISP to program the Arduino Uno during debugging to avoid any issues. You might want to do the same, e.g. via:
make BOARD=arduino-uno PROGRAMMER=dragon_isp flash
AVR_DEBUGDEVICEenvironment variable to the required flag to pass to AVaRICE, e.g. when using the Atmel-ICE you have to export
AVR_DEBUGDEVICE=--edbg. If the debug device is not connected via USB, you also need to export
AVR_DEBUGINTERFACEto the correct value.
The ATmega328P only has a single hardware break point and zero watchpoints. The single hardware breakpoint is used for single-stepping. As a result neither breakpoints nor watchpoints can be used. AVaRICE tries to emulate breakpoints be inserting the break machine instruction into the ROM in place of the original instruction to break on. Once this break instruction is reached, the original instruction is restored. This is not only super slow, but also wastes two flash cycles every time a breakpoint is hit. This cumulates to significant flash wear during long debugging sessions.
|Board specific definitions for the Arduino Uno board. |