1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 05:12:57 +01:00

boards/arduino-nano: Added doc on debugging

This commit is contained in:
Marian Buschsieweke 2019-12-04 10:49:22 +01:00
parent 8a89918a73
commit e97ae8ba6c
No known key found for this signature in database
GPG Key ID: 61F64C6599B1539F

View File

@ -59,6 +59,104 @@ If RIOT is stuck in a reboot loop e.g. after restarting the device with the
[issue with the stock bootloader](https://forum.arduino.cc/index.php?topic=150419.0)
that can be solved by using Optiboot as bootloader instead (see above).
## On-Chip Debugging
On-Chip Debugging on the Arduino Nano 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 Nano
nonetheless.
### Prerequisites
#### Debugging Hardware
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.
#### Board Modifications
On the Arduino Nano the RESET pin of the MCU is connected to a 100 nF capacitor,
which in turn is connected to the DTR pin of the FT232RL USB-UART bridge. 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. You can either carefully de-solder it (which
allows you to solder it back in after debugging), or just break it off with
pinch-nose pliers (which usually destroys the capacitor, making the modification
permanent). After this modification, flashing via bootloader requires a manual
press on the reset button.
#### Software
You need to have [AVaRICE](http://avarice.sourceforge.net/) 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.
#### Fuses
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 |
|:------------- |:--------------- |:------------- |
| Low Fuse | `0xFF` | `0xFF` |
| High Fuse | `0xDA` | `0x9A` |
| Extended Fuse | `0xFD` | `0xFD` |
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:0x9a:m
And disable debugging via:
avrdude -p m328p -c <PROGRAMMER> -U hfuse:w:0xda:m
@note You can use a different ISP to enable debugging, but disabling it
again will only work with the AVR Dragon: The ISP will require the RESET
pin to work, but the RESET pin is re-purposed for debugWIRE when
debugging is enabled. Recent versions of avrdude will use the debugWIRE
interface to temporarily disable debugWIRE and restore the RESET pin's
default behavior in order to use the ISP. But this requires a
programmer/debugger that can be used as both ISP and debugWIRE debugger
using the same connector. So don't enable debugging unless you have an
AVR Dragon or another plan on how to disable debugging again.
### Debugging
With the AVR Dragon, debugging is as simple as running:
make BOARD=arduino-nano debug
@warning For flashing the device via ISP, avrdude will temporarily disable
debugWIRE. If AVaRICE complains that synchronization with the device
is not possible after having it flashed, the device might need a
cold boot to enable debugWIRE again.
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 Nano during debugging to
avoid any issues. You might want to do the same, e.g. via:
make BOARD=arduino-nano PROGRAMMER=dragon_isp flash
@warning Flashing via ISP overwrites the bootloader. But you can restore it
easily using the ISP. Consult the Arduino documentation on how to
restore the bootloader.
@note If you are using a different debugger than the AVR Dragon, you have
to export the `AVR_DEBUGDEVICE` environment 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_DEBUGINTERFACE` to
the correct value.
## Caution
Don't expect having a working network stack due to very limited resources.
*/