Something I noticed when using platformio with AVR microcontrollers is the lack of debugging tools. As suggested in VSCode PIO debugger for AVR, projects like dwire-debug could change this situation after solving some problems and limitations, like only one breakpoint, assembler listings among them.
However, another project that could be of use is simavr, an opensource AVR simulator. Something amazing about this is that it not only emulates the AVR core but also, interruptions, peripherals and also includes a GDB server.
It isn’t long since I found about this simulator (or even Platformio) so some mistakes could have been made, but this is my first working attempt to integrate simavr with platformio and VSCode.
To make this work the first step is to install simavr itself which can be done by a simple apt-get install simavr or downloading and installing from source code. I didn’t verify this but it looks like is possible to compile for mac and windows too.
Next is to create a platformio project as usual and modify the platformio.ini file by adding a custom debugger, just like this one.
Finally copy the simavr_env.py file to the root of the project. The simavr_env.py script creates a target, called simulate, for the pio command, and to launch the simulator and GDB session the following command is required: pio run -t simulate -e debug
This python script automatically handles the generation of arguments for simavr based in the board_mcu and board_f_cpu definitions, so the simulated controller will always be the same as the one in the board definition in platformio.ini
The emulated environment works without any modification to the microcontroller’s source code, however, to enhance the experience the header simavr/avr/avr_mcu_section.h should be included together with some macros as explained in the simavr’s project page, like this example.
Among the new features comes the possibility to log any register or variable and graph them as if a logic analyzer were connected. Also, it looks like it can also emulate external devices like displays, buttons, and even sensors, but I haven’t tested those yet.
I just found about simavr a couple of days ago but it allowed me to get the debugging experience I had with other microcontrollers like stm32. I don’t know if my approach is the best one, but at least it doesn’t require to fiddle with internal configuration files but only the platformio.ini file.
Now it would be interesting if simavr were included in the platformio environment maybe as a board to avoid conflicts with the existing ones, but that’s only a suggestion.