SD-Card Insert/Remove Handlers
Moderators: RoccoMarco, lbednarz, tfAteba
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: SD-Card Insert/Remove Handlers
I have been able to reproduce the problem on an STM32-E407 and also found a workaround.
By inserting a 10ms delay between sdc_lld_start_clk() and sdc_lld_send_cmd_none() in sdcConnect() the problem is resolved.
My problem is that I am unable to find a requirement for this, is this specified somewhere?
Giovanni
By inserting a 10ms delay between sdc_lld_start_clk() and sdc_lld_send_cmd_none() in sdcConnect() the problem is resolved.
My problem is that I am unable to find a requirement for this, is this specified somewhere?
Giovanni
Re: SD-Card Insert/Remove Handlers
Excellent, in my application i like to provide the customer with hot plugable SD-Card operation, so thats why it was causing me some grief.
I can conifrm adding the following fixes the issue
/* Card clock initialization.*/
sdc_lld_start_clk(sdcp);
/* Let the card settle.*/
chThdSleepMilliseconds(10);
/* Enforces the initial card state.*/
sdc_lld_send_cmd_none(sdcp, MMCSD_CMD_GO_IDLE_STATE, 0);
I can conifrm adding the following fixes the issue
/* Card clock initialization.*/
sdc_lld_start_clk(sdcp);
/* Let the card settle.*/
chThdSleepMilliseconds(10);
/* Enforces the initial card state.*/
sdc_lld_send_cmd_none(sdcp, MMCSD_CMD_GO_IDLE_STATE, 0);
Re: SD-Card Insert/Remove Handlers
What i am getting now is _unhandled_exception, this happens here when the f_open is called it fails in here
bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk,
uint8_t *buf, uint32_t n) {
bool_t status;
chDbgCheck((sdcp != NULL) && (buf != NULL) && (n > 0), "sdcRead");
chDbgAssert(sdcp->state == BLK_READY, "sdcRead(), #1", "invalid state");
if ((startblk + n - 1) > sdcp->capacity){
sdcp->errors |= SDC_OVERFLOW_ERROR;
return CH_FAILED;
}
/* Read operation in progress.*/
sdcp->state = BLK_READING;
bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk,
uint8_t *buf, uint32_t n) {
bool_t status;
chDbgCheck((sdcp != NULL) && (buf != NULL) && (n > 0), "sdcRead");
chDbgAssert(sdcp->state == BLK_READY, "sdcRead(), #1", "invalid state");
if ((startblk + n - 1) > sdcp->capacity){
sdcp->errors |= SDC_OVERFLOW_ERROR;
return CH_FAILED;
}
/* Read operation in progress.*/
sdcp->state = BLK_READING;
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: SD-Card Insert/Remove Handlers
It could be anything from a stack overflow to a wrong pointer.
Giovanni
Giovanni
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: SD-Card Insert/Remove Handlers
I committed the fix as bug #464, I also changed that read timeout default from 5 to 25.
Giovanni
Giovanni
Re: SD-Card Insert/Remove Handlers
so this is what ive got, blinky thread modified to write a string to text.txt file on the sd-card. At the moment i get _unhandled_exception as explained above
/*
* Green LED blinker thread, times are in milliseconds.
*/
static WORKING_AREA(waThread1, 128);
static msg_t Thread1(void *arg) {
(void)arg;
FIL file;
UINT wbytes;
FRESULT result;
char msgstr[40];
chRegSetThreadName("blinker");
while (TRUE) {
chThdSleepMilliseconds(1000);
if(fs_mounted == TRUE)
{
result = f_open( &file, "test.txt",//filename,
FA_OPEN_ALWAYS | FA_WRITE );
if( result == FR_OK )
{
f_lseek(&file, file.fsize);
strcpy( msgstr, "Hello World......\r\n");
f_write( &file, msgstr, strlen(msgstr), &wbytes );
f_close( &file );
}
}
}
}
If i change the WORKING_AREA to 512 it now loops in while loop doing nothing
Thread *chSchReadyI(Thread *tp) {
Thread *cp;
chDbgCheckClassI();
/* Integrity checks.*/
chDbgAssert((tp->p_state != THD_STATE_READY) &&
(tp->p_state != THD_STATE_FINAL),
"chSchReadyI(), #1",
"invalid state");
tp->p_state = THD_STATE_READY;
cp = (Thread *)&rlist.r_queue;
do {
cp = cp->p_next;
} while (cp->p_prio >= tp->p_prio);
/* Insertion on p_prev.*/
tp->p_next = cp;
tp->p_prev = cp->p_prev;
tp->p_prev->p_next = cp->p_prev = tp;
return tp;
}
/*
* Green LED blinker thread, times are in milliseconds.
*/
static WORKING_AREA(waThread1, 128);
static msg_t Thread1(void *arg) {
(void)arg;
FIL file;
UINT wbytes;
FRESULT result;
char msgstr[40];
chRegSetThreadName("blinker");
while (TRUE) {
chThdSleepMilliseconds(1000);
if(fs_mounted == TRUE)
{
result = f_open( &file, "test.txt",//filename,
FA_OPEN_ALWAYS | FA_WRITE );
if( result == FR_OK )
{
f_lseek(&file, file.fsize);
strcpy( msgstr, "Hello World......\r\n");
f_write( &file, msgstr, strlen(msgstr), &wbytes );
f_close( &file );
}
}
}
}
If i change the WORKING_AREA to 512 it now loops in while loop doing nothing
Thread *chSchReadyI(Thread *tp) {
Thread *cp;
chDbgCheckClassI();
/* Integrity checks.*/
chDbgAssert((tp->p_state != THD_STATE_READY) &&
(tp->p_state != THD_STATE_FINAL),
"chSchReadyI(), #1",
"invalid state");
tp->p_state = THD_STATE_READY;
cp = (Thread *)&rlist.r_queue;
do {
cp = cp->p_next;
} while (cp->p_prio >= tp->p_prio);
/* Insertion on p_prev.*/
tp->p_next = cp;
tp->p_prev = cp->p_prev;
tp->p_prev->p_next = cp->p_prev = tp;
return tp;
}
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: SD-Card Insert/Remove Handlers
What optimization level are you using? are debug options enabled in chconf.h?
Giovanni
Giovanni
Re: SD-Card Insert/Remove Handlers
I never knowingly use optimizations for just the reason you are asking, they are often not worth the hassle......
But at the moment it is using the default chibios settting od -O2
The only debug option that is TRUE is THREADS_PROFILING, all the rest are FALSE.
But at the moment it is using the default chibios settting od -O2
The only debug option that is TRUE is THREADS_PROFILING, all the rest are FALSE.
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: SD-Card Insert/Remove Handlers
Try enabling all of them and see if something is caught (it goes in halt and the dbg_panic_msg variable points to a message).
Giovanni
Giovanni