Page 1 of 5
SD-Card Insert/Remove Handlers
Posted: Thu Jan 23, 2014 3:27 pm
by Tabulous
Hi all,
just testing out the SD-Card on ChibiOS. Seems to work ok apart from one things.
Insert the card and card is mounted ok, if i now remove the card and then re-insert it, it will not mount. But once again if i remove it and re-insert it all is good agian.
Its like it only mounts once in every 2 inserts ???
Re: SD-Card Insert/Remove Handlers
Posted: Thu Jan 23, 2014 4:09 pm
by Giovanni
In which demo? the card detection code is different from board to board, it is in board.c.
Giovanni
Re: SD-Card Insert/Remove Handlers
Posted: Thu Jan 23, 2014 4:21 pm
by Tabulous
I have taken the code from Olimex E407
This is my sdc low level in board.c i changed it to report the card det status, which is connected to GPIOH pin13. Pin H13 is setup to Input with Pullup as the switch on the card holder pulls signal to ground. If i place break point on this it works perfectly.
bool_t sdc_lld_is_card_inserted(SDCDriver *sdcp) {
static bool_t last_status = FALSE;
return last_status = (bool_t)palReadPad(GPIOH, GPIOH_SDIO_DECT);
}
Re: SD-Card Insert/Remove Handlers
Posted: Thu Jan 23, 2014 4:29 pm
by Tabulous
Here are the handlers
static void InsertHandler(eventid_t id) {
FRESULT err;
(void)id;
/*
* On insertion SDC init and FS mount.
*/
if (sdcConnect(&SDCD1))
return;
err = f_mount(0, &SDC_FS);
if (err != FR_OK) {
sdcDisconnect(&SDCD1);
return;
}
palSetPad(GPIOG, GPIOG_LED2);
fs_ready = TRUE;
}
/*
* Card removal event.
*/
static void RemoveHandler(eventid_t id) {
(void)id;
/*
* On removal SDC de-init and um-mount.
*/
f_mount(0, NULL);
sdcDisconnect(&SDCD1);
palClearPad(GPIOG, GPIOG_LED2);
fs_ready = FALSE;
}
Re: SD-Card Insert/Remove Handlers
Posted: Thu Jan 23, 2014 8:49 pm
by Giovanni
The E407 uses a strange detection method, your board seems to have a dedicated signal for detection so you don't need that last_status variable.
Giovanni
Re: SD-Card Insert/Remove Handlers
Posted: Thu Jan 23, 2014 10:08 pm
by Tabulous
That is true, but that is not what is causing the issue. The comes because this
if (sdcConnect(&SDCD1))
return;
every alternate card insertion sdcConnect returns TRUE and thus with out mounting the file system.
Inspecting sdcConnect function it fails here and calls goto failed;
/* V2.0 cards detection.*/
if (!sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_SEND_IF_COND,
MMCSD_CMD8_PATTERN, resp)) {
sdcp->cardmode = SDC_MODE_CARDTYPE_SDV20;
/* Voltage verification.*/
if (((resp[0] >> 8) & 0xF) != 1)
goto failed;
Note this is predictable and repeatable.
Re: SD-Card Insert/Remove Handlers
Posted: Thu Jan 23, 2014 10:13 pm
by Giovanni
I never experienced that behavior, try adding a delay before sdcConnec(), just in case it is a power up problem. You may also try another (different) card.
Giovanni
Re: SD-Card Insert/Remove Handlers
Posted: Thu Jan 23, 2014 10:36 pm
by Tabulous
Tried couple of different cards,
SanDisk 1GB (Has the issue)
SanDisk 2GB (Has the issue)
Storage Options 4GB SDHC (works OK)
I dont have any issues with the above cards if i use them on the same hardware but running my own super loop(no chibios), with FatFS and STM Libs.
So i can only conclude that there is an issue in the SD-Card implementation in chibios
Re: SD-Card Insert/Remove Handlers
Posted: Thu Jan 23, 2014 10:44 pm
by Giovanni
Is the card removal event called on extraction?
Tabulous wrote:So i can only conclude that there is an issue in the SD-Card implementation in chibios
It is possible.
Giovanni
Re: SD-Card Insert/Remove Handlers
Posted: Thu Jan 23, 2014 10:54 pm
by Tabulous
Yeah everything looks like it should be working right, i've got some LEDs that indicate the card insertion state, you can see them in my code above.
These LED show exactly what i'm seeing, the card only gets mounted every alternate insertion.