cancel
Showing results for 
Search instead for 
Did you mean: 

In STM32-G0B1RE, I have an issue of SPI peripheral clock configuration and clock initialization.

Grace_04
Associate

I'm trying to communicate with external device using SPI, but I'm not getting any SPI peripheral clock at configuration level and there is no clock initialization details in SPI Init(); 

void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)

{

GPIO_InitTypeDef GPIO_InitStruct = {0};

if(hspi->Instance==SPI1)

{

/* USER CODE BEGIN SPI1_MspInit 0 */

 

/* USER CODE END SPI1_MspInit 0 */

/* Peripheral clock enable */

__HAL_RCC_SPI1_CLK_ENABLE();

 

__HAL_RCC_GPIOA_CLK_ENABLE();

/**SPI1 GPIO Configuration

PA1 ------> SPI1_SCK

PA6 ------> SPI1_MISO

PA7 ------> SPI1_MOSI

*/

GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_6|GPIO_PIN_7;

GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

GPIO_InitStruct.Alternate = GPIO_AF0_SPI1;

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 

/* USER CODE BEGIN SPI1_MspInit 1 */

 

/* USER CODE END SPI1_MspInit 1 */

}

}

Screenshot (275).png

 

 

 

 

 

1 REPLY 1
TDK
Guru

I'm not sure what you're showing us here, perhaps a misunderstanding?

HAL_SPI_MspInit initializes the pins, that's it. The peripheral initialization will be in MX_SPI1_Init which calls HAL_SPI_Init. The function MX_SPI1_Init should be in main.c.

 

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