VS Arduino
>> >> Software serial can't receive messages when debugging?
https://www.visualmicro.com/forums/YaBB.pl?num=1579231013

Message started by fantasyhpu on Jan 17th, 2020 at 3:16am

Title: Software serial can't receive messages when debugging?
Post by fantasyhpu on Jan 17th, 2020 at 3:16am
Hi, I want to debug arduino uno, I followed the instructions posted in arduino project hub:
https://create.arduino.cc/projecthub/visualmicro/arduino-uno-debugging-f4d470?f=1
and my test code is:

Code (c++):

#define _DEBUG 1

#ifdef _DEBUG
#include <SoftwareSerial.h>
#include <avr8-stub.h>
#include <app_api.h>
#define USE_SERIAL SWSerial
SoftwareSerial USE_SERIAL(2, 3);
#else
#define USE_SERIAL Serial
#endif


const int NUMBER_OF_FIELDS = 3;
int fieldIndex = 0;
int values[NUMBER_OF_FIELDS] = { 0 };

void setup()
{
#ifdef _DEBUG
    debug_init();
#endif
    USE_SERIAL.begin(9600);
}

void loop()
{
    USE_SERIAL.println(fieldIndex);
    if (USE_SERIAL.available())
    {
        char ch = USE_SERIAL.read();
        if (ch >= '0' && ch <= '9')
        {
            if (fieldIndex < NUMBER_OF_FIELDS)
            {
                values[fieldIndex] = (values[fieldIndex] * 10) + (ch - '0');
            }
        }
        else if (ch == ',')
        {
            fieldIndex++;
        }
        else
        {
            for (int i = 0; i < min(NUMBER_OF_FIELDS, fieldIndex); i++)
            {
                USE_SERIAL.println(values[i]);
                values[i] = 0;
            }
            fieldIndex = 0;
        }
    }
}

The serial port used to upload the sketch is COM9, and the serial port generated by the USB-to-Serial board is COM7.
When debugging, I can get the messages output by "USE_SERIAL.println(fieldIndex);", but the COM7 can't receive the messages I send to it (the message is "12,1,3"), as the test.git file illustrated, so the "debug arrow" can't enter the "if (USE_SERIAL.available()) {...}" statement.

For a test, I quit the debug session, and upload the code to arduino uno, then I open serial monitor and select COM7 and click the "Connect" button in the "Serial | COM7" window, typing "12,1,3", then click the "send data to the connected device", I find that the software serial works very well.

But why the software serial port can not receive messages in the debug session?
Can anyone tell me how to do with it?
Best regards.
test.gif ( 870 KB | 4 Downloads )

Title: Re: Software serial can't receive messages when debugging?
Post by Simon Hopkinson on Jan 17th, 2020 at 10:41am
This may be a limitation of the GDBStub Implementation (receiving data), as when it is paused on a break point, there are no interrupts happening either.

The Serial Debugger may be a better option for the Uno in this case, and it allows changing data on the fly when sat on a break point as you require.

To move to this select "Debug: Serial", and remove the GDBStub changes and library from your code.

The Serial debugger requires re-upload of the code when breakpoints are edited or added, so add in the points to stop or trace now.  Variables can be added for editing using the Breakpoint Actions and {variableName} syntax.

An example video showing this feature (used for calibration often) is on Youtube Here.

Further Info:
Serial Debugger
Serial Debug Breakpoint Actions


Title: Re: Software serial can't receive messages when debugging?
Post by fantasyhpu on Jan 17th, 2020 at 11:48am

Simon@Visual Micro wrote on Jan 17th, 2020 at 10:41am:
This may be a limitation of the GDBStub Implementation (receiving data), as when it is paused on a break point, there are no interrupts happening either.

The Serial Debugger may be a better option for the Uno in this case, and it allows changing data on the fly when sat on a break point as you require.

To move to this select "Debug: Serial", and remove the GDBStub changes and library from your code.

The Serial debugger requires re-upload of the code when breakpoints are edited or added, so add in the points to stop or trace now.  Variables can be added for editing using the Breakpoint Actions and {variableName} syntax.

An example video showing this feature (used for calibration often) is on Youtube Here.

Further Info:
Serial Debugger
Serial Debug Breakpoint Actions



Hi, thank you very much for tellimg me the reasons.
Best regards.

VS Arduino » Powered by YaBB 2.6.12!
YaBB Forum Software © 2000-2024. All Rights Reserved.