cancel
Showing results for 
Search instead for 
Did you mean: 

I'm trying to create my own GPIO API using LL library on STM32F4. When declaring GPIO port I get warning: initialization of 'long unsigned int' from 'GPIO_TypeDef *' {aka 'struct <anonymous> *'} makes integer from pointer without a cast [-Wint-conversion]

DSimp.1
Associate III

Hey,

I create some enums and struct to declare specific pin settings. In .h file I create these struct and enums:

typedef enum {

ePin_Led_Stat=0,

ePin_Led_GPS_Fix,

ePin_USART1_Tx,

ePin_USART1_Rx,

ePin_USART2_Tx,

ePin_USART2_Rx,

  ePin_Name_Last

} ePin_Name;

typedef struct {

uint32_t port;

uint32_t pin;

uint32_t mode;

uint32_t speed;

uint32_t output_type;

uint32_t pull;

uint32_t alternate;

uint32_t baudRate;

uint32_t dataWidth;

uint32_t stopBits;

uint32_t parity;

uint32_t transferDirection;

uint32_t hardwareFlowControl;

uint32_t overSampling;

} s_GPIO_Init_t;

Then in .C file I wrote this code:

s_GPIO_Init_t pin_name[] = {

[ePin_Led_Stat] =  {GPIOB, LL_GPIO_PIN_5, LL_GPIO_MODE_OUTPUT, LL_GPIO_SPEED_FREQ_LOW, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_NO, 0, 0, 0, 0, 0, 0, 0, 0},

[ePin_Led_GPS_Fix] = {GPIOB, LL_GPIO_PIN_4, LL_GPIO_MODE_OUTPUT, LL_GPIO_SPEED_FREQ_LOW, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_NO, 0, 0, 0, 0, 0, 0, 0, 0},

[ePin_USART1_Tx] =  {GPIOB, LL_GPIO_PIN_6, LL_GPIO_MODE_ALTERNATE, LL_GPIO_SPEED_FREQ_VERY_HIGH, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_NO, LL_GPIO_AF_7, 115200, LL_USART_DATAWIDTH_8B, LL_USART_STOPBITS_1, LL_USART_PARITY_NONE, LL_USART_DIRECTION_TX_RX, LL_USART_HWCONTROL_NONE, LL_USART_OVERSAMPLING_16},

[ePin_USART1_Rx] =  {GPIOB, LL_GPIO_PIN_7, LL_GPIO_MODE_ALTERNATE, LL_GPIO_SPEED_FREQ_VERY_HIGH, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_NO, LL_GPIO_AF_7, 115200, LL_USART_DATAWIDTH_8B, LL_USART_STOPBITS_1, LL_USART_PARITY_NONE, LL_USART_DIRECTION_TX_RX, LL_USART_HWCONTROL_NONE, LL_USART_OVERSAMPLING_16},

[ePin_USART2_Tx] =  {GPIOD, LL_GPIO_PIN_5, LL_GPIO_MODE_ALTERNATE, LL_GPIO_SPEED_FREQ_VERY_HIGH, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_NO, LL_GPIO_AF_7, 115200, LL_USART_DATAWIDTH_8B, LL_USART_STOPBITS_1, LL_USART_PARITY_NONE, LL_USART_DIRECTION_TX_RX, LL_USART_HWCONTROL_NONE, LL_USART_OVERSAMPLING_16},

[ePin_USART2_Rx] =  {GPIOD, LL_GPIO_PIN_6, LL_GPIO_MODE_ALTERNATE, LL_GPIO_SPEED_FREQ_VERY_HIGH, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_NO, LL_GPIO_AF_7, 115200, LL_USART_DATAWIDTH_8B, LL_USART_STOPBITS_1, LL_USART_PARITY_NONE, LL_USART_DIRECTION_TX_RX, LL_USART_HWCONTROL_NONE, LL_USART_OVERSAMPLING_16}

};

void GPIO_Init (ePin_Name Pin) {

LL_GPIO_InitTypeDef GPIO_InitStruct = {0};

LL_USART_InitTypeDef USART_InitStruct = {0};

LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA);

LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB);

LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOD);

GPIO_InitStruct.Pin = pin_name[Pin].pin;

GPIO_InitStruct.Mode = pin_name[Pin].mode;

GPIO_InitStruct.Speed = pin_name[Pin].speed;

GPIO_InitStruct.OutputType = pin_name[Pin].output_type;

GPIO_InitStruct.Pull = pin_name[Pin].pull;

GPIO_InitStruct.Alternate = pin_name[Pin].alternate;

LL_GPIO_Init(pin_name[Pin].port, &GPIO_InitStruct);

if ( pin_name[Pin].alternate == LL_GPIO_AF_7 ) {

USART_InitStruct.BaudRate = pin_name[Pin].baudRate;

USART_InitStruct.DataWidth = pin_name[Pin].dataWidth;

USART_InitStruct.StopBits = pin_name[Pin].stopBits;

USART_InitStruct.Parity = pin_name[Pin].parity;

USART_InitStruct.TransferDirection = pin_name[Pin].transferDirection;

USART_InitStruct.HardwareFlowControl = pin_name[Pin].hardwareFlowControl;

USART_InitStruct.OverSampling = pin_name[Pin].overSampling;

if (Pin == 2 || Pin == 3) {

LL_USART_Init(USART1, &USART_InitStruct);

LL_USART_ConfigAsyncMode(USART1);

LL_USART_Enable(USART1);

} else {

LL_USART_Init(USART1, &USART_InitStruct);

LL_USART_ConfigAsyncMode(USART1);

LL_USART_Enable(USART1);

}

}

}

void GPIO_Set (ePin_Led led_pin) {

LL_GPIO_SetOutputPin(pin_name[led_pin].port, pin_name[led_pin].pin);

}

void GPIO_Reset (ePin_Led led_pin) {

LL_GPIO_ResetOutputPin(pin_name[led_pin].port, pin_name[led_pin].pin);

}

void GPIO_Toggle (ePin_Led led_pin) {

LL_GPIO_TogglePin(pin_name[led_pin].port, pin_name[led_pin].pin);

}

void GPIO_Read (ePin_Name Pin) {

LL_GPIO_ReadInputPort(pin_name[Pin].port);

}

As I understand the warning, I'm trying to get specific port with pin_name[Pin].port , but something isn't right with types. I also get other warnings for all functions when trying to pass this kind of port calling: passing argument 1 of 'LL_GPIO_Init' makes pointer from integer without a cast [-Wint-conversion].

Any ideas how to declare port in my struct to fix this?

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

> uint32_t port;

this should be of type GPIO_TypeDef *, not uint32_t, in order to avoid the warning.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
TDK
Guru

> uint32_t port;

this should be of type GPIO_TypeDef *, not uint32_t, in order to avoid the warning.

If you feel a post has answered your question, please click "Accept as Solution".
DSimp.1
Associate III

Yeah, I managed to figure that out by myself, but thank you, this was indeed the problem :)