/** * @brief Configures and activates the I2S peripheral. * * @param[in] i2sp pointer to the @p I2SDriver object * * @notapi */ void i2s_lld_start(I2SDriver *i2sp) { /* If in stopped state then enables the SPI and DMA clocks.*/ if (i2sp->state == I2S_STOP) { #if STM32_SPI_USE_SPI2 if (&SPID2 == spip) { bool_t b; b = dmaStreamAllocate(spip->dma, STM32_I2S_I2S2_IRQ_PRIORITY, (stm32_dmaisr_t)i2s_lld_serve_rx_interrupt, (void *)spip); chDbgAssert(!b, "spi_lld_start(), #1", "stream already allocated"); rccEnableSPI2(FALSE); } #endif #if STM32_SPI_USE_SPI3 if (&SPID3 == spip) { bool_t b; b = dmaStreamAllocate(spip->dma, STM32_I2S_I2S3_IRQ_PRIORITY, (stm32_dmaisr_t)i2s_lld_serve_rx_interrupt, (void *)spip); chDbgAssert(!b, "spi_lld_start(), #2", "stream already allocated"); rccEnableSPI3(FALSE); } #endif } /* Configuration.*/ }
/* Initialise the I2S interface to the CS43L22 */ static void _cs43l22_init_i2s( u32 frequency ) { rccEnableSPI3(FALSE); u32 plln = ( RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN ) >> 6; u32 pllr = ( RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR ) >> 28; u32 pllm = (u32)( RCC->PLLCFGR & RCC_PLLCFGR_PLLM ); u32 clock = (u32)( ( ( HSE_VALUE / pllm ) * plln ) / pllr ); chprintf( (void*)&SD2 , "PLL REG=0x%.x N=%d R=%d M=%d CLK = %d\r\n" , RCC->PLLI2SCFGR , plln , pllr , pllm , clock ); u16 frq = (u16)(( ( ( clock / 256 ) * 10 ) / frequency ) + 5 ) / 10; chprintf( (void*)&SD2 , "frq base = 0x%x\r\n" , frq ); if ( ( frq & 1 ) == 0 ) { frq = frq >> 1; } else {
/** * @brief Configures and activates the SPI peripheral. * * @param[in] spip pointer to the @p SPIDriver object * * @notapi */ void spi_lld_start(SPIDriver *spip) { uint32_t ds; /* If in stopped state then enables the SPI and DMA clocks.*/ if (spip->state == SPI_STOP) { #if STM32_SPI_USE_SPI1 if (&SPID1 == spip) { bool_t b; b = dmaStreamAllocate(spip->dmarx, STM32_SPI_SPI1_IRQ_PRIORITY, (stm32_dmaisr_t)spi_lld_serve_rx_interrupt, (void *)spip); chDbgAssert(!b, "spi_lld_start(), #1", "stream already allocated"); b = dmaStreamAllocate(spip->dmatx, STM32_SPI_SPI1_IRQ_PRIORITY, (stm32_dmaisr_t)spi_lld_serve_tx_interrupt, (void *)spip); chDbgAssert(!b, "spi_lld_start(), #2", "stream already allocated"); rccEnableSPI1(FALSE); } #endif #if STM32_SPI_USE_SPI2 if (&SPID2 == spip) { bool_t b; b = dmaStreamAllocate(spip->dmarx, STM32_SPI_SPI2_IRQ_PRIORITY, (stm32_dmaisr_t)spi_lld_serve_rx_interrupt, (void *)spip); chDbgAssert(!b, "spi_lld_start(), #3", "stream already allocated"); b = dmaStreamAllocate(spip->dmatx, STM32_SPI_SPI2_IRQ_PRIORITY, (stm32_dmaisr_t)spi_lld_serve_tx_interrupt, (void *)spip); chDbgAssert(!b, "spi_lld_start(), #4", "stream already allocated"); rccEnableSPI2(FALSE); } #endif #if STM32_SPI_USE_SPI3 if (&SPID3 == spip) { bool_t b; b = dmaStreamAllocate(spip->dmarx, STM32_SPI_SPI3_IRQ_PRIORITY, (stm32_dmaisr_t)spi_lld_serve_rx_interrupt, (void *)spip); chDbgAssert(!b, "spi_lld_start(), #5", "stream already allocated"); b = dmaStreamAllocate(spip->dmatx, STM32_SPI_SPI3_IRQ_PRIORITY, (stm32_dmaisr_t)spi_lld_serve_tx_interrupt, (void *)spip); chDbgAssert(!b, "spi_lld_start(), #6", "stream already allocated"); rccEnableSPI3(FALSE); } #endif /* DMA setup.*/ dmaStreamSetPeripheral(spip->dmarx, &spip->spi->DR); dmaStreamSetPeripheral(spip->dmatx, &spip->spi->DR); } /* Configuration-specific DMA setup.*/ ds = spip->config->cr2 & SPI_CR2_DS; if (!ds || (ds <= (SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0))) { /* Frame width is 8 bits or smaller.*/ spip->rxdmamode = (spip->rxdmamode & ~STM32_DMA_CR_SIZE_MASK) | STM32_DMA_CR_PSIZE_BYTE | STM32_DMA_CR_MSIZE_BYTE; spip->txdmamode = (spip->txdmamode & ~STM32_DMA_CR_SIZE_MASK) | STM32_DMA_CR_PSIZE_BYTE | STM32_DMA_CR_MSIZE_BYTE; } else { /* Frame width is larger than 8 bits.*/ spip->rxdmamode = (spip->rxdmamode & ~STM32_DMA_CR_SIZE_MASK) | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD; spip->txdmamode = (spip->txdmamode & ~STM32_DMA_CR_SIZE_MASK) | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD; } /* SPI setup and enable.*/ spip->spi->CR1 = 0; 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 | SPI_CR2_TXDMAEN; spip->spi->CR1 |= SPI_CR1_SPE; }
/** * @brief Configures and activates the SPI peripheral. * * @param[in] spip pointer to the @p SPIDriver object * * @notapi */ void spi_lld_start(SPIDriver *spip) { /* If in stopped state then enables the SPI and DMA clocks.*/ if (spip->state == SPI_STOP) { #if STM32_SPI_USE_SPI1 if (&SPID1 == spip) { bool_t b; b = dmaStreamAllocate(spip->dmarx, STM32_SPI_SPI1_IRQ_PRIORITY, (stm32_dmaisr_t)spi_lld_serve_rx_interrupt, (void *)spip); chDbgAssert(!b, "spi_lld_start(), #1", "stream already allocated"); b = dmaStreamAllocate(spip->dmatx, STM32_SPI_SPI1_IRQ_PRIORITY, (stm32_dmaisr_t)spi_lld_serve_tx_interrupt, (void *)spip); chDbgAssert(!b, "spi_lld_start(), #2", "stream already allocated"); rccEnableSPI1(FALSE); } #endif #if STM32_SPI_USE_SPI2 if (&SPID2 == spip) { bool_t b; b = dmaStreamAllocate(spip->dmarx, STM32_SPI_SPI2_IRQ_PRIORITY, (stm32_dmaisr_t)spi_lld_serve_rx_interrupt, (void *)spip); chDbgAssert(!b, "spi_lld_start(), #3", "stream already allocated"); b = dmaStreamAllocate(spip->dmatx, STM32_SPI_SPI2_IRQ_PRIORITY, (stm32_dmaisr_t)spi_lld_serve_tx_interrupt, (void *)spip); chDbgAssert(!b, "spi_lld_start(), #4", "stream already allocated"); rccEnableSPI2(FALSE); } #endif #if STM32_SPI_USE_SPI3 if (&SPID3 == spip) { bool_t b; b = dmaStreamAllocate(spip->dmarx, STM32_SPI_SPI3_IRQ_PRIORITY, (stm32_dmaisr_t)spi_lld_serve_rx_interrupt, (void *)spip); chDbgAssert(!b, "spi_lld_start(), #5", "stream already allocated"); b = dmaStreamAllocate(spip->dmatx, STM32_SPI_SPI3_IRQ_PRIORITY, (stm32_dmaisr_t)spi_lld_serve_tx_interrupt, (void *)spip); chDbgAssert(!b, "spi_lld_start(), #6", "stream already allocated"); rccEnableSPI3(FALSE); } #endif #if STM32_SPI_USE_SPI4 if (&SPID4 == spip) { bool_t b; b = dmaStreamAllocate(spip->dmarx, STM32_SPI_SPI4_IRQ_PRIORITY, (stm32_dmaisr_t)spi_lld_serve_rx_interrupt, (void *)spip); chDbgAssert(!b, "spi_lld_start(), #7", "stream already allocated"); b = dmaStreamAllocate(spip->dmatx, STM32_SPI_SPI4_IRQ_PRIORITY, (stm32_dmaisr_t)spi_lld_serve_tx_interrupt, (void *)spip); chDbgAssert(!b, "spi_lld_start(), #8", "stream already allocated"); rccEnableSPI4(FALSE); } #endif #if STM32_SPI_USE_SPI5 if (&SPID5 == spip) { bool_t b; b = dmaStreamAllocate(spip->dmarx, STM32_SPI_SPI5_IRQ_PRIORITY, (stm32_dmaisr_t)spi_lld_serve_rx_interrupt, (void *)spip); chDbgAssert(!b, "spi_lld_start(), #9", "stream already allocated"); b = dmaStreamAllocate(spip->dmatx, STM32_SPI_SPI5_IRQ_PRIORITY, (stm32_dmaisr_t)spi_lld_serve_tx_interrupt, (void *)spip); chDbgAssert(!b, "spi_lld_start(), #10", "stream already allocated"); rccEnableSPI5(FALSE); } #endif #if STM32_SPI_USE_SPI6 if (&SPID6 == spip) { bool_t b; b = dmaStreamAllocate(spip->dmarx, STM32_SPI_SPI6_IRQ_PRIORITY, (stm32_dmaisr_t)spi_lld_serve_rx_interrupt, (void *)spip); chDbgAssert(!b, "spi_lld_start(), #11", "stream already allocated"); b = dmaStreamAllocate(spip->dmatx, STM32_SPI_SPI6_IRQ_PRIORITY, (stm32_dmaisr_t)spi_lld_serve_tx_interrupt, (void *)spip); chDbgAssert(!b, "spi_lld_start(), #12", "stream already allocated"); rccEnableSPI6(FALSE); } #endif /* DMA setup.*/ dmaStreamSetPeripheral(spip->dmarx, &spip->spi->DR); dmaStreamSetPeripheral(spip->dmatx, &spip->spi->DR); } /* Configuration-specific DMA setup.*/ if ((spip->config->cr1 & SPI_CR1_DFF) == 0) { /* Frame width is 8 bits or smaller.*/ spip->rxdmamode = (spip->rxdmamode & ~STM32_DMA_CR_SIZE_MASK) | STM32_DMA_CR_PSIZE_BYTE | STM32_DMA_CR_MSIZE_BYTE; spip->txdmamode = (spip->txdmamode & ~STM32_DMA_CR_SIZE_MASK) | STM32_DMA_CR_PSIZE_BYTE | STM32_DMA_CR_MSIZE_BYTE; } else { /* Frame width is larger than 8 bits.*/ spip->rxdmamode = (spip->rxdmamode & ~STM32_DMA_CR_SIZE_MASK) | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD; spip->txdmamode = (spip->txdmamode & ~STM32_DMA_CR_SIZE_MASK) | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD; } /* SPI setup and enable.*/ #if !defined(STM32_SPI_SLAVE_MODE) spip->spi->CR1 = 0; spip->spi->CR1 = spip->config->cr1 | SPI_CR1_MSTR | SPI_CR1_SSM | SPI_CR1_SSI; spip->spi->CR2 = SPI_CR2_SSOE | SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN; spip->spi->CR1 |= SPI_CR1_SPE; #else spip->spi->CR1 = spip->config->cr1| SPI_CR1_LSBFIRST| SPI_CR1_DFF;// | SPI_CR1_RXONLY; //| SPI_CR1_DFF; spip->spi->CR2 = SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN; //| SPI_CR2_RXNEIE; spip->spi->CR1 |= SPI_CR1_SPE; #endif }
/** * @brief Configures and activates the I2S peripheral. * * @param[in] i2sp pointer to the @p I2SDriver object * * @notapi */ void i2s_lld_start(I2SDriver *i2sp) { /* If in stopped state then enables the SPI and DMA clocks.*/ if (i2sp->state == I2S_STOP) { #if STM32_I2S_USE_SPI2 if (&I2SD2 == i2sp) { bool b; /* Enabling I2S unit clock.*/ rccEnableSPI2(FALSE); #if STM32_I2S_RX_ENABLED(STM32_I2S_SPI2_MODE) b = dmaStreamAllocate(i2sp->dmarx, STM32_I2S_SPI2_IRQ_PRIORITY, (stm32_dmaisr_t)i2s_lld_serve_rx_interrupt, (void *)i2sp); osalDbgAssert(!b, "stream already allocated"); /* CRs settings are done here because those never changes until the driver is stopped.*/ i2sp->spi->CR1 = 0; i2sp->spi->CR2 = SPI_CR2_RXDMAEN; #endif #if STM32_I2S_TX_ENABLED(STM32_I2S_SPI2_MODE) b = dmaStreamAllocate(i2sp->dmatx, STM32_I2S_SPI2_IRQ_PRIORITY, (stm32_dmaisr_t)i2s_lld_serve_tx_interrupt, (void *)i2sp); osalDbgAssert(!b, "stream already allocated"); /* CRs settings are done here because those never changes until the driver is stopped.*/ i2sp->spi->CR1 = 0; i2sp->spi->CR2 = SPI_CR2_TXDMAEN; #endif } #endif #if STM32_I2S_USE_SPI3 if (&I2SD3 == i2sp) { bool b; /* Enabling I2S unit clock.*/ rccEnableSPI3(FALSE); #if STM32_I2S_RX_ENABLED(STM32_I2S_SPI3_MODE) b = dmaStreamAllocate(i2sp->dmarx, STM32_I2S_SPI3_IRQ_PRIORITY, (stm32_dmaisr_t)i2s_lld_serve_rx_interrupt, (void *)i2sp); osalDbgAssert(!b, "stream already allocated"); i2sp->spi->CR1 = 0; i2sp->spi->CR2 = SPI_CR2_RXDMAEN; #endif #if STM32_I2S_TX_ENABLED(STM32_I2S_SPI3_MODE) b = dmaStreamAllocate(i2sp->dmatx, STM32_I2S_SPI3_IRQ_PRIORITY, (stm32_dmaisr_t)i2s_lld_serve_tx_interrupt, (void *)i2sp); osalDbgAssert(!b, "stream already allocated"); i2sp->spi->CR1 = 0; i2sp->spi->CR2 = SPI_CR2_TXDMAEN; #endif } #endif if (NULL != i2sp->dmarx) { dmaStreamSetMode(i2sp->dmarx, i2sp->rxdmamode); dmaStreamSetPeripheral(i2sp->dmarx, &i2sp->spi->DR); } if (NULL != i2sp->dmatx) { dmaStreamSetMode(i2sp->dmatx, i2sp->txdmamode); dmaStreamSetPeripheral(i2sp->dmatx, &i2sp->spi->DR); } } /* I2S (re)configuration.*/ i2sp->spi->I2SPR = i2sp->config->i2spr; i2sp->spi->I2SCFGR = i2sp->config->i2scfgr | i2sp->cfg | SPI_I2SCFGR_I2SMOD; }