AnsweredAssumed Answered

SPI SD Card with CRC

Question asked by jo.farmer on Jun 8, 2013
Latest reply on Jun 9, 2013 by jo.farmer

I am looking to understand exactly what CRC support the STM32F103 provides when interfacing with an SD card using an SPI channel and no DMA.

I am using an Olimex STM32-P103 development platform and have successfully transmitted CMD8 to a SanDisk 2GB (class 2) SD card (at 280KHz) but only when I pre-calculate the 6-byte command as follows. 40 00 00 00 00 95. The reply data that is returned in this case is valid.

I would like to use the built in CRC capability of the interface to calculate the final CRC byte but this is where things go wrong. I now transmit 40 00 00 00 00 and on the final 00 byte set the CRCNEXT bit in the CR1 control register. I do indeed get a sixth byte transmission but it is not the required 95 (this I verified by viewing the MOSI signal using an oscilloscope).

My questions are as follows.

(*) In order for the calculated CRC value to be useful only the low 7-bits should be used which need to be shifted left 1-bit position and a LSB of 1 needs to be set (to satisfy the SD card protocol for transmitted commands). Does this happen automatically or is the byte transmitted the final CRC calculation which will be invalid in most cases?

(*) If the latter does not happen then am I correct in thinking that this must be managed by user code? If so how would this be achieved if DMA transfers are used?

(*) Is register SPI_CRCPR actually programmed with a generator polynomial or is it simply set to 7 to select CRC7 (with left-shift and LSB set to 1 prior to transmission)?