Keil Logo

ARM: Example Ported from Keil RTX5 to FreeRTOS Does Not Run


Information in this knowledgebase article applies to:

  • CMSIS-FreeRTOS

SYMPTOM

To test, if we can use the CMSIS RTOS2 FreeRTOS implementation, I used an existing middleware example and switched in the RTE Run-Time manager the CMSIS RTOS2 implementation from Keil RTX5 to FreeRTOS. After that, the project builds without error, but it does not run. We thought, the actual RTOS2 implementation does not matter. So, what is the problem here?

CAUSE

The FreeRTOS CMSIS RTOS2 implementation has unfortunately some limitations. One is, that threads can't be created, if the Attributes parameter of the osThreadNew() function only specifies custom stack memory. So, if the example starts e. g. the app_main thread like this:

#define APP_MAIN_STK_SZ (1024U)
uint64_t app_main_stk[APP_MAIN_STK_SZ / 8];
const osThreadAttr_t app_main_attr = {
  .stack_mem  = &app_main_stk[0],
  .stack_size = sizeof(app_main_stk)
};

int main( void )
{
  ...
  osThreadNew(app_main, NULL, &app_main_attr);
  ...
}

the thread creation will fail with CMSIS-FreeRTOS. And so, the application will not run.
This is also mentioned in the limitations section of the CMSIS-FreeRTOS pack documentation.

RESOLUTION

To get the thread created, either remove the custom stack specification (default stack size needs to be sufficient) or add suitable values also for the control block structure as shown in the example:

#include "FreeRTOS.h"

#define APP_MAIN_STK_SZ (1024U)
uint64_t app_main_stk[APP_MAIN_STK_SZ / 8];
StaticTask_t app_main_cb;
const osThreadAttr_t app_main_attr = {
  .stack_mem  = &app_main_stk[0],
  .stack_size = sizeof(app_main_stk),
  .cb_mem     = &app_main_cb,
  .cb_size    = sizeof(app_main_cb)
};

With that the thread creation will work and also the example project should run.

MORE INFORMATION

Last Reviewed: Friday, November 13, 2020


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.