Skip to content

Commit

Permalink
Merge pull request #41 from oyama/fix/v2-sdcard-init-response-not-che…
Browse files Browse the repository at this point in the history
…cked

Check SD Card V2 initialisation response
  • Loading branch information
oyama authored Jun 15, 2024
2 parents abb90ca + 5cef194 commit 6f9f613
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
8 changes: 4 additions & 4 deletions examples/benchmark/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ int main(void) {
stdio_init_all();
init_filesystem_combination();

for (size_t i = 0; i < NUM_COMBINATION; i++) {
for (size_t i = 3; i < NUM_COMBINATION; i++) {
struct combination_map setting = combination[i];
printf("Test of %s on %s:\n", setting.filesystem->name, setting.device->name);

Expand All @@ -172,12 +172,12 @@ int main(void) {
continue;
}
if (err == -1) {
printf("fs_format error: %s\n", strerror(errno));
printf("fs_format error: %s\n", fs_strerror(errno));
return -1;
}
err = fs_mount("/", setting.filesystem, setting.device);
if (err == -1) {
printf("fs_mount / error: %s\n", strerror(errno));
printf("fs_mount / error: %s\n", fs_strerror(errno));
return -1;
}

Expand All @@ -186,7 +186,7 @@ int main(void) {

err = fs_unmount("/");
if (err == 01) {
printf("fs_unmount / error: %s\n", strerror(errno));
printf("fs_unmount / error: %s\n", fs_strerror(errno));
return -1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/blockdevice/sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ static int _cmd8(void *_config) {

arg |= (0x1 << 8); // 2.7-3.6V // [11:8]supply voltage(VHS)

status = _cmd(config, CMD8_SEND_IF_COND, arg, false, NULL);
status = _cmd(config, CMD8_SEND_IF_COND, arg, false, &response);
// Verify voltage and pattern for V2 version of card
if ((BD_ERROR_OK == status) && (SDCARD_V2 == config->card_type)) {
// If check pattern is not matched, CMD8 communication is not valid
Expand Down
47 changes: 45 additions & 2 deletions src/filesystem/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,51 @@ struct dirent *readdir(DIR *dir) {
}
}

char *fs_strerror(int error) {
return strerror(-error);
char *fs_strerror(int errnum) {
if (errnum > 5000) {
// SD blockdevice error
const char *str = "";
switch (errnum) {
case 5001:
str = "operation would block";
break;
case 5002:
str = "unsupported operation";
break;
case 5003:
str = "invalid parameter";
break;
case 5004:
str = "uninitialized";
break;
case 5005:
str = "device is missing or not connected";
break;
case 5006:
str = "write protected";
break;
case 5007:
str = "unusable card";
break;
case 5008:
str = "No response from device";
break;
case 5009:
str = "CRC error";
break;
case 5010:
str = "Erase error: reset/sequence";
break;
case 5011:
str = "Write error: !SPI_DATA_ACCEPTED";
break;
default:
break;
}
return (char *)str;
} else {
return strerror(errnum);
}
}

#if defined(PICO_FS_AUTO_INIT)
Expand Down

0 comments on commit 6f9f613

Please sign in to comment.