Hi
I am using latest Mbed OS5, and I try to use SDBlockDevice API to access a HC micro SD card.
I have followed block device configuration, but the micro SD card fails to initialize.
The micro SD card seems to be fine. I can use a SD card reader to read / write / format the card.
The failure is due to a mismatch in “Voltage accepted” field in R7 response. I use a multimeter to probe the micro SD card housing, and confirm the reading is at 3.3V, so I am quite puzzle why “Voltage accepted” register values are different.
Below is the debug message when I turn on SD_DBG and SD_CMD_TRACE in SDBlockDevice.cpp
I got the same error regardless the clock speeds although I have tried SCK = 10kHz, 100kHz, 400kHz, 1MHz, 10MHz, 20MHz, 25MHz.
Really appreciate if someone can help shed some light on what I might be missing and what I can investigate further.
I modified the micro SD card pins directly in the following file, and I think it is ok since I am able to access the micro SD card as a block device (mentioned a bit further below)
mbed-os\components\storage\blockdevice\COMPONENT_SD\mbed_lib.json
However, I am getting the following assertion error while mounting (I have enable MBED_CONF_FAT_CHAN_FFS_DBG to help debugging).
Incidentally, if I do the following without mount, I can read / write to the micro SD card as a block device., but the size information doesn’t look correct. In addition, I do intent to set up a file system on the micro SD card. Am I missing anything from this set up so far?
err = bd->init();
if (err) {
printf("Can't init block device");
}
printf("sd size: %llu\n", bd->size()); // 67108864 on terminal vs actual: 4GB
printf("sd read size: %llu\n", bd->get_read_size()); // 1 on terminal
printf("sd program size: %llu\n", bd->get_program_size()); // 512 on terminal
printf("sd erase size: %llu\n", bd->get_erase_size()); // 262144 on terminal
uint8_t block[512] = "Hello World!\n";
if ( 0 == bd->program(block, 0, 512)) {
// read the data block from the device
if ( 0 == bd->read(block, 0, 512)) {
// print the contents of the block
printf("Message read: %s", block);
}
} else {
printf("SD Block Device Fail to read/write");
}
Update as of 5/12/20:
As I debug further, I noticed that the default block device was set to “QSPIF” (by calling BlockDevice::get_type()) instead of “SD”. Thus, I modified custom_target.json with “components_remove: [“QSPIF”]” and re-ran the block device example, but still failed due to the same “Voltage accepted” mismatch.
It turned out that I was using GCC_ARM compiler, and it would do sign extend on numerical comparison, so I have to explicitly cast the operands to have the correct behavior.
I am using Mbed Studio + Mbed-os 6.0 to access an external SD card. I notice SDBlockDevice.h is not recognized but BlockDevice.h is fine.
I use the following code:
BlockDevice *bd = BlockDevice::get_default_instance(); // ok
FATFileSystem fs(“sd”); // ok
BlockDevice sd (p5, p6, p7, p16); // not OK, error
My target board is mbed LPC1768. Any idea if latest Mbed-os 6.0 can support SD card functions ?
Also did not see mbed_app.json file next to main.cpp file.