2020-10-15 8:09 AM
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_SPI4Does the CS for this device is an automatic CS?
Thank you in advance,
S.Tarik,
Solved! Go to Solution.
2020-10-15 10:27 AM
> 1/Does ST has configured the GPIO for Clk MOSI MISO and CS?
The SPI pin configuration is performed within stm32f4xx_hal_msp.c:
In this example, a CS pin is not used. See the diagram in the readme.
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.
2020-10-15 8:39 AM
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
2020-10-15 10:27 AM
> 1/Does ST has configured the GPIO for Clk MOSI MISO and CS?
The SPI pin configuration is performed within stm32f4xx_hal_msp.c:
In this example, a CS pin is not used. See the diagram in the readme.
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.
2020-10-16 5:28 AM
Thank you for you replay.
