From b5650c045732a833ab9bb9ae44a6be1f604bb9c1 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 3 Mar 2014 14:57:32 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6749 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/i2s.h | 2 +- os/hal/ports/STM32/LLD/SPIv1/i2s_lld.c | 18 ++++++++++++----- testhal/STM32F4xx/I2S/main.c | 37 +++++++++++++++++++++++++++++++++- testhal/STM32F4xx/I2S/mcuconf.h | 2 +- 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/os/hal/include/i2s.h b/os/hal/include/i2s.h index c7143daec..711ec3b5c 100644 --- a/os/hal/include/i2s.h +++ b/os/hal/include/i2s.h @@ -163,7 +163,7 @@ extern "C" { void i2sStart(I2SDriver *i2sp, const I2SConfig *config); void i2sStop(I2SDriver *i2sp); void i2sStartExchange(I2SDriver *i2sp); - void i2sStopTransfer(I2SDriver *i2sp); + void i2sStopExchange(I2SDriver *i2sp); #ifdef __cplusplus } #endif diff --git a/os/hal/ports/STM32/LLD/SPIv1/i2s_lld.c b/os/hal/ports/STM32/LLD/SPIv1/i2s_lld.c index e95ac27ba..26f6bb5fc 100644 --- a/os/hal/ports/STM32/LLD/SPIv1/i2s_lld.c +++ b/os/hal/ports/STM32/LLD/SPIv1/i2s_lld.c @@ -419,14 +419,22 @@ void i2s_lld_start_exchange(I2SDriver *i2sp) { */ void i2s_lld_stop_exchange(I2SDriver *i2sp) { - /* Stop DMAs.*/ - if (NULL != i2sp->dmatx) + /* Stop TX DMA, if enabled.*/ + if (NULL != i2sp->dmatx) { dmaStreamDisable(i2sp->dmatx); - if (NULL != i2sp->dmarx) - dmaStreamDisable(i2sp->dmarx); - /* Stop transfer.*/ + /* From the RM: To switch off the I2S, by clearing I2SE, it is mandatory + to wait for TXE = 1 and BSY = 0.*/ + while ((i2sp->spi->SR & (SPI_SR_TXE | SPI_SR_BSY)) != SPI_SR_TXE) + ; + } + + /* Stop SPI/I2S peripheral.*/ i2sp->spi->I2SCFGR &= ~SPI_I2SCFGR_I2SE; + + /* Stop RX DMA, if enabled.*/ + if (NULL != i2sp->dmarx) + dmaStreamDisable(i2sp->dmarx); } #endif /* HAL_USE_I2S */ diff --git a/testhal/STM32F4xx/I2S/main.c b/testhal/STM32F4xx/I2S/main.c index 803ab5a64..306141da8 100644 --- a/testhal/STM32F4xx/I2S/main.c +++ b/testhal/STM32F4xx/I2S/main.c @@ -17,6 +17,28 @@ #include "ch.h" #include "hal.h" +#define I2S_BUF_SIZE 256 + +static uint16_t i2s_rx_buf[I2S_BUF_SIZE]; + +static void i2scallback(I2SDriver *i2sp, size_t offset, size_t n); + +static const I2SConfig i2scfg = { + NULL, + i2s_rx_buf, + I2S_BUF_SIZE, + i2scallback, + 0, + 16 +}; + +static void i2scallback(I2SDriver *i2sp, size_t offset, size_t n) { + + (void)i2sp; + (void)offset; + (void)n; +} + /* * Application entry point. */ @@ -33,9 +55,22 @@ int main(void) { chSysInit(); /* - * Normal main() thread activity, in this demo it does nothing. + * Starting and configuring the I2S driver 2. + */ + i2sStart(&I2SD2, &i2scfg); + + /* + * Starting continuous I2S transfer. + */ + i2sStartExchange(&I2SD2); + + /* + * Normal main() thread activity, if the button is pressed then the I2s + * transfer is stopped. */ while (TRUE) { + if (palReadPad(GPIOA, GPIOA_BUTTON)) + i2sStopExchange(&I2SD2); chThdSleepMilliseconds(500); } return 0; diff --git a/testhal/STM32F4xx/I2S/mcuconf.h b/testhal/STM32F4xx/I2S/mcuconf.h index 2a50dd166..8b49e5ebd 100644 --- a/testhal/STM32F4xx/I2S/mcuconf.h +++ b/testhal/STM32F4xx/I2S/mcuconf.h @@ -54,7 +54,7 @@ #define STM32_MCO1PRE STM32_MCO1PRE_DIV1 #define STM32_MCO2SEL STM32_MCO2SEL_SYSCLK #define STM32_MCO2PRE STM32_MCO2PRE_DIV5 -#define STM32_I2SSRC STM32_I2SSRC_CKIN +#define STM32_I2SSRC STM32_I2SSRC_PLLI2S #define STM32_PLLI2SN_VALUE 192 #define STM32_PLLI2SR_VALUE 5 #define STM32_PVD_ENABLE FALSE -- cgit v1.2.3