cancel
Showing results for 
Search instead for 
Did you mean: 

FreeRTOS on STM32F1 falls through osKernelStart()

danieloneill9
Associate II
Posted on May 02, 2015 at 05:30

I am using the STM32F1DISCOVERY and generating a project for IAR from STM32CUBEMX.

I have changed the configureation to use timers and added a toggle LED command in each of the default task and timer methods, however no LEDs blink.

When I break I'm in the for loop below osKernelStart() that the code should never get to....

Looking deeper into this in vTaskStartScheduler() (tasks.c) it makes it all the way to the bottom where there is following comment and code

        /* This line will only be reached if the kernel could not be started,

        because there was not enough FreeRTOS heap to create the idle task

        or the timer task. */

        configASSERT( xReturn );

I increased the configTOTAL_HEAP_SIZE in FreeRTOSConfig.h from 2000 to 4000 but this didn't amke a difference.

Thoughts anyone?

#stm32cubemx #stm32f1 #freertos
4 REPLIES 4
FCR
Associate III
Posted on May 02, 2015 at 17:11

Hi Daniel,

Even if, at first glance, I have not seen anything wrong, I can share my ''thoughts'', purely on software side (not having a board any way),

That board, STM32VLDISCOVERY, (not available in CubeMx, or I missed something) has a STM32F100RB MCU with 8KB of RAM

(note: in CubeMx, 8KB will be the maximum value for the heap size of freertos... in theory, if nothing else requires RAM memory).

Defaut FreeRTOS configuration in CubeMx for STM32F1 is setting configMINIMAL_STACK_SIZE to 128 Words (of 32bits).

In freertos code (tasks.c), body of vTaskStartScheduler, the call to xTaskCreate for the idle task, will ask for 512 bytes allocation in the heap

(tskIDLE_STACK_SIZE == configMINIMAL_STACK_SIZE, a size in Words of 32 bits).

That should be ok with the FreeRTOS heap size originally set to 2000 Bytes.

Still in the same freertos code, the call to xTimerCreateTimerTask, itself calling xtaskCreate (in timers.c),

will ask for 1024 Bytes allocation in the heap (configTIMER_TASK_STACK_DEPTH == configMINIMAL_STACK_SIZE * 2)

That should be ok too... Except that you have a trouble...

Finally, my (software) thoughts:

- could fail if the value of configMINIMAL_STACK_SIZE was changed to something bigger (let's say 512 for instance) leading to malloc requests higher than heap size.

    ==> have you increased configMINIMAL_STACK_SIZE value or kept the original one (128)?

- could fail if xTimerQueue object is not well created by prvCheckForValidListAndQueue (first function called by xTimerCreateTimerTask in timers.c)

It would be good, any way, to get your project file (the .ioc file) so that, next week, one of my colleagues could further investigate on a board.

Regards,

Fred

I am using the STM32F1DISCOVERY and generating a project for IAR from STM32CUBEMX.

I have changed the configureation to use timers and added a toggle LED command in each of the default task and timer methods, however no LEDs blink.

When I break I'm in the for loop below osKernelStart() that the code should never get to....

Looking deeper into this in vTaskStartScheduler() (tasks.c) it makes it all the way to the bottom where there is following comment and code

        /* This line will only be reached if the kernel could not be started,

        because there was not enough FreeRTOS heap to create the idle task

        or the timer task. */

        configASSERT( xReturn );

I increased the configTOTAL_HEAP_SIZE in FreeRTOSConfig.h from 2000 to 4000 but this didn't amke a difference.

Thoughts anyone?
FCR
Associate III
Posted on May 04, 2015 at 08:18

Oops... Something forgotten in my first answer.

CubeMx generates a default task, used for init code of middlewares (such as FATFS, LWIP, and USBH), but also for user code.

It can be found in main.c file, just before the call to osKernelStart:

  /* definition and creation of defaultTask */

  osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);

  defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);

 

  /* Start scheduler */

  osKernelStart();

 

That single task requests for 128 Words on the heap.

Totally, adding that size to the one for idle task (128) and the one for tomer task (128*2), total amount is 512 Words (with CubeMx default configuration on F1).

Now, when trying to allocate 512*4 Bytes on a heap of 2000 Bytes ==> failure.

This can explain your original trouble: something wrong in the default configuration of CubeMx (at leastf for F1 series) when enabling timers. Bug.

I take the action to make it better for next CubeMx release.

But this does not explain why with a heap size now set to 4000, you still have the same trouble...

Getting your project then could help (including C code you added).

By the way, which version of CubeMx are you using?

Regards,

Fred

Hi Daniel,

Even if, at first glance, I have not seen anything wrong, I can share my ''thoughts'', purely on software side (not having a board any way),

That board, STM32VLDISCOVERY, (not available in CubeMx, or I missed something) has a STM32F100RB MCU with 8KB of RAM

(note: in CubeMx, 8KB will be the maximum value for the heap size of freertos... in theory, if nothing else requires RAM memory).

Defaut FreeRTOS configuration in CubeMx for STM32F1 is setting configMINIMAL_STACK_SIZE to 128 Words (of 32bits).

In freertos code (tasks.c), body of vTaskStartScheduler, the call to xTaskCreate for the idle task, will ask for 512 bytes allocation in the heap

(tskIDLE_STACK_SIZE == configMINIMAL_STACK_SIZE, a size in Words of 32 bits).

That should be ok with the FreeRTOS heap size originally set to 2000 Bytes.

Still in the same freertos code, the call to xTimerCreateTimerTask, itself calling xtaskCreate (in timers.c),

will ask for 1024 Bytes allocation in the heap (configTIMER_TASK_STACK_DEPTH == configMINIMAL_STACK_SIZE * 2)

That should be ok too... Except that you have a trouble...

Finally, my (software) thoughts:

- could fail if the value of configMINIMAL_STACK_SIZE was changed to something bigger (let's say 512 for instance) leading to malloc requests higher than heap size.

    ==> have you increased configMINIMAL_STACK_SIZE value or kept the original one (128)?

- could fail if xTimerQueue object is not well created by prvCheckForValidListAndQueue (first function called by xTimerCreateTimerTask in timers.c)

It would be good, any way, to get your project file (the .ioc file) so that, next week, one of my colleagues could further investigate on a board.

Regards,

Fred

I am using the STM32F1DISCOVERY and generating a project for IAR from STM32CUBEMX.

I have changed the configureation to use timers and added a toggle LED command in each of the default task and timer methods, however no LEDs blink.

When I break I'm in the for loop below osKernelStart() that the code should never get to....

Looking deeper into this in vTaskStartScheduler() (tasks.c) it makes it all the way to the bottom where there is following comment and code

        /* This line will only be reached if the kernel could not be started,

        because there was not enough FreeRTOS heap to create the idle task

        or the timer task. */

        configASSERT( xReturn );

I increased the configTOTAL_HEAP_SIZE in FreeRTOSConfig.h from 2000 to 4000 but this didn't amke a difference.

Thoughts anyone?
danieloneill9
Associate II
Posted on May 04, 2015 at 13:05

Hi Fred,

Attached is my FreeRTOSConfig.h main.c and ioc file.

I had also tried to increase the configMINIMAL_STACK_SIZE parameter to This would result in the stack exceeding the memory requirements.

I have tried with 128 and 4000 and this now works and runs correctly.

Thank you for your help!

Cheers,

Daniel

________________

Attachments :

FreeRTOSConfig.h : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzSq&d=%2Fa%2F0X0000000bN2%2FeHGnq1zzPStvCq6ehgJTHTVzkE2PlKzfYDb_NoBp0L8&asPdf=false

main.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzVy&d=%2Fa%2F0X0000000bMy%2FnDSEKvHQ_ApyXXbxglHpdFgeupVM7JlP4OndLQBON84&asPdf=false

stm32vl_test.ioc : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzVt&d=%2Fa%2F0X0000000bMz%2FPKhgSFpN8ZnB.PbtOtXsQBhi3VFmQYxiSJsraA_h0vw&asPdf=false
FCR
Associate III
Posted on May 13, 2015 at 15:42

Hi Daniel,

For your information, a fix has been done and will be available in the next CubeMx release (4.8, available in the coming weeks).

The default value, 2000, for the heap size was kept only for the MCU with 4K of RAM.

For others, that value will be set to 3000 (in CubeMx 4.8).

In your case, 3000 should be enough (according to the tasks we listed previously).

Nothing prevents you from keeping 4000, as long as the total application is ok with that (your MCU having 8K of RAM, probably still some space left, but not that much any way 😉 )

Regards,

Fred

Hi Fred,

Attached is my FreeRTOSConfig.h main.c and ioc file.

I had also tried to increase the configMINIMAL_STACK_SIZE parameter to 256. This would result in the stack exceeding the memory requirements.

I have tried with 128 and 4000 and this now works and runs correctly.

Thank you for your help!

Cheers,

Daniel