SD-Card Insert/Remove Handlers

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

Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

SD-Card Insert/Remove Handlers

Postby Tabulous » Thu Jan 23, 2014 3:27 pm

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 ???

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: SD-Card Insert/Remove Handlers

Postby Giovanni » Thu Jan 23, 2014 4:09 pm

In which demo? the card detection code is different from board to board, it is in board.c.

Giovanni

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

Re: SD-Card Insert/Remove Handlers

Postby Tabulous » Thu Jan 23, 2014 4:21 pm

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);
}

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

Re: SD-Card Insert/Remove Handlers

Postby Tabulous » Thu Jan 23, 2014 4:29 pm

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;
}

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: SD-Card Insert/Remove Handlers

Postby Giovanni » Thu Jan 23, 2014 8:49 pm

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

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

Re: SD-Card Insert/Remove Handlers

Postby Tabulous » Thu Jan 23, 2014 10:08 pm

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.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: SD-Card Insert/Remove Handlers

Postby Giovanni » Thu Jan 23, 2014 10:13 pm

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

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

Re: SD-Card Insert/Remove Handlers

Postby Tabulous » Thu Jan 23, 2014 10:36 pm

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

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: SD-Card Insert/Remove Handlers

Postby Giovanni » Thu Jan 23, 2014 10:44 pm

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

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

Re: SD-Card Insert/Remove Handlers

Postby Tabulous » Thu Jan 23, 2014 10:54 pm

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.


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 9 guests