@@ -264,8 +264,8 @@ SDBlockDevice::SDBlockDevice(PinName mosi, PinName miso, PinName sclk, PinName c
264
264
_card_type = SDCARD_NONE;
265
265
266
266
// Set default to 100kHz for initialisation and 1MHz for data transfer
267
- MBED_STATIC_ASSERT (((MBED_CONF_SD_INIT_FREQUENCY >= 100000 ) && (MBED_CONF_SD_INIT_FREQUENCY <= 400000 )),
268
- " Initialization frequency should be between 100KHz to 400KHz" );
267
+ static_assert (((MBED_CONF_SD_INIT_FREQUENCY >= 100000 ) && (MBED_CONF_SD_INIT_FREQUENCY <= 400000 )),
268
+ " Initialization frequency should be between 100KHz to 400KHz" );
269
269
_init_sck = MBED_CONF_SD_INIT_FREQUENCY;
270
270
_transfer_sck = hz;
271
271
@@ -285,8 +285,8 @@ SDBlockDevice::SDBlockDevice(const spi_pinmap_t &spi_pinmap, PinName cs, uint64_
285
285
_card_type = SDCARD_NONE;
286
286
287
287
// Set default to 100kHz for initialisation and 1MHz for data transfer
288
- MBED_STATIC_ASSERT (((MBED_CONF_SD_INIT_FREQUENCY >= 100000 ) && (MBED_CONF_SD_INIT_FREQUENCY <= 400000 )),
289
- " Initialization frequency should be between 100KHz to 400KHz" );
288
+ static_assert (((MBED_CONF_SD_INIT_FREQUENCY >= 100000 ) && (MBED_CONF_SD_INIT_FREQUENCY <= 400000 )),
289
+ " Initialization frequency should be between 100KHz to 400KHz" );
290
290
_init_sck = MBED_CONF_SD_INIT_FREQUENCY;
291
291
_transfer_sck = hz;
292
292
@@ -711,15 +711,15 @@ uint8_t SDBlockDevice::_cmd_spi(SDBlockDevice::cmdSupported cmd, uint32_t arg)
711
711
// CMD0 is executed in SD mode, hence should have correct CRC
712
712
// CMD8 CRC verification is always enabled
713
713
switch (cmd) {
714
- case CMD0_GO_IDLE_STATE:
715
- cmdPacket[5 ] = 0x95 ;
716
- break ;
717
- case CMD8_SEND_IF_COND:
718
- cmdPacket[5 ] = 0x87 ;
719
- break ;
720
- default :
721
- cmdPacket[5 ] = 0xFF ; // Make sure bit 0-End bit is high
722
- break ;
714
+ case CMD0_GO_IDLE_STATE:
715
+ cmdPacket[5 ] = 0x95 ;
716
+ break ;
717
+ case CMD8_SEND_IF_COND:
718
+ cmdPacket[5 ] = 0x87 ;
719
+ break ;
720
+ default :
721
+ cmdPacket[5 ] = 0xFF ; // Make sure bit 0-End bit is high
722
+ break ;
723
723
}
724
724
}
725
725
@@ -817,30 +817,30 @@ int SDBlockDevice::_cmd(SDBlockDevice::cmdSupported cmd, uint32_t arg, bool isAc
817
817
818
818
// Get rest of the response part for other commands
819
819
switch (cmd) {
820
- case CMD8_SEND_IF_COND: // Response R7
821
- debug_if (_dbg, " V2-Version Card\n " );
822
- _card_type = SDCARD_V2; // fallthrough
823
- // Note: No break here, need to read rest of the response
824
- case CMD58_READ_OCR: // Response R3
825
- response = (_spi.write (SPI_FILL_CHAR) << 24 );
826
- response |= (_spi.write (SPI_FILL_CHAR) << 16 );
827
- response |= (_spi.write (SPI_FILL_CHAR) << 8 );
828
- response |= _spi.write (SPI_FILL_CHAR);
829
- debug_if (_dbg, " R3/R7: 0x%" PRIx32 " \n " , response);
830
- break ;
820
+ case CMD8_SEND_IF_COND: // Response R7
821
+ debug_if (_dbg, " V2-Version Card\n " );
822
+ _card_type = SDCARD_V2; // fallthrough
823
+ // Note: No break here, need to read rest of the response
824
+ case CMD58_READ_OCR: // Response R3
825
+ response = (_spi.write (SPI_FILL_CHAR) << 24 );
826
+ response |= (_spi.write (SPI_FILL_CHAR) << 16 );
827
+ response |= (_spi.write (SPI_FILL_CHAR) << 8 );
828
+ response |= _spi.write (SPI_FILL_CHAR);
829
+ debug_if (_dbg, " R3/R7: 0x%" PRIx32 " \n " , response);
830
+ break ;
831
831
832
- case CMD12_STOP_TRANSMISSION: // Response R1b
833
- case CMD38_ERASE:
834
- _wait_ready (SD_COMMAND_TIMEOUT);
835
- break ;
832
+ case CMD12_STOP_TRANSMISSION: // Response R1b
833
+ case CMD38_ERASE:
834
+ _wait_ready (SD_COMMAND_TIMEOUT);
835
+ break ;
836
836
837
- case ACMD13_SD_STATUS: // Response R2
838
- response = _spi.write (SPI_FILL_CHAR);
839
- debug_if (_dbg, " R2: 0x%" PRIx32 " \n " , response);
840
- break ;
837
+ case ACMD13_SD_STATUS: // Response R2
838
+ response = _spi.write (SPI_FILL_CHAR);
839
+ debug_if (_dbg, " R2: 0x%" PRIx32 " \n " , response);
840
+ break ;
841
841
842
- default : // Response R1
843
- break ;
842
+ default : // Response R1
843
+ break ;
844
844
}
845
845
846
846
// Pass the updated response to the command
@@ -1044,41 +1044,41 @@ bd_size_t SDBlockDevice::_sd_sectors()
1044
1044
// csd_structure : csd[127:126]
1045
1045
int csd_structure = ext_bits (csd, 127 , 126 );
1046
1046
switch (csd_structure) {
1047
- case 0 :
1048
- c_size = ext_bits (csd, 73 , 62 ); // c_size : csd[73:62]
1049
- c_size_mult = ext_bits (csd, 49 , 47 ); // c_size_mult : csd[49:47]
1050
- read_bl_len = ext_bits (csd, 83 , 80 ); // read_bl_len : csd[83:80] - the *maximum* read block length
1051
- block_len = 1 << read_bl_len; // BLOCK_LEN = 2^READ_BL_LEN
1052
- mult = 1 << (c_size_mult + 2 ); // MULT = 2^C_SIZE_MULT+2 (C_SIZE_MULT < 8)
1053
- blocknr = (c_size + 1 ) * mult; // BLOCKNR = (C_SIZE+1) * MULT
1054
- capacity = (bd_size_t ) blocknr * block_len; // memory capacity = BLOCKNR * BLOCK_LEN
1055
- blocks = capacity / _block_size;
1056
- debug_if (SD_DBG, " Standard Capacity: c_size: %" PRIu32 " \n " , c_size);
1057
- debug_if (SD_DBG, " Sectors: 0x%" PRIx64 " : %" PRIu64 " \n " , blocks, blocks);
1058
- debug_if (SD_DBG, " Capacity: 0x%" PRIx64 " : %" PRIu64 " MB\n " , capacity, (capacity / (1024U * 1024U )));
1059
-
1060
- // ERASE_BLK_EN = 1: Erase in multiple of 512 bytes supported
1061
- if (ext_bits (csd, 46 , 46 )) {
1062
- _erase_size = BLOCK_SIZE_HC;
1063
- } else {
1064
- // ERASE_BLK_EN = 1: Erase in multiple of SECTOR_SIZE supported
1065
- _erase_size = BLOCK_SIZE_HC * (ext_bits (csd, 45 , 39 ) + 1 );
1066
- }
1067
- break ;
1068
-
1069
- case 1 :
1070
- hc_c_size = ext_bits (csd, 69 , 48 ); // device size : C_SIZE : [69:48]
1071
- blocks = (hc_c_size + 1 ) << 10 ; // block count = C_SIZE+1) * 1K byte (512B is block size)
1072
- debug_if (SD_DBG, " SDHC/SDXC Card: hc_c_size: %" PRIu32 " \n " , hc_c_size);
1073
- debug_if (SD_DBG, " Sectors: 0x%" PRIx64 " x : %" PRIu64 " \n " , blocks, blocks);
1074
- debug_if (SD_DBG, " Capacity: %" PRIu64 " MB\n " , (blocks / (2048U )));
1075
- // ERASE_BLK_EN is fixed to 1, which means host can erase one or multiple of 512 bytes.
1047
+ case 0 :
1048
+ c_size = ext_bits (csd, 73 , 62 ); // c_size : csd[73:62]
1049
+ c_size_mult = ext_bits (csd, 49 , 47 ); // c_size_mult : csd[49:47]
1050
+ read_bl_len = ext_bits (csd, 83 , 80 ); // read_bl_len : csd[83:80] - the *maximum* read block length
1051
+ block_len = 1 << read_bl_len; // BLOCK_LEN = 2^READ_BL_LEN
1052
+ mult = 1 << (c_size_mult + 2 ); // MULT = 2^C_SIZE_MULT+2 (C_SIZE_MULT < 8)
1053
+ blocknr = (c_size + 1 ) * mult; // BLOCKNR = (C_SIZE+1) * MULT
1054
+ capacity = (bd_size_t ) blocknr * block_len; // memory capacity = BLOCKNR * BLOCK_LEN
1055
+ blocks = capacity / _block_size;
1056
+ debug_if (SD_DBG, " Standard Capacity: c_size: %" PRIu32 " \n " , c_size);
1057
+ debug_if (SD_DBG, " Sectors: 0x%" PRIx64 " : %" PRIu64 " \n " , blocks, blocks);
1058
+ debug_if (SD_DBG, " Capacity: 0x%" PRIx64 " : %" PRIu64 " MB\n " , capacity, (capacity / (1024U * 1024U )));
1059
+
1060
+ // ERASE_BLK_EN = 1: Erase in multiple of 512 bytes supported
1061
+ if (ext_bits (csd, 46 , 46 )) {
1076
1062
_erase_size = BLOCK_SIZE_HC;
1077
- break ;
1063
+ } else {
1064
+ // ERASE_BLK_EN = 1: Erase in multiple of SECTOR_SIZE supported
1065
+ _erase_size = BLOCK_SIZE_HC * (ext_bits (csd, 45 , 39 ) + 1 );
1066
+ }
1067
+ break ;
1078
1068
1079
- default :
1080
- debug_if (SD_DBG, " CSD struct unsupported\r\n " );
1081
- return 0 ;
1069
+ case 1 :
1070
+ hc_c_size = ext_bits (csd, 69 , 48 ); // device size : C_SIZE : [69:48]
1071
+ blocks = (hc_c_size + 1 ) << 10 ; // block count = C_SIZE+1) * 1K byte (512B is block size)
1072
+ debug_if (SD_DBG, " SDHC/SDXC Card: hc_c_size: %" PRIu32 " \n " , hc_c_size);
1073
+ debug_if (SD_DBG, " Sectors: 0x%" PRIx64 " x : %" PRIu64 " \n " , blocks, blocks);
1074
+ debug_if (SD_DBG, " Capacity: %" PRIu64 " MB\n " , (blocks / (2048U )));
1075
+ // ERASE_BLK_EN is fixed to 1, which means host can erase one or multiple of 512 bytes.
1076
+ _erase_size = BLOCK_SIZE_HC;
1077
+ break ;
1078
+
1079
+ default :
1080
+ debug_if (SD_DBG, " CSD struct unsupported\r\n " );
1081
+ return 0 ;
1082
1082
};
1083
1083
return blocks;
1084
1084
}
0 commit comments