2015-05-01 08:30 PM
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 #freertos2015-05-02 08:11 AM
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?2015-05-03 11:18 PM
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?2015-05-04 04:05 AM
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=falsemain.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzVy&d=%2Fa%2F0X0000000bMy%2FnDSEKvHQ_ApyXXbxglHpdFgeupVM7JlP4OndLQBON84&asPdf=falsestm32vl_test.ioc : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzVt&d=%2Fa%2F0X0000000bMz%2FPKhgSFpN8ZnB.PbtOtXsQBhi3VFmQYxiSJsraA_h0vw&asPdf=false2015-05-13 06:42 AM
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, FredHi 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