cancel
Showing results for 
Search instead for 
Did you mean: 

Error in the Stm32CudeIde program

juvf1
Associate

When generating code, the Code Ide generates the following code:

/*

* Name: cmsis_os2.c

* Purpose: CMSIS RTOS2 wrapper for FreeRTOS

*/

...

osStatus_t osThreadTerminate (osThreadId_t thread_id) {

TaskHandle_t hTask = (TaskHandle_t)thread_id;

osStatus_t stat;

#ifndef USE_FreeRTOS_HEAP_1

eTaskState tstate;

 

if (IS_IRQ()) {

stat = osErrorISR;

}

else if (hTask == NULL) {

stat = osErrorParameter;

}

else {

tstate = eTaskGetState (hTask);

 

if (tstate != eDeleted) {

stat = osOK;

vTaskDelete (hTask);

} else {

stat = osErrorResource;

}

}

#else

stat = osError;

#endif

 

return (stat);

}

 

I have not defined USE_FreeRTOS_HEAP_1. Why is the 'hTask' variable in the code?

 The compiler throws an error (or a warning, depending on the settings)

../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c:658:16: error: unused variable 'hTask' [-Werror=unused-variable]

 

 

Why do you declare if you don't use it? The code should be like this:

 

osStatus_t osThreadTerminate (osThreadId_t thread_id) {

osStatus_t stat;

#ifndef USE_FreeRTOS_HEAP_1

TaskHandle_t hTask = (TaskHandle_t)thread_id;

eTaskState tstate;

 

if (IS_IRQ()) {

stat = osErrorISR;

}

else if (hTask == NULL) {

stat = osErrorParameter;

}

else {

tstate = eTaskGetState (hTask);

 

if (tstate != eDeleted) {

stat = osOK;

vTaskDelete (hTask);

} else {

stat = osErrorResource;

}

}

#else

stat = osError;

#endif

 

return (stat);

}

 

After each code generation, I have to fix several such places. How to fix it?

Where does the generator get the code from? Maybe there is a template in the IDE that can be corrected and there will be no error? 

 

2 REPLIES 2
Bob S
Principal

Yeah - this can be a pain.  I've modified several of the stock HAL and CubeMX-generated files to fix warnings generated by strict compiler warning settings (added lots of UNUSED() lines for unused variables).  I use GIT (any version control program will work).  Then just revert all modified HAL files after each CubeMX code gen.  It takes some effort, but works and is less effort than re-editing those files one by one to add back my changes.

It's a Kludge, but thanks anyway. I searched in the depths of the IDE for a template for cmsis_os 2.c - I did not find it.

You can do this: fix cmsis_os 2.c, make a copy in cmsis_os 2.copy. Add the command "rm cmsis_os 2.c && cp cmsis_os 2.copy cmsis_os 2.c" to "prebuild"