Skip to main content
NSemrHomeInit
Associate III
October 15, 2020
Solved

GPIO for SPI communication ST example is not set?

  • October 15, 2020
  • 3 replies
  • 1050 views

Dear ST Hello,

I am using the ST example for SPI communication for getting started with STM32F429i-discovery.

This the header of the main file.

 ******************************************************************************
 
 * @file SPI/SPI_FullDuplex_ComPolling/Src/main.c 
 
 * @author MCD Application Team
 
 * @brief This sample code shows how to use STM32F4xx SPI HAL API to transmit 
 
 * and receive a data buffer with a communication process based on
 
 * Polling transfer. 
 
 * The communication is done using 2 Boards.
 
 ******************************************************************************

This the link to the project:

STM32Cube_FW_F4_V1.24.0\Projects\STM32F429I-Discovery\Examples\SPI\SPI_FullDuplex_ComPolling\SW4STM32

My question is:

1/Does ST has configured the GPIO for Clk MOSI MISO and CS?

2/In the main.h file, there no definition for CS,

/* Definition for SPIx Pins */

#define SPIx_SCK_PIN GPIO_PIN_2
 
#define SPIx_SCK_GPIO_PORT GPIOE
 
#define SPIx_SCK_AF GPIO_AF5_SPI4
 
#define SPIx_MISO_PIN GPIO_PIN_5
 
#define SPIx_MISO_GPIO_PORT GPIOE
 
#define SPIx_MISO_AF GPIO_AF5_SPI4
 
#define SPIx_MOSI_PIN GPIO_PIN_6
 
#define SPIx_MOSI_GPIO_PORT GPIOE
 
#define SPIx_MOSI_AF GPIO_AF5_SPI4

Does the CS for this device is an automatic CS?

Thank you in advance,

S.Tarik,

This topic has been closed for replies.
Best answer by TDK

> 1/Does ST has configured the GPIO for Clk MOSI MISO and CS?

The SPI pin configuration is performed within stm32f4xx_hal_msp.c:

https://github.com/STMicroelectronics/STM32CubeF4/blob/master/Projects/STM32F429I-Discovery/Examples/SPI/SPI_FullDuplex_ComPolling/Src/stm32f4xx_hal_msp.c#L67

In this example, a CS pin is not used. See the diagram in the readme.

https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Projects/STM32F429I-Discovery/Examples/SPI/SPI_FullDuplex_ComPolling

If you need to use a CS pin, I recommend initializing it as a GPIO pin and toggling it manually before/after calls to HAL_SPI_(Transmit and/or Receive), etc.

> Could you please tell me what is the purpose of the __weak keyword?

If you define a function twice and one of those definitions is weak, the linker will use the non-weak definition and the weak one will be discarded.

3 replies

NSemrHomeInit
Associate III
October 15, 2020

In the HAL_SPI_Init(SPI_HandleTypeDef *hspi) this function "HAL_SPI_MspInit(hspi);" is called.

In the HAL_SPI_MspInit(hspi) function the GPIO should be set but, in my case there is no code in this function !

__weak void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)
{
 /* Prevent unused argument(s) compilation warning */
 UNUSED(hspi);
 
 /* NOTE : This function should not be modified, when the callback is needed,
 the HAL_SPI_MspInit should be implemented in the user file
 */
}

The HAl_SPI_MspInit should be implemented in the user file.

Could you please tell me what is the purpose of the __weak keyword? When ill call HAl_SPI_MspInit to configure GPIO, the compiler will find two function prototype?

Thank you very much

TDK
TDKBest answer
October 15, 2020

> 1/Does ST has configured the GPIO for Clk MOSI MISO and CS?

The SPI pin configuration is performed within stm32f4xx_hal_msp.c:

https://github.com/STMicroelectronics/STM32CubeF4/blob/master/Projects/STM32F429I-Discovery/Examples/SPI/SPI_FullDuplex_ComPolling/Src/stm32f4xx_hal_msp.c#L67

In this example, a CS pin is not used. See the diagram in the readme.

https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Projects/STM32F429I-Discovery/Examples/SPI/SPI_FullDuplex_ComPolling

If you need to use a CS pin, I recommend initializing it as a GPIO pin and toggling it manually before/after calls to HAL_SPI_(Transmit and/or Receive), etc.

> Could you please tell me what is the purpose of the __weak keyword?

If you define a function twice and one of those definitions is weak, the linker will use the non-weak definition and the weak one will be discarded.

"If you feel a post has answered your question, please click ""Accept as Solution""."
NSemrHomeInit
Associate III
October 16, 2020

Thank you for you replay.