cancel
Showing results for 
Search instead for 
Did you mean: 

CMSIS_OS.h warning - osThreadDef, warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]

GreenGuy
Senior III
Posted on May 01, 2018 at 03:41

Has anyone seen this warning while using FreeRTOS?  The full define is :

#define osThreadDef(name, thread, priority, instances, stacksz)  \

const osThreadDef_t os_thread_def_##name = \

{ #name, (thread), (priority), (instances), (stacksz)}

This define is being used because the current FreeRTOSConfig.h has configSUPPORT_STATIC_ALLOCATION == 0.  This was taken from the tcpip RTOS example from H7_V1.2.0.

Has anyone seen this?

1 REPLY 1
Stm32User
Associate II

I have seen this problem when using static timers, specifically with the ​osTimerStaticDef macro, but my experiences may be of help to you or others.

static osTimerId              IdleTimerId ;                                                                                                                     // This is the timer handle

osStaticTimerDef_t        IdleTimerControlBlock;                                                                                                 // This is some ram for the timer

osTimerStaticDef(IdleTimer, IdleTimer_TimeOut, &IdleTimerControlBlock);                                           // This macro creates a timer object

Here is the macro itself:-

#define osTimerStaticDef(name, function, control) \

const osTimerDef_t os_timer_def_##name = \

{ (function), (control) }

#endif

And this is what it creates the following :-

const osTimerDef_t os_timer_def_IdleTimer = { IdleTimer_TimeOut, &IdleTimerControlBlock };

IdleTimer_TimeOut is a callback function pointer, &IdleTimerControlBlock is a pointer to the TCB

I had the callback function declared as follows:-

void IdleTimer_TimeOut(void)

and got the warnings you mentioned. So I inspected the definition of osTimerDef_t

typedef struct os_timer_def {

 os_ptimer                        ptimer;                  ///< start address of a timer function

 osStaticTimerDef_t       *controlblock;     ///< control block to hold timer's data for static allocation; NULL for dynamic allocation

} osTimerDef_t;

and then os_ptimer

typedef void (*os_ptimer) (void const *argument);

You can see that the call back pointer needs to correspond with this type. I changed the call back declaration as follows and the warnings went away.

void IdleTimer_TimeOut(void const *argument)

Hope this helps.