From aa5b03d54d50e12fef3d0734d9afd2ff3a13c967 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Fri, 25 Aug 2017 08:43:06 +0000 Subject: Fixed bug #879. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10483 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/ports/STM32/LLD/SPIv1/hal_spi_lld.c | 2 +- os/hal/ports/STM32/LLD/SPIv2/hal_spi_lld.c | 2 +- readme.txt | 2 ++ .../STM32F4xx-SPI (OpenOCD, Flash and Run).launch | 2 +- testhal/STM32/STM32F7xx/SPI/main.c | 20 +++++++++++++++----- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/os/hal/ports/STM32/LLD/SPIv1/hal_spi_lld.c b/os/hal/ports/STM32/LLD/SPIv1/hal_spi_lld.c index 4be8cedc1..0cee5729b 100644 --- a/os/hal/ports/STM32/LLD/SPIv1/hal_spi_lld.c +++ b/os/hal/ports/STM32/LLD/SPIv1/hal_spi_lld.c @@ -422,7 +422,7 @@ void spi_lld_start(SPIDriver *spip) { STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD; } /* SPI setup and enable.*/ - spip->spi->CR1 = 0; + spip->spi->CR1 &= ~SPI_CR1_SPE; spip->spi->CR1 = spip->config->cr1 | SPI_CR1_MSTR | SPI_CR1_SSM | SPI_CR1_SSI; spip->spi->CR2 = spip->config->cr2 | SPI_CR2_SSOE | SPI_CR2_RXDMAEN | diff --git a/os/hal/ports/STM32/LLD/SPIv2/hal_spi_lld.c b/os/hal/ports/STM32/LLD/SPIv2/hal_spi_lld.c index 914249fe7..b3aafff07 100644 --- a/os/hal/ports/STM32/LLD/SPIv2/hal_spi_lld.c +++ b/os/hal/ports/STM32/LLD/SPIv2/hal_spi_lld.c @@ -425,7 +425,7 @@ void spi_lld_start(SPIDriver *spip) { } /* SPI setup and enable.*/ - spip->spi->CR1 = 0; + spip->spi->CR1 &= ~SPI_CR1_SPE; spip->spi->CR1 = spip->config->cr1 | SPI_CR1_MSTR; spip->spi->CR2 = spip->config->cr2 | SPI_CR2_FRXTH | SPI_CR2_SSOE | SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN; diff --git a/readme.txt b/readme.txt index 069bdb27c..e11192d5c 100644 --- a/readme.txt +++ b/readme.txt @@ -93,6 +93,8 @@ dependencies and configuration directories. This makes possible to have multiple non-conflicting makefiles in the same project. Updated the various platform.mk implementing "smart build" mode. +- HAL: Fixed STM32 SPI problem in spi_lld_start() (bug #879)(backported + to 17.6.1 and 16.1.9). - HAL: Fixed invalid STM32 CAN3 filters initialization (bug #878) (backported to 17.6.1). - HAL: Fixed missing CAN definitions in STM32L432 registry entry (bug #877) diff --git a/testhal/STM32/STM32F4xx/SPI/debug/STM32F4xx-SPI (OpenOCD, Flash and Run).launch b/testhal/STM32/STM32F4xx/SPI/debug/STM32F4xx-SPI (OpenOCD, Flash and Run).launch index 03aa07db2..7d1aebba0 100644 --- a/testhal/STM32/STM32F4xx/SPI/debug/STM32F4xx-SPI (OpenOCD, Flash and Run).launch +++ b/testhal/STM32/STM32F4xx/SPI/debug/STM32F4xx-SPI (OpenOCD, Flash and Run).launch @@ -33,7 +33,7 @@ - + diff --git a/testhal/STM32/STM32F7xx/SPI/main.c b/testhal/STM32/STM32F7xx/SPI/main.c index 2b0c1744b..c9bc3696e 100644 --- a/testhal/STM32/STM32F7xx/SPI/main.c +++ b/testhal/STM32/STM32F7xx/SPI/main.c @@ -32,7 +32,7 @@ static const SPIConfig hs_spicfg = { NULL, GPIOB, GPIOB_ARD_D15, - SPI_CR1_BR_0, + SPI_CR1_CPOL | SPI_CR1_BR_0, SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0 }; @@ -167,15 +167,25 @@ int main(void) { /* * Starting the transmitter and receiver threads. */ - chThdCreateStatic(spi_thread_1_wa, sizeof(spi_thread_1_wa), - NORMALPRIO + 1, spi_thread_1, NULL); - chThdCreateStatic(spi_thread_2_wa, sizeof(spi_thread_2_wa), - NORMALPRIO + 1, spi_thread_2, NULL); +// chThdCreateStatic(spi_thread_1_wa, sizeof(spi_thread_1_wa), +// NORMALPRIO + 1, spi_thread_1, NULL); +// chThdCreateStatic(spi_thread_2_wa, sizeof(spi_thread_2_wa), +// NORMALPRIO + 1, spi_thread_2, NULL); /* * Normal main() thread activity, in this demo it does nothing. */ + uint8_t byte = 0x55; while (true) { chThdSleepMilliseconds(500); + spiStart(&SPID2, &hs_spicfg); + + spiSelect(&SPID2); + spiSend(&SPID2, 1, &byte); + spiUnselect(&SPID2); + + spiSelect(&SPID2); + spiSend(&SPID2, 1, &byte); + spiUnselect(&SPID2); } } -- cgit v1.2.3