Activity Forums Questions & Troubleshooting Debug program using PlatformIO and avr-stub

  • Debug program using PlatformIO and avr-stub

  • DanielAtValenco

    Member
    May 22, 2023 at 3:43 pm

    Hello,

    I am trying to debug a rather complex and time sensitive application running on a Controllino MEGA. My problem is that there is quite a lot happening and simply using print statements (besides being inelegant) is just not cutting it anymore.

    At first I tried using BetterSerialPlotter and this works quite well for visualizing how the system reacts but sadly cannot give me any insight as to WHY it does what it does.

    PlatformIO together with avr-stub can be used to do source level debugging but there are some caveats.

    While I do have everything set up in PIO and can upload code and enter the debug mode my program does not work as intended because it uses millis() -> see this explanation pages 95-96.

    For debugging to work I would need to use the Optiboot bootloader and use FLASH breakpoints as per this explanation.

    Burning a new bootloader is pretty straight forward and there is even an official tutorial for doing so with a Controllino MINI.

    On the official GitHub there is an Optiboot version of the bootloader for use with the Controllino MINI. Sadly, however my project requires a Controllino MEGA and for this only the standard bootloader seems to be publicly available.

    If I upload a version of Optiboot compiled for the ATMEGA2560 from the MegaCore project, I can successfully run stock Arduino sketches on it (one undesirable side effect is that the bootloader flashes an LED on startup which toggles one of the outputs). The problem begins when I then try to use my original program written for the Controllino since this requires the chosen board to be of the Controllino family (<- insert surprised Pikachu face here…). If, however I choose one of these boards uploading the sketch does not work anymore with a timeout error. As far as I can tell this is because the new Bootloader does not communicate the same way as the standard one does and so the programmer can’t find it. I tried to create a new custom board based on the Optiboot version but with the Settings adjusted so it acts as if it where a Controllino MEGA but I must admit that this goes a bit over my head, especially in PIO.

    My question now is threefold:

    1. Am I the problem (quite probably yes) and I am just doing something wrong? If so, any hints would be greatly appreciated.

    2. Is there any other way of debugging that I am not aware of? This would probably solve this whole issue (and likely create a bunch of news Problems…)

    3. Is there a possibility of getting an official version of the Optiboot bootloader for the Controllino MEGA ?

    Thank you all in advance. If you need any more Information I will try and give you what you need.

Viewing 1 of 1 replies

Log in to reply.

Original Post
0 of 0 posts June 2018
Now