From 9537715ebb62366c69253a03731a458578cd2838 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 20 Oct 2014 15:36:11 -0600 Subject: [PATCH] stm32f429i-disco: add wrapper for spi5 evice initializing As long as the method up_spiinitialize recognized the initialized state of the spi device by the spi enable flag of the cr1 register, it isn't safe to disable the spi device outside of the nuttx spi interface structure. But this has to be done as long as the nuttx spi interface doesn't support bidirectional data transfer for multiple devices share one spi bus. This wrapper store the initialized state of the spi device after the first initializing and should be used by each driver who shares the spi5 bus. Note! Understand this as temporary workaround. Signed-off-by: Marco Krahl --- .../stm32f429i-disco/src/stm32_ili93414ws.c | 2 +- configs/stm32f429i-disco/src/stm32_spi.c | 41 ++++++++++++++++++- .../stm32f429i-disco/src/stm32f429i-disco.h | 25 +++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/configs/stm32f429i-disco/src/stm32_ili93414ws.c b/configs/stm32f429i-disco/src/stm32_ili93414ws.c index accefd2dc2..c5a2a6c60e 100644 --- a/configs/stm32f429i-disco/src/stm32_ili93414ws.c +++ b/configs/stm32f429i-disco/src/stm32_ili93414ws.c @@ -1173,7 +1173,7 @@ FAR struct ili9341_lcd_s *stm32_ili93414ws_initialize(void) lcddbg("initialize ili9341 4-wire serial subdriver\n"); lcdvdbg("initialize spi device: %d\n", ILI93414WS_SPI_DEVICE); - spi = up_spiinitialize(ILI9341WS_SPI_DEVICE); + spi = stm32_spi5initialize(); if (spi) { diff --git a/configs/stm32f429i-disco/src/stm32_spi.c b/configs/stm32f429i-disco/src/stm32_spi.c index 2cda281789..5eb95de854 100644 --- a/configs/stm32f429i-disco/src/stm32_spi.c +++ b/configs/stm32f429i-disco/src/stm32_spi.c @@ -54,7 +54,7 @@ #include "stm32f429i-disco.h" #if defined(CONFIG_STM32_SPI1) || defined(CONFIG_STM32_SPI2) || defined(CONFIG_STM32_SPI3) ||\ - defined(CONFIG_STM32_SPI4) || defined(CONFIG_STM32_SPI5) + defined(CONFIG_STM32_SPI4) || defined(CONFIG_STM32_SPI5) /************************************************************************************ * Definitions @@ -78,6 +78,14 @@ # define spivdbg(x...) #endif +/************************************************************************************ + * Private Data + ************************************************************************************/ + +#ifdef CONFIG_STM32_SPI5 +FAR struct spi_dev_s *g_spidev5 = NULL; +#endif + /************************************************************************************ * Private Functions ************************************************************************************/ @@ -283,4 +291,35 @@ int stm32_spi5cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd) #endif /* CONFIG_SPI_CMDDATA */ +/****************************************************************************** + * Name: stm32_spi5initialize + * + * Description: + * Initialize the selected SPI port. + * As long as the method up_spiinitialize recognized the initialized state of + * the spi device by the spi enable flag of the cr1 register, it isn't safe to + * disable the spi device outside of the nuttx spi interface structure. But + * this has to be done as long as the nuttx spi interface doesn't support + * bidirectional data transfer for multiple devices share one spi bus. This + * wrapper does nothing else than store the initialized state of the spi + * device after the first initializing and should be used by each driver who + * shares the spi5 bus. + * + * Input Parameter: + * + * Returned Value: + * Valid SPI device structure reference on success; a NULL on failure + * + ******************************************************************************/ +#ifdef CONFIG_STM32_SPI5 +FAR struct spi_dev_s *stm32_spi5initialize(void) +{ + if (!g_spidev5) + { + g_spidev5 = up_spiinitialize(5); + } + + return g_spidev5; +} +#endif #endif /* CONFIG_STM32_SPI1 || CONFIG_STM32_SPI2 */ diff --git a/configs/stm32f429i-disco/src/stm32f429i-disco.h b/configs/stm32f429i-disco/src/stm32f429i-disco.h index 61a93a98e9..9a0aaf7942 100644 --- a/configs/stm32f429i-disco/src/stm32f429i-disco.h +++ b/configs/stm32f429i-disco/src/stm32f429i-disco.h @@ -258,6 +258,31 @@ int nsh_archinitialize(void); FAR struct ili9341_lcd_s *stm32_ili93414ws_initialize(void); #endif +#ifdef CONFIG_STM32_SPI5 +/****************************************************************************** + * Name: stm32_spi5initialize + * + * Description: + * Initialize the selected SPI port. + * As long as the method up_spiinitialize recognized the initialized state of + * the spi device by the spi enable flag of the cr1 register, it isn't safe to + * disable the spi device outside of the nuttx spi interface structure. But + * this has to be done as long as the nuttx spi interface doesn't support + * bidirectional data transfer for multiple devices share one spi bus. This + * wrapper does nothing else than store the initialized state of the spi + * device after the first initializing and should be used by each driver who + * shares the spi5 bus. + * + * Input Parameter: + * + * Returned Value: + * Valid SPI device structure reference on succcess; a NULL on failure + * + ******************************************************************************/ + +FAR struct spi_dev_s *stm32_spi5initialize(void); +#endif + #endif /* __ASSEMBLY__ */ #endif /* __CONFIGS_STM32F429I_DISCO_SRC_STM32F429I_DISCO_H */