Page 1 of 1

sdcDisconnect wait forever

Posted: Fri Jan 31, 2020 9:27 am
by wurstnase
Hi,

I'm trying to find an issue with my SD-card slot.

Actually I trigger a manual disconnect from the sd-card. After some disconnects the driver will hang in a while loop:

hal_sdc.c

Code: Select all

bool sdcDisconnect(SDCDriver *sdcp) {
//...snip...//

  /* Waits for eventual pending operations completion.*/
  if (_sdc_wait_for_transfer_state(sdcp)) { // <- wait here
    sdc_lld_stop_clk(sdcp);
    sdcp->state = BLK_ACTIVE;
    return HAL_FAILED;
  }


hal_sdc.c

Code: Select all

bool _sdc_wait_for_transfer_state(SDCDriver *sdcp) {
  uint32_t resp[1];

  while (true) {
    if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_SEND_STATUS, // <- wait here
                                   sdcp->rca, resp) ||
        MMCSD_R1_ERROR(resp[0])) {
      return HAL_FAILED;
    }


os/hal/ports/STM32/LLD/SDIOv1/hal_sdc_lld.c

Code: Select all

bool sdc_lld_send_cmd_short_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg,
                                uint32_t *resp) {
  uint32_t sta;

  sdcp->sdio->ARG = arg;
  sdcp->sdio->CMD = (uint32_t)cmd | SDIO_CMD_WAITRESP_0 | SDIO_CMD_CPSMEN;
  while (((sta = sdcp->sdio->STA) & (SDIO_STA_CMDREND | SDIO_STA_CTIMEOUT |
                                     SDIO_STA_CCRCFAIL)) == 0) // <- the STA stay at 0
    ;


Any idea what happend, or how I could prevent this?

Re: sdcDisconnect wait forever

Posted: Fri Jan 31, 2020 9:55 am
by Giovanni
Hi,

Is the card always inserted during the connect/disconnect attempts?

Perhaps the driver needs a timeout during those waiting loops.

Giovanni

Re: sdcDisconnect wait forever

Posted: Fri Jan 31, 2020 10:23 am
by wurstnase
Hi Giovanni,

yes the card is any time in the slot.

It could be an hardware issue, because I can see this issue mainly, when the wifi-module, close to it, will create a connection, which could draw more current in that situation.

Re: sdcDisconnect wait forever

Posted: Fri Jan 31, 2020 11:29 am
by wurstnase
I should enable the CHIBIOS debug options...

The sdcDisconnect will stop, because it is not BKL_READY.
Before I make a sdcDisconnect I wait now for a sdcSync will return HAL_SUCCESS.