Skip to main content
magene
Senior
December 26, 2020
Solved

Using SPI with STM32L4R9 Discovery Board

  • December 26, 2020
  • 2 replies
  • 908 views

Unfortunately there isn't an example provided for SPI on the STM32L4R9 Disco board. I can tell from the User Manual that I need to set the quad SPDT switch on the board to the SPI configuration. If I understand table 20 in the User Manual, I need to set GPIO6 and GPIO7 of the MFX to 0. There are dozens of functions in the STM32l4R9i-discoveryxx.c and mfxstm32l152.c files so I'm confused about how to initialize and use the MFX. Can someone point me at some example code that explains how to set up and use the MFX on the STM32L4R9 discovery board to set some GPIO lines?

Thanks

This topic has been closed for replies.
Best answer by Tesla DeLorean

Look at the BSP_IO implementation

void BSP_LED_Init(Led_TypeDef Led)
{
 GPIO_InitTypeDef GPIO_InitStructure;
 
 if (Led == LED2)
 {
 /* Enable the GPIO_LED clock */
 LED2_GPIO_CLK_ENABLE();
 
 /* Configure the GPIO_LED pin */
 GPIO_InitStructure.Pin = LED_PIN[Led];
 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
 GPIO_InitStructure.Pull = GPIO_NOPULL;
 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
 
 HAL_GPIO_Init(LED2_GPIO_PORT, &GPIO_InitStructure);
 /* By default, turn off LED */
 HAL_GPIO_WritePin(LED2_GPIO_PORT, GPIO_InitStructure.Pin, GPIO_PIN_SET);
 }
 else
 {
 /* Initialize the IO functionalities */
 if (BSP_IO_Init() == IO_ERROR)
 {
 BSP_ErrorHandler();
 }
 
 /* By default, turn off LED */
 BSP_IO_WritePin(LED_PIN[Led], GPIO_PIN_SET);
 
 BSP_IO_ConfigPin(LED_PIN[Led],IO_MODE_OUTPUT);
 }
 
} 

2 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
December 26, 2020

Look at the BSP_IO implementation

void BSP_LED_Init(Led_TypeDef Led)
{
 GPIO_InitTypeDef GPIO_InitStructure;
 
 if (Led == LED2)
 {
 /* Enable the GPIO_LED clock */
 LED2_GPIO_CLK_ENABLE();
 
 /* Configure the GPIO_LED pin */
 GPIO_InitStructure.Pin = LED_PIN[Led];
 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
 GPIO_InitStructure.Pull = GPIO_NOPULL;
 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
 
 HAL_GPIO_Init(LED2_GPIO_PORT, &GPIO_InitStructure);
 /* By default, turn off LED */
 HAL_GPIO_WritePin(LED2_GPIO_PORT, GPIO_InitStructure.Pin, GPIO_PIN_SET);
 }
 else
 {
 /* Initialize the IO functionalities */
 if (BSP_IO_Init() == IO_ERROR)
 {
 BSP_ErrorHandler();
 }
 
 /* By default, turn off LED */
 BSP_IO_WritePin(LED_PIN[Led], GPIO_PIN_SET);
 
 BSP_IO_ConfigPin(LED_PIN[Led],IO_MODE_OUTPUT);
 }
 
} 

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
magene
mageneAuthor
Senior
December 27, 2020

Excellent. For future readers, it's actually LED1 that is connected to the MFX chip and eventually uses the BSP_IO_WritePin function in the stm32l4r9i_discovery_io.c file which uses io_driver->WritePin(IO_I2C_ADDRESS, IO_Pin, 0) to actually set the state of the pin.