STM32duino vTaskStartScheduler() problem

I have a STM32F103C86T with PL2303 to communicate over Serial. I have to implement STM32FreeRTOS but I’m having issues after I call vTaskStartScheduler() in my code. Whenever I call vTaskStartScheduler() after creating my tasks, onboard led of the STM blinks faster than I decided and stays ON for about 3 seconds then starts to blink again. While this happening, my tasks aren’t working at all.

I was trying to test the original example blink code right from GitHub but I couldn’t find a proper solution. Also, even I remove all the led codes from the example (including pinMode()), led still blinks.

 * Based on Blink_AnalogRead example from:
 * Modified by: Frederic Pillon <frederic.pillon (at)>
#include <STM32FreeRTOS.h>

// define two tasks for Blink & AnalogRead
void TaskBlink( void *pvParameters );
void TaskAnalogRead( void *pvParameters );

// the setup function runs once when you press reset or power the board
void setup() {

  // initialize serial communication at 9600 bits per second:

  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB, on LEONARDO, MICRO, YUN, and other 32u4 based boards.

  // Now set up two tasks to run independently.
    ,  (const portCHAR *)"Blink"   // A name just for humans
    ,  128  // This stack size can be checked & adjusted by reading the Stack Highwater
    ,  NULL
    ,  2  // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
    ,  NULL );

    ,  (const portCHAR *) "AnalogRead"
    ,  128  // Stack size
    ,  NULL
    ,  1  // Priority
    ,  NULL );

  // start scheduler
  Serial.println("Insufficient RAM");

void loop()
  // Empty. Things are done in Tasks.

/*---------------------- Tasks ---------------------*/

void TaskBlink(void *pvParameters)  // This is a task.
  (void) pvParameters;

  Turns on an LED on for one second, then off for one second, repeatedly.
  Most Arduinos have an on-board LED you can control. On the UNO, LEONARDO, MEGA, and ZERO
  it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN takes care
  of use the correct LED pin whatever is the board used.
  The MICRO does not have a LED_BUILTIN available. For the MICRO board please substitute
  the LED_BUILTIN definition with either LED_BUILTIN_RX or LED_BUILTIN_TX.
  e.g. pinMode(LED_BUILTIN_RX, OUTPUT); etc.
  If you want to know what pin the on-board LED is connected to on your Arduino model, check
  the Technical Specs of your board  at
  This example code is in the public domain.
  modified 8 May 2014
  by Scott Fitzgerald
  modified 2 Sep 2016
  by Arturo Guadalupi

  // initialize digital LED_BUILTIN on pin 13 as an output.

  for (;;) // A Task shall never return or exit.
    digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
    vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second
    digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
    vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second

void TaskAnalogRead(void *pvParameters)  // This is a task.
  (void) pvParameters;

  Reads an analog input on pin 0, prints the result to the serial monitor.
  Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
  This example code is in the public domain.

  for (;;)
    // read the input on analog pin 0:
    int sensorValue = analogRead(A0);
    // print out the value you read:
    vTaskDelay(1);  // one tick delay (15ms) in between reads for stability

I’d like to hear some ideas about it.
Thank you in advance,

Hello @emredaglier ,

Here are a few suggestions you could try:

  1. Build a bare-metal (without FreeRTOS) blink firmware and check if the led blinks without FreeRTOS involved.

  2. Check that the BOOT0/BOOT1 jumpers are set correctly on your board so that it runs rather than stays in the bootloader.

  3. Try increasing the stack size of each task. It’s possible that calls to the arduino libraries require more than 128 bytes of stack.

  4. Check that the LED you are observing is the correct one and matches the pin defined by LED_BUILTIN (PB12 or PC13 depending on the board). It is possible that the LED you are observing is used for serial communication rather than directly driven by the STM32F103C86T.

  5. Ensure you have selected the correct board in your arduino IDE. In particular, the definition for the ubiquitous STM32F103 “pill” board has two different LED pins depending on the variant.


Hey @PaulB-AWS,

Unluckily, these suggestions didn’t work in the way I wanted:

  1. Without FreeRTOS, I can successfully blink leds without any problem, Controlling an external and in-build led is not a problem at the moment.

  2. After uploading the initial code over Serial COM, STM32 automatically switches BOOT0 to 0. I also tried to move the jumper to 0 and reset but however that didn’t work as well.

  3. Increasing stack size to both 2048 made built-in led disappear however still none of tasks are running or working. I tried to connect a working led over PB8 which I test normally before implementing FreeRTOS but still no hope.

  4. I have a led that blinks depending on the serial messages, but that led stays on the PL2303. I’ve made some research about it but i found nothing about a serial protocol on the STM32F103 that has a connection between PC13. Also after trying to blink the built-in led without FreeRTOS using both LED_BUILTIN and PC13 worked pretty well and same.

  5. I’m pretty sure that the correct setting have been applied to my IDE properly, reading from datasheet and selecting the correct variant.

The only change became after the 3rd idea. But however still tasks aren’t running properly unfortunately. I’m wondering if you can direct me from here.

Thank you for your time in advance,

You should check the xTaskCreate return code to see if the tasks could be created successfully.
You have to have enough heap for the stacks and a bit more.

Hey @hs2,

Both of the tasks returns 1

I found out that using an older version of STM32FreeRTOS (9.0.4) solved the problem, thank you all for your time.


Thanks for reporting back ! But usually upgrading FreeRTOS is not a problem. They are very careful NOT breaking existing applications. It’s still a bit strange …

You should try to break in debugger and see what the code is doing when it appears not working.