Including the FreeRTOS makes the stm32 do nothing

Hi,
i wanted to test out freeRTOS support on a stm32f103c8 bluepill, but i encountered a strange problem. If i add the lib_deps = stm32duino/STM32duino FreeRTOS@^10.3.1 to my platfomIO.ini file my bluepill just does nothing after uploading. Meaning opening the serial monitor does not work, and no code seems to be executed (even a blink sketch doesn’t work) without the freeRTOS dependency in the platformIO.ini file everything works as expected

my simple test code:

#include <Arduino.h>
// the setup routine runs once when you press reset:
void setup() {
  Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
  Serial.println("alive");
  delay(500);        // delay in between reads for stability
}

My platformI.ini file:

[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino
upload_protocol = stlink
debug_tool = stlink
;lib_deps = stm32duino/STM32duino FreeRTOS@^10.3.1
build_flags = 
	-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
	-D USBCON

What happens when you use the intended example source code? STM32FreeRTOS/frBlinkPrint.ino at main · stm32duino/STM32FreeRTOS · GitHub

the same behaviour: absolutely no reaction from the bluepill, no blinking and no serial over USB.
When i use the arduino IDE to upload the same code, the blinking works, but only as long as no usb cable is plugged in. When the USB cable is plugged in the board also does nothing.

It does also blink when i remove the USB build flags from the platfomIO.ini file

Ah, for USB-CDC, you need to add

monitor_dtr = 1

to the platformio.ini per Difficulty with getting USB serial [USB CDC] working - #6 by maxgerhardt.

Sadly, that does not help, the bluepill still does not blink when uploaded with the RTOS library

Do you get a working USB serial with the above modification and without FreeRTOS?

Yes, without the freeRTOS library in the lib deps, everything works as expected with or without the monitor_dtr line

With the FreeRTOS library enabled, can you use the debugger to see where it’s stuck / crashes?

Given the FreeRTOS example sketch I referenced above.

I had an error in image previously, that’s why i deleted that post:

When i run the example code without any break points, it stops at the following point:
image

also i get a “USB device not recognized” message in windows. When i then click on resume the bluepill starts blinking, but there is no usb serial port

Hm, halting the USB core during enumeration is bad.

Try and add

debug_init_break = b loop

to skip execution until the loop() function.

Now it stops here:


I still get the same “USB not recognized” message in windows and i cant resume because it will forever stop in the empty loop.

When i add a non-existing function to debug_init_break the code does not stop and i dont get the not recognized message, however the bluepill does not blink. When i then pause execution, it always goes here and it seems stuck here:

What’s the call backtrace when you are in this function?


I comes from USBD_SetClassConfig

i guess there must be some incompatibility between the stm32 usb stack and the freertos implementation. I i will probably have to also open an issue in the stm32duino github.

Well that looks deadly, a malloc within the USB interrupt, that’s not compatible with FreeRTOS at all

Is there any progress on this issue? I have the same problem. Please note that using FreeRTOS 10.2.1 everything works just fine.

Same stacktrace, malloc called in the interrupt?

I don’t have any debugging tool unfortunately, however, my code works with 10.3.1 if I remove the USB related defines (-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC -D USBCON) from build flags in platformio.ini . Looks like the same exact problem.