platform-ststm32 icon indicating copy to clipboard operation
platform-ststm32 copied to clipboard

nucleo_f429, hardwareSerial.available(), debug optimization "-O0 -g" do not work together.

Open KoolElmout opened this issue 2 years ago • 0 comments

Hello everyone,

I have discovered something strange to me which i haven't found any explanation on the web. I move my code from ststm32 15.3.0 to 15.4.1. My code was working fine either in debug or in release with the 15.3.0.

The problem:

  • The hardwareSerial...available() function does not report any data whereas the USART6->DR register has the correct data inside (USART6->SR = 0x0F8),
  • After struggling several days, i found out if i remove the non optimization constraints "debug_build_flags = -g -O0", the available() function work again correctly.

My question I am used to have the -g -O0 for debugging to be able to have a true step by step across my code. I do not understand what happened here. I would like to understand why the non optimization asked will interfere with the available() functionality. Do you have some explanation ?.

Thank in advance. Julien

Information:

  • ststm32 15.4.1
  • pio core 6.1.6 / home 3.4.3
  • vscode 1.75.1
  • With non optimization debug activate : Flash iss 3.5% full and RAM 0.7% full

Here is my platform.ini before the rectification [env:nucleo_f429zi] platform = ststm32 board = nucleo_f429zi framework = arduino debug_build_flags = -g -O0 <<=== I had to comment this line for the available() function to work. lib_deps = adafruit/Adafruit INA219@^1.2.0 extra_scripts = pre_generateBuildDate.py

Partial Code

#define BAUDRATE 115200
#define rs485_rx_pin PG9   // Arduino D0 //USART6
#define rs485_tx_pin PG14  // Arduino D1

HardwareSerial* uart;
void setup() {
    uart = new HardwareSerial(rs485_rx_pin, rs485_tx_pin);
    uart->begin(BAUDRATE);
}

void loop() {
   if (uart->available() > 0) {  //<== This available function does not work when using debug non optimization
          rxb = (uint8_t)uart->read();
    ...
    }
}

KoolElmout avatar Feb 24 '23 17:02 KoolElmout