Page 1 of 1

Error handling in MMC Driver

Posted: Fri Jan 25, 2013 11:20 am
by alexblack
I trying to work with FATfs with MMC over SPI driver on my STM32F103 device.
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...

Re: Error handling in MMC Driver

Posted: Fri Jan 25, 2013 7:54 pm
by Giovanni
Hi,

Thanks for finding, the driver should go in the active state so it is a bug, could you add a ticket?

I am traveling so I can't fix it right away. The fix should be simple but I noticed that also the documentation needs an update, in the meanwhile you can ignore the assertion, nothing is affected by the problem.

Giovanni

Re: Error handling in MMC Driver

Posted: Sat Jan 26, 2013 11:30 am
by alexblack
Hi,
Giovanni wrote:Thanks for finding, the driver should go in the active state so it is a bug, could you add a ticket?
Giovanni

Sorry, I do not know how to do this. Can you give me a link where it is described?

Re: Error handling in MMC Driver

Posted: Sat Jan 26, 2013 12:54 pm
by Giovanni
Hi,

It is done on the sourceforge project page but nevermind, I will add it myself in the evening.

Giovanni

Re: Error handling in MMC Driver

Posted: Sun Feb 24, 2013 9:12 am
by Giovanni
Hi,

I committed a fixed for this, the state machine handling was more incorrect than I initially thought. Bug 3605794.

Giovanni