247
247
// Only HC block size is supported. Making this a static constant reduces code size.
248
248
const uint32_t SDBlockDevice::_block_size = BLOCK_SIZE_HC;
249
249
250
+ #if MBED_CONF_SD_CRC_ENABLED
250
251
SDBlockDevice::SDBlockDevice (PinName mosi, PinName miso, PinName sclk, PinName cs, uint64_t hz, bool crc_on)
251
252
: _sectors(0 ), _spi(mosi, miso, sclk), _cs(cs), _is_initialized(0 ),
252
- _crc_on(crc_on), _init_ref_count(0 ), _crc16(0 , 0 , false , false )
253
+ _init_ref_count(0 ), _crc_on(crc_on), _crc16(0 , 0 , false , false )
254
+ #else
255
+ SDBlockDevice::SDBlockDevice (PinName mosi, PinName miso, PinName sclk, PinName cs, uint64_t hz, bool crc_on)
256
+ : _sectors(0 ), _spi(mosi, miso, sclk), _cs(cs), _is_initialized(0 ),
257
+ _init_ref_count(0 )
258
+ #endif
253
259
{
254
260
_cs = 1 ;
255
261
_card_type = SDCARD_NONE;
@@ -293,10 +299,12 @@ int SDBlockDevice::_initialise_card()
293
299
return status;
294
300
}
295
301
302
+ #if MBED_CONF_SD_CRC_ENABLED
296
303
if (_crc_on) {
297
304
// Enable CRC
298
305
status = _cmd (CMD59_CRC_ON_OFF, _crc_on);
299
306
}
307
+ #endif
300
308
301
309
// Read OCR - CMD58 Response contains OCR register
302
310
if (BD_ERROR_OK != (status = _cmd (CMD58_READ_OCR, 0x0 , 0x0 , &response))) {
@@ -350,10 +358,15 @@ int SDBlockDevice::_initialise_card()
350
358
debug_if (SD_DBG, " Card Initialized: Version 1.x Card\n " );
351
359
}
352
360
361
+ #if MBED_CONF_SD_CRC_ENABLED
353
362
if (!_crc_on) {
354
363
// Disable CRC
355
364
status = _cmd (CMD59_CRC_ON_OFF, _crc_on);
356
365
}
366
+ #else
367
+ status = _cmd (CMD59_CRC_ON_OFF, 0 );
368
+ #endif
369
+
357
370
return status;
358
371
}
359
372
@@ -649,7 +662,6 @@ uint8_t SDBlockDevice::_cmd_spi(SDBlockDevice::cmdSupported cmd, uint32_t arg)
649
662
{
650
663
uint8_t response;
651
664
char cmdPacket[PACKET_SIZE];
652
- uint32_t crc;
653
665
654
666
// Prepare the command packet
655
667
cmdPacket[0 ] = SPI_CMD (cmd);
@@ -658,10 +670,14 @@ uint8_t SDBlockDevice::_cmd_spi(SDBlockDevice::cmdSupported cmd, uint32_t arg)
658
670
cmdPacket[3 ] = (arg >> 8 );
659
671
cmdPacket[4 ] = (arg >> 0 );
660
672
673
+ #if MBED_CONF_SD_CRC_ENABLED
674
+ uint32_t crc;
661
675
if (_crc_on) {
662
676
_crc7.compute ((void *)cmdPacket, 5 , &crc);
663
677
cmdPacket[5 ] = (char )(crc | 0x01 );
664
- } else {
678
+ } else
679
+ #endif
680
+ {
665
681
// CMD0 is executed in SD mode, hence should have correct CRC
666
682
// CMD8 CRC verification is always enabled
667
683
switch (cmd) {
@@ -874,6 +890,7 @@ int SDBlockDevice::_read_bytes(uint8_t *buffer, uint32_t length)
874
890
crc = (_spi.write (SPI_FILL_CHAR) << 8 );
875
891
crc |= _spi.write (SPI_FILL_CHAR);
876
892
893
+ #if MBED_CONF_SD_CRC_ENABLED
877
894
if (_crc_on) {
878
895
uint32_t crc_result;
879
896
// Compute and verify checksum
@@ -885,6 +902,7 @@ int SDBlockDevice::_read_bytes(uint8_t *buffer, uint32_t length)
885
902
return SD_BLOCK_DEVICE_ERROR_CRC;
886
903
}
887
904
}
905
+ #endif
888
906
889
907
_deselect ();
890
908
return 0 ;
@@ -907,6 +925,7 @@ int SDBlockDevice::_read(uint8_t *buffer, uint32_t length)
907
925
crc = (_spi.write (SPI_FILL_CHAR) << 8 );
908
926
crc |= _spi.write (SPI_FILL_CHAR);
909
927
928
+ #if MBED_CONF_SD_CRC_ENABLED
910
929
if (_crc_on) {
911
930
uint32_t crc_result;
912
931
// Compute and verify checksum
@@ -917,6 +936,7 @@ int SDBlockDevice::_read(uint8_t *buffer, uint32_t length)
917
936
return SD_BLOCK_DEVICE_ERROR_CRC;
918
937
}
919
938
}
939
+ #endif
920
940
921
941
return 0 ;
922
942
}
@@ -933,10 +953,12 @@ uint8_t SDBlockDevice::_write(const uint8_t *buffer, uint8_t token, uint32_t len
933
953
// write the data
934
954
_spi.write ((char *)buffer, length, NULL , 0 );
935
955
956
+ #if MBED_CONF_SD_CRC_ENABLED
936
957
if (_crc_on) {
937
958
// Compute CRC
938
959
_crc16.compute ((void *)buffer, length, &crc);
939
960
}
961
+ #endif
940
962
941
963
// write the checksum CRC16
942
964
_spi.write (crc >> 8 );
0 commit comments