cancel
Showing results for 
Search instead for 
Did you mean: 

Error in the code

juvf
Associate II

Hello

After generating the code with FreeRTOS, the cmsis_o2.c file is generated. I run the build and get warnings:

make -j4 all

arm-none-eabi-gcc "../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c" -mcpu=cortex-m4 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F429xx -c -I../Core/Inc -I"C:/work/wsCubeIde/bi0470_lvgl/Core" -I"C:/work/wsCubeIde/bi0470_lvgl/canlib" -I"C:/work/wsCubeIde/bi0470_lvgl/Middlewares/Third_Party" -I"C:/work/wsCubeIde/bi0470_lvgl" -I"C:/work/wsCubeIde/bi0470_lvgl/lvgl" -I../Core/app -I../Drivers/STM32F4xx_HAL_Driver/Inc -I../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32F4xx/Include -I../Drivers/CMSIS/Include -I../Middlewares/Third_Party/FreeRTOS/Source/include -I../Middlewares/Third_Party/lvgl -I../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F -I../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 -O0 -ffunction-sections -fdata-sections -Wall -pedantic-errors -Wno-variadic-macros -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.d" -MT"Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.o"

../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c: In function 'osThreadTerminate':

../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c:658:16: warning: unused variable 'hTask' [-Wunused-variable]

658 | TaskHandle_t hTask = (TaskHandle_t)thread_id;

| ^~~~~

../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c: In function 'osTimerDelete':

../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c:1079:17: warning: unused variable 'hTimer' [-Wunused-variable]

1079 | TimerHandle_t hTimer = (TimerHandle_t)timer_id;

| ^~~~~~

../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c: In function 'osEventFlagsDelete':

../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c:1275:22: warning: unused variable 'hEventGroup' [-Wunused-variable]

1275 | EventGroupHandle_t hEventGroup = (EventGroupHandle_t)ef_id;

| ^~~~~~~~~~~

../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c: In function 'osSemaphoreDelete':

../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c:1666:21: warning: unused variable 'hSemaphore' [-Wunused-variable]

1666 | SemaphoreHandle_t hSemaphore = (SemaphoreHandle_t)semaphore_id;

| ^~~~~~~~~~

../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c: In function 'osMessageQueueDelete':

../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c:1919:17: warning: unused variable 'hQueue' [-Wunused-variable]

 

Here is your code

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);

}

 

Why do you declare the TaskHandle_t hTask variable if you don't use it?

 I fixed this code:

 

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);

}

 

But after the new code generation, all the warnings returned.

 

Just do not say that warnings are possible. The code should be collected without warnings.

Bugs are hiding behind every warning. If you enable -Werror, the code will not compile.

 

In this case, there is no need for an unused variable and the code is easily corrected.

Can you fix your cmsis_os2.c? 

 

0 REPLIES 0