SPI working on F7 but cache handling unfinished.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8241 35acf78f-673a-0410-8e92-d51de3d6d3f4
master
Giovanni Di Sirio 2015-08-26 10:03:11 +00:00
parent 9e5337241d
commit ccef2d248b
4 changed files with 25 additions and 30 deletions

View File

@ -49,16 +49,6 @@
*/ */
#define STM32_DMA2_STREAMS_MASK 0x0000FF00U #define STM32_DMA2_STREAMS_MASK 0x0000FF00U
/**
* @brief Post-reset value of the stream CR register.
*/
#define STM32_DMA_CR_RESET_VALUE 0x00000000U
/**
* @brief Post-reset value of the stream FCR register.
*/
#define STM32_DMA_FCR_RESET_VALUE 0x00000021U
/*===========================================================================*/ /*===========================================================================*/
/* Driver exported variables. */ /* Driver exported variables. */
/*===========================================================================*/ /*===========================================================================*/

View File

@ -126,6 +126,7 @@
* @name CR register constants common to all DMA types * @name CR register constants common to all DMA types
* @{ * @{
*/ */
#define STM32_DMA_CR_RESET_VALUE 0x00000000U
#define STM32_DMA_CR_EN DMA_SxCR_EN #define STM32_DMA_CR_EN DMA_SxCR_EN
#define STM32_DMA_CR_TEIE DMA_SxCR_TEIE #define STM32_DMA_CR_TEIE DMA_SxCR_TEIE
#define STM32_DMA_CR_HTIE DMA_SxCR_HTIE #define STM32_DMA_CR_HTIE DMA_SxCR_HTIE
@ -178,6 +179,7 @@
* @name FCR register constants only found in STM32F2xx/STM32F4xx * @name FCR register constants only found in STM32F2xx/STM32F4xx
* @{ * @{
*/ */
#define STM32_DMA_FCR_RESET_VALUE 0x00000021U
#define STM32_DMA_FCR_FEIE DMA_SxFCR_FEIE #define STM32_DMA_FCR_FEIE DMA_SxFCR_FEIE
#define STM32_DMA_FCR_FS_MASK DMA_SxFCR_FS #define STM32_DMA_FCR_FS_MASK DMA_SxFCR_FS
#define STM32_DMA_FCR_DMDIS DMA_SxFCR_DMDIS #define STM32_DMA_FCR_DMDIS DMA_SxFCR_DMDIS
@ -398,11 +400,10 @@ typedef void (*stm32_dmaisr_t)(void *p, uint32_t flags);
* @special * @special
*/ */
#define dmaStreamDisable(dmastp) { \ #define dmaStreamDisable(dmastp) { \
(dmastp)->stream->CR &= ~(STM32_DMA_CR_TCIE | STM32_DMA_CR_HTIE | \ (dmastp)->stream->CR &= ~STM32_DMA_CR_EN; \
STM32_DMA_CR_TEIE | STM32_DMA_CR_DMEIE | \
STM32_DMA_CR_EN); \
while (((dmastp)->stream->CR & STM32_DMA_CR_EN) != 0U) \ while (((dmastp)->stream->CR & STM32_DMA_CR_EN) != 0U) \
; \ ; \
(dmastp)->stream->CR = STM32_DMA_CR_RESET_VALUE; \
dmaStreamClearInterrupt(dmastp); \ dmaStreamClearInterrupt(dmastp); \
} }
@ -445,7 +446,8 @@ typedef void (*stm32_dmaisr_t)(void *p, uint32_t flags);
dmaStreamSetTransactionSize(dmastp, n); \ dmaStreamSetTransactionSize(dmastp, n); \
dmaStreamSetMode(dmastp, (mode) | \ dmaStreamSetMode(dmastp, (mode) | \
STM32_DMA_CR_MINC | STM32_DMA_CR_PINC | \ STM32_DMA_CR_MINC | STM32_DMA_CR_PINC | \
STM32_DMA_CR_DIR_M2M | STM32_DMA_CR_EN); \ STM32_DMA_CR_DIR_M2M); \
dmaStreamEnable(dmastp); \
} }
/** /**

View File

@ -259,7 +259,7 @@ void spi_lld_init(void) {
#endif #endif
#if STM32_SPI_USE_SPI5 #if STM32_SPI_USE_SPI5
spiObjectInit(&SPID3); spiObjectInit(&SPID5);
SPID5.spi = SPI5; SPID5.spi = SPI5;
SPID5.dmarx = STM32_DMA_STREAM(STM32_SPI_SPI5_RX_DMA_STREAM); SPID5.dmarx = STM32_DMA_STREAM(STM32_SPI_SPI5_RX_DMA_STREAM);
SPID5.dmatx = STM32_DMA_STREAM(STM32_SPI_SPI5_TX_DMA_STREAM); SPID5.dmatx = STM32_DMA_STREAM(STM32_SPI_SPI5_TX_DMA_STREAM);
@ -427,10 +427,10 @@ void spi_lld_start(SPIDriver *spip) {
STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD; STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD;
spip->fsize = sizeof (uint16_t); spip->fsize = sizeof (uint16_t);
} }
/* SPI setup and enable.*/ /* SPI setup and enable.*/
spip->spi->CR1 = 0; spip->spi->CR1 = 0;
spip->spi->CR1 = spip->config->cr1 | SPI_CR1_MSTR | SPI_CR1_SSM | spip->spi->CR1 = spip->config->cr1 | SPI_CR1_MSTR;
SPI_CR1_SSI;
spip->spi->CR2 = spip->config->cr2 | SPI_CR2_FRXTH | SPI_CR2_SSOE | spip->spi->CR2 = spip->config->cr2 | SPI_CR2_FRXTH | SPI_CR2_SSOE |
SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN; SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN;
spip->spi->CR1 |= SPI_CR1_SPE; spip->spi->CR1 |= SPI_CR1_SPE;
@ -554,7 +554,7 @@ void spi_lld_exchange(SPIDriver *spip, size_t n,
dmaStreamSetMemory0(spip->dmarx, rxbuf); dmaStreamSetMemory0(spip->dmarx, rxbuf);
dmaStreamSetTransactionSize(spip->dmarx, n); dmaStreamSetTransactionSize(spip->dmarx, n);
dmaStreamSetMode(spip->dmarx, spip->rxdmamode| STM32_DMA_CR_MINC); dmaStreamSetMode(spip->dmarx, spip->rxdmamode | STM32_DMA_CR_MINC);
dmaStreamSetMemory0(spip->dmatx, txbuf); dmaStreamSetMemory0(spip->dmatx, txbuf);
dmaStreamSetTransactionSize(spip->dmatx, n); dmaStreamSetTransactionSize(spip->dmatx, n);

View File

@ -26,9 +26,9 @@
*/ */
static const SPIConfig hs_spicfg = { static const SPIConfig hs_spicfg = {
NULL, NULL,
GPIOI, GPIOB,
GPIOI_ARD_D13, GPIOB_ARD_D15,
0, SPI_CR1_BR_0,
SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0 SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0
}; };
@ -37,8 +37,8 @@ static const SPIConfig hs_spicfg = {
*/ */
static const SPIConfig ls_spicfg = { static const SPIConfig ls_spicfg = {
NULL, NULL,
GPIOI, GPIOB,
GPIOI_ARD_D13, GPIOB_ARD_D14,
SPI_CR1_BR_2 | SPI_CR1_BR_1, SPI_CR1_BR_2 | SPI_CR1_BR_1,
SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0 SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0
}; };
@ -114,8 +114,8 @@ int main(void) {
*/ */
palSetPadMode(GPIOI, palSetPadMode(GPIOI,
GPIOI_ARD_D13, GPIOI_ARD_D13,
PAL_MODE_OUTPUT_PUSHPULL | PAL_MODE_ALTERNATE(5) |
PAL_STM32_OSPEED_HIGHEST); /* LED over SPI SCK. */ PAL_STM32_OSPEED_HIGHEST); /* SPI SCK. */
palSetPadMode(GPIOB, palSetPadMode(GPIOB,
GPIOB_ARD_D12, GPIOB_ARD_D12,
PAL_MODE_ALTERNATE(5) | PAL_MODE_ALTERNATE(5) |
@ -124,11 +124,14 @@ int main(void) {
GPIOB_ARD_D11, GPIOB_ARD_D11,
PAL_MODE_ALTERNATE(5) | PAL_MODE_ALTERNATE(5) |
PAL_STM32_OSPEED_HIGHEST); /* MOSI. */ PAL_STM32_OSPEED_HIGHEST); /* MOSI. */
palSetPadMode(GPIOI, palSetPad(GPIOB, GPIOB_ARD_D15);
GPIOI_ARD_D10, palSetPadMode(GPIOB,
PAL_MODE_OUTPUT_PUSHPULL | GPIOB_ARD_D15,
PAL_STM32_OSPEED_HIGHEST); /* CS. */ PAL_MODE_OUTPUT_PUSHPULL); /* CS0. */
palSetPad(GPIOI, GPIOI_ARD_D10); palSetPad(GPIOB, GPIOB_ARD_D14);
palSetPadMode(GPIOB,
GPIOB_ARD_D14,
PAL_MODE_OUTPUT_PUSHPULL); /* CS1. */
/* /*
* Prepare transmit pattern. * Prepare transmit pattern.