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 ???
SD-Card Insert/Remove Handlers
Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess
- 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
In which demo? the card detection code is different from board to board, it is in board.c.
Giovanni
Giovanni
Re: SD-Card Insert/Remove Handlers
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);
}
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
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;
}
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;
}
- 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
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
Giovanni
Re: SD-Card Insert/Remove Handlers
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.
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.
- 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
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
Giovanni
Re: SD-Card Insert/Remove Handlers
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
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
- 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
Is the card removal event called on extraction?
It is possible.
Giovanni
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
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.
These LED show exactly what i'm seeing, the card only gets mounted every alternate insertion.
Who is online
Users browsing this forum: No registered users and 9 guests