I am trying to call a library function with signature
void GPIO_Init(GPIO_InitTypeDef* GPIO_InitStruct)
where GPIO_InitTypeDef is a typedef struct.
I have tried doing the following:
GPIO_InitTypeDef NE1 = {
7, GPIO_Mode_AF, GPIO_Speed_25MHz, GPIO_OType_PP, GPIO_PuPd_UP
};
GPIO_Init(NE1);
but I get a compiler error
error: incompatible type for argument 1 of ‘GPIO_Init’ expected
‘struct GPIO_InitTypeDef *’ but argument is of type ‘GPIO_InitTypeDef’
I have also tried using the struct keyword:
struct GPIO_InitTypeDef NE1 = {
7, GPIO_Mode_AF, GPIO_Speed_25MHz, GPIO_OType_PP, GPIO_PuPd_UP
};
GPIO_Init(NE1);
but them I get the compiler error
error: storage size of ‘NE1’ isn’t known
What am I doing wrong, and what is the proper way to call GPIO_Init?
You need to use:
That function expects a pointer to a
GPIO_InitStructstructure, as indicated with:But your
NE1variable is an actual structure, so you have to use&to get the pointer to it, so you can pass that.Because you’re trying to pass the structure instead of a pointer to a structure, that’s what’s causing your
incompatible typeerror.