Error handling in MMC Driver

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
alexblack
Posts: 277
Joined: Mon Sep 24, 2012 3:52 pm
Been thanked: 33 times

Error handling in MMC Driver

Post 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...
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Error handling in MMC Driver

Post 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
alexblack
Posts: 277
Joined: Mon Sep 24, 2012 3:52 pm
Been thanked: 33 times

Re: Error handling in MMC Driver

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Error handling in MMC Driver

Post by Giovanni »

Hi,

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

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Error handling in MMC Driver

Post by Giovanni »

Hi,

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

Giovanni
Post Reply