You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to extend your simple example for an application where sd cards get removed and replugged while the program continues to run.
I've modified the code the code to run within a loop and added delays between unmount and remount for replugging the sd card.
During testing testing i've noticed the following behavior:
As soon as i remove and insert the sd-card again, the app "panics" with the following output:
No response CMD:17
No response CMD:17
No response CMD:17
No response CMD:17 response: 0xff
*** PANIC ***
f_mount error: A hard error occurred in the low level disk I
As long as the card stays plugged-in the first time since reboot - access works fine. Also if I replug the card without ever accessing it (since reboot) it works just fine.
Would you please point me in the right direction regarding the additional things that need to be considered for this usecase?
The modified sample code:
#include<stdio.h>//#include"f_util.h"#include"ff.h"#include"pico/stdlib.h"#include"rtc.h"//#include"hw_config.h"intmain() {
stdio_init_all();
// Set display chip select to high (connected to same SPI)gpio_init(5);
gpio_set_dir(5, GPIO_OUT);
gpio_put(5, 1);
// set and hold i2c portexpander in reset (high impedance outputs)gpio_init(17);
gpio_set_dir(17, GPIO_OUT);
gpio_put(17, 0);
time_init();
sleep_ms(2000);
puts("------------");
puts("Hello, world!");
puts("------------");
while (true) {
puts("Insert Card...");
sleep_ms(8000);
// See FatFs - Generic FAT Filesystem Module, "Application Interface",// http://elm-chan.org/fsw/ff/00index_e.htmlFATFSfs;
puts("mount...");
FRESULTfr=f_mount(&fs, "", 1);
if (FR_OK!=fr) panic("f_mount error: %s (%d)\n", FRESULT_str(fr), fr);
FILfil;
constchar*constfilename="filename_long.txt";
puts("fr_open file.txt...");
fr=f_open(&fil, filename, FA_OPEN_APPEND | FA_WRITE);
if (FR_OK!=fr&&FR_EXIST!=fr) {
panic("f_open(%s) error: %s (%d)\n", filename, FRESULT_str(fr), fr);
}
puts("write hello world into file...");
if (f_printf(&fil, "Hello, world!\n") <0) {
printf("f_printf failed\n");
}
puts("close file");
fr=f_close(&fil);
if (FR_OK!=fr) {
printf("f_close error: %s (%d)\n", FRESULT_str(fr), fr);
}
puts("unmount...");
f_unmount("");
puts("Done!");
puts("Remove Card now!");
sleep_ms(8000);
}
}
Kind Regards
Nasrudin
The text was updated successfully, but these errors were encountered:
Does your SD card socket support Card Detection (Insertion/Removal)? I recommend that you set up an interrupt on the Card Detect line to detect removal or insertion of the card when it happens. For example, see main.cpp. Also, see Notes about Card Detect.
Dear Carl,
I am trying to extend your simple example for an application where sd cards get removed and replugged while the program continues to run.
I've modified the code the code to run within a loop and added delays between unmount and remount for replugging the sd card.
During testing testing i've noticed the following behavior:
As soon as i remove and insert the sd-card again, the app "panics" with the following output:
As long as the card stays plugged-in the first time since reboot - access works fine. Also if I replug the card without ever accessing it (since reboot) it works just fine.
Would you please point me in the right direction regarding the additional things that need to be considered for this usecase?
The modified sample code:
Kind Regards
Nasrudin
The text was updated successfully, but these errors were encountered: