To communicate my discovery board with an external device, it's required to use SPI in DMA mode with CRC enabled. Firstly we wrote a program using STM library directly, it works very well. Then we rewrote it using ChibiOS 2.6.1 and now got a data corruption. It appears we can send data to external device fine. But at first attempt to read 6 bytes from device we got all zero, although logical analyzer clearly shows the last byte is non-zero.
I guess this is related to CRC. By default ChibiOS doesn't support CRC, I enabled CRC in my code, I'm afraid I'm not doing it correctly. Following is the code, appreciated any suggestions.
Code: Select all
static const SPIConfig spi2_conf = {
NULL,
GPIOE, /* chip select */
7, /* chip select */
SPI_CR1_BR_0 | /* quarter of APB2 frequency */
SPI_CR1_CRCEN /* enable CRC */
};
void exchange(const void *txbuf, void *rxbuf, int size)
{
uint16_t crc;
spiAcquireBus(&SPID2);
spiStart(&SPID2, &spi2_conf);
spiSelect(&SPID2);
spiExchange(&SPID2, size, txbuf, rxbuf);
/* Read DR (CRC) to clear RXNE flag */
crc = SPID2.spi->DR;
(void) crc; /* to quiet compiler warning */
spiUnselect(&SPID2);
spiReleaseBus(&SPID2);
}