Hi everyone, I’m using PlatformIO with AVR8-STUB and after a little research I realize that right now is not an option to use this debugger and Serial.print at the same time, as this link illustrates:
But I’ve been thinking and I would like to know if the following could be a workaround:
The idea is to modify Arduino Mega 2560 Bootloader and AVR-STUB definitions to use UART3 instead of UART0 for debugging
i.e. using RX3-TX3 with an FTDI for debugging and keeping RX0-TX0 printing functionality at the same time
Does anyone have tried something similar? And if yes, would you guide me on how to do it?
THE WHYS:
Why do I need avr-stub debugging instead of serial prints?
This project has 8 custom made libraries and uses another 10 open source libraries. As you could imagine the code is getting bigger. Serial prints for debugging are no longer pretty nor useful choice
Why I would like to keep functionality on Serial Port 0?
As I mentioned before I use third party libraries that already use Serial port printing (a lot)
some of them are mentioned here:
StreamUtils,
ArduinoJson
Adafruit_SSD1306
Adafruit_GFX
WiFiEspAT
PubSubClient
I could comment out Serial.prints in the whole code but it would be a real pain and not sustainable at all, there are more than 500 usages in the mentioned libraries
And last, the aim of my device is to connect with a computer through serial port 0 and send data to a python app, so the idea is to use built in USB host port for this. I could add an FTDI over another serial port but I think it would be a waste and will not solve the previous mentioned issues
Sorry for the late reply, I couldn’t test it until today.
My original idea was to modify Arduino bootloader to use UART3 also for program uploading but it was not necessary, I realize there are two different parameters inside of platformio.ini, upload_port and debug_port, that allowed me to run those options separately
So I ended up using built in Arduino USB host (UART0) for program uploading, and, at the same time, USB to Serial TTL CP2102 connected on RX3 TX3 (UART3) for program debugging
In case that someone is struggling with this, here it is my setup:
FINAL SETUP
I put avr8-stub in libraries folder, in my case, ~/Arduino/libraries and included that path on lib_extra_dirs