AVR simulator as aid tool for debugging code

Hm good question. Usually the internal register map of a microcontroller is specified in SVD files which the PlatformIO unified debugger can load and then display the current value of it. This is indeed working already working, see screenshot and that little section “PERIPHERALS” – that info was decoded from the .svd file and the current value of that was captured using the gdb client.

But SVD files are mostly an ARM microcontroller type thing, and Atmel provides atdf that describe their hardware registers (per this). This is a project that can convert these files to SVD files though, and it supports the atmega328p – haven’t tried it yet or seen the corresponding SVD file though.

The way it internally works for the SVD files is that the board definition declares the path to the file

which maps e.g. to the file found in platform-atmelsam/misc/svd at develop · platformio/platform-atmelsam · GitHub in this case. But GitHub - platformio/platform-atmelavr: Atmel AVR: development platform for PlatformIO has no such SVD files.

If that file is obtained and referenced in the e.g. uno.json file, it’s half the story. The other is whether the current version of the PlatformIO Unified debugger will load the SVD file correctly, and whether avr-gdb will spit out the correct value for a certain register, if asked for. AVRs have a different memory architecture (harvard, I/O registers live in data memory and not in program memory), if the debugger asks GDB the wrong way for the value of a register address, it might get garbage or crash.

Also, I wanted to try out dwire since reports on that in VSCode PIO debugger for AVR - #9 by fedex03 of it partially working, I’m gonna give this a spin in combination with SVD files.

If it works, it means we have live-debugging of a running chip via debug-wire (the NRST line abused as bi-directional data line for debugging) with a decoded register view.

Note that currently also avr-stub works, but it inherently needs the main serial to communicate and it also needs flash space. But a working live-example of that can be seen in How to debug on Arduino mega 2560 - #2 by maxgerhardt.

Edit:

But that does work with avarice as a debugging server, doesn’t it? So, you can get live-debugging with that, too. See CLion / Avarice debug not working

1 Like