From a3e1bdde14b5a016d3e2c83a0d93c723ca05668f Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Thu, 18 Aug 2016 08:38:49 -0600 Subject: [PATCH] STM32 SPI: Fix STM32F3XXX SPI driver to read 8-bit correctly. --- arch/arm/src/stm32/stm32_spi.c | 35 ++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/arch/arm/src/stm32/stm32_spi.c b/arch/arm/src/stm32/stm32_spi.c index b8400c6564..d82b6eb3cb 100644 --- a/arch/arm/src/stm32/stm32_spi.c +++ b/arch/arm/src/stm32/stm32_spi.c @@ -193,6 +193,9 @@ struct stm32_spidev_s /* Helpers */ static inline uint16_t spi_getreg(FAR struct stm32_spidev_s *priv, uint8_t offset); +#if defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F37XX) +static inline uint8_t spi_getreg8(FAR struct stm32_spidev_s *priv, uint8_t offset); +#endif static inline void spi_putreg(FAR struct stm32_spidev_s *priv, uint8_t offset, uint16_t value); #if defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F37XX) @@ -536,6 +539,28 @@ static inline uint16_t spi_getreg(FAR struct stm32_spidev_s *priv, uint8_t offse return getreg16(priv->spibase + offset); } +/************************************************************************************ + * Name: spi_getreg8 + * + * Description: + * Get the contents of the SPI register at offset + * + * Input Parameters: + * priv - private SPI device structure + * offset - offset to the register of interest + * + * Returned Value: + * The contents of the 16-bit register + * + ************************************************************************************/ + +#if defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F37XX) +static inline uint8_t spi_getreg8(FAR struct stm32_spidev_s *priv, uint8_t offset) +{ + return getreg8(priv->spibase + offset); +} +#endif + /************************************************************************************ * Name: spi_putreg * @@ -615,9 +640,15 @@ static inline uint16_t spi_readword(FAR struct stm32_spidev_s *priv) * at the receiver side, as data can be lost if it is not in line." */ - /* REVISIT */ + if (priv->nbits < 9) + { + return (uint16_t)spi_getreg8(priv, STM32_SPI_DR_OFFSET); + } + else #endif - return spi_getreg(priv, STM32_SPI_DR_OFFSET); + { + return spi_getreg(priv, STM32_SPI_DR_OFFSET); + } } /************************************************************************************