Can someone experienced tell me how I can debug the Arduino Nano (basic) board? I was surprised to see that IDE 2x tells me that debugging for Nano is not supported.
Why surprised? The Nano board doesn't have a debugger on board that could e.g. speak debugWire to the ATMega328P. It doesn't have the hardware on board for good debugging capabilities.
More modern boards, e.g. those based on an STM32, have better capabilities, because they have on-board debuggers like an ST-Link. Even with the Arduino Uno R4 WiFi, the ESP32S3 on there acts like a CMSIS-DAP debugger, debugging the Renesas ARM chip via SWD.
If you're looking for a professional debug experience, an Arduino Nano board is absolutely not the right choice, thanks to the outdated chip and no on-board debugger.
There are hacky workarounds for the older AVR boards that can run an on-device debugger ("gdb stub") on the chip itself to make it debugabble via the regular serial connection. But then you also lose the capability to use the Serial normally (though you can still debug messages via a specified API).
The library https://github.com/jdolinay/avr_debug implements this. With some hacking you can also get it to work inside the Arduino IDE (https://github.com/jdolinay/avr_debug/blob/master/arduino/readme.txt).
But with IDEs like PlatformIO, it works rather nicely. Like e.g. How to debug on Arduino mega 2560 - #2 by maxgerhardt - Debugging - PlatformIO Community shows.
Thank you for your fast response, Max. I think the easier way for me, as I am not a professional, is to move to an ESP32 device, with which I have been working before.
At least make sure to get a newer ESP32 that has a builtin USB JTAG debugger, like a ESP32-S3 or a ESP32-C3, if you want the out of the box debuggability experience.
Otherwise you too will have to connect a JTAG debugger to an ESP32 to debug that XTensa or RISC-V core.
Of course, this does in no way mean that old-school debugging methods via Serial.println() / printf() style don't work. You can still get very far with that and some logical deducation capability.
Hi @richardfl. Debugging for the ATmega328P-based boards is available when using the excellent 3rd party "MiniCore" boards platform:
See the MiniCore readme for information about how to install and use the platform.
As @maxgerhardt explained, there is no on-board/on-chip debug probe on the Nano. So you do need to connect external debug probe hardware between the board and your computer in order to use the debugger:
https://github.com/felias-fogg/dw-gdbserver#supported-and-tested-hardware-debuggers
Thanks a lot for the lead
You are welcome. If you give it a try, please let us know how it goes. I'm sure some of the forum members (including myself) will be interested to learn more about this recently added advanced capability for working with the beloved ATmega328P microcontroller via Arduino IDE.
For the time being, I will try to avoid that solution. I already have esp32 and an Uno R4 minima that I can use to debug the SW, and then I can transport it to the Nano. Sure enough, if this gives me a headache, I will not have other alternative but to use the MCY dude.
