2016-01-23 04:20:00 UTC
I'm working on a STM32 F3 device and accessing some slave devices that require / expect CRC enabled. Not all slave devices do CRC. Multiple devices can obviously exist on a SPI bus (with a sufficient number of chip selects of course) and not all of those devices may require / support CRC. So CRC needs to be configurable for each transfer / exchange.
Looking at the stm32/stm32_spi.c I see that while the polynomial is configured in spi_portinitialize() the driver does not appear to support CRC in general. I don't see the point of configuring the polynomial if CRC isn't supported, particularly because the value specified (7) is the power up default. But that's another issue.
Normally I'd implement this as a bitmask / flag I pass in a message structure but per the SPI interface (include/nuttx/spi/spi.h) requirese individual parameters (txbuffer, rxbuffer, nbytes) rather than a structure in spi_exchange(). So if I add a flag OR a new structure to replace the individual parameters, I break the system's SPI interface.
I am still researching some statements in the reference manual that seem to indicate hardware SPI CRC calculations are only supported for transfers of 1 or 2 bytes, and if that's true, I'll have to do it in higher level software as I'm sending larger buffers. BUT...assuming the CRC function of the peripheral isn't so stupidly limited and actually calculates it at completion of the DMA or something convenient like that, then I would like to add the capability to the driver and submit the changes to the project.
Before I can do that, however, I need to know how you would prefer to address the interface issue. I would prefer to model SPI after I2C and pass a "message" type structure which could contain:
and I would naturally set flags to:
to enable CRC on that particular exchange.