I used standard examples from ChibiOS and found that when removing card while reading, the driver remains in state BLK_READING. When RemoveHandler try to execute mmcDisconnect it halted in PortHalt with dbg message: "mmcDisconnect(), #1", "invalid state".
If change the state of the driver manually, then it works. But I am not shure it is right way?
Code: Select all
/* MMC card removal event.*/
static void RemoveHandler(eventid_t id)
{
(void)id;
DEBUG_TRACE("SD CARD REMOVED...\n\r\n\r");
f_mount(0, NULL);
fs_ready = FALSE;
if ((MMCD1.state != BLK_READY) && (MMCD1.state != BLK_ACTIVE)) MMCD1.state = BLK_ACTIVE;
mmcDisconnect(&MMCD1);
DEBUG_TRACE("disconnected...\n\r");
}
I looked at code of MMC driver and found that there are no driver state transitions on errors.
Code: Select all
619 bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) {
620 int i;
...
636 /* Timeout.*/
637 spiUnselect(mmcp->config->spip);
638 spiStop(mmcp->config->spip);
639 return CH_FAILED;
...
the same picture in other places. May need to add them?
p.s. I know that removing card in active state is danger for card or(and) data but in real application it may be, or may be some other reading/writing errors. I think the good application must have correct error handling...