Skip to content

Conversation

@iabdalkader
Copy link
Contributor

When HAL_SDIO_WriteExtended_DMA or HAL_SDIO_ReadExtended_DMA returns an error, interrupts are not enabled so the semaphore would never be given, and it will always timeout.

Some drivers expect certain functions to fail during normal operation. For example, WHD calls whd_kso_enable during sleep/wakeup cycles which can fail. This would waste 200ms (CONFIG_SD_CMD_TIMEOUT default) on every such failure.

For reference, the logic of HAL_SDIO_WriteExtended_DMA and HAL_SDIO_ReadExtended_DMA looks like this:

HAL_StatusTypeDef HAL_SDIO_WriteExtended_DMA(...) {
    if (params == NULL)
        return HAL_ERROR;              // No ISR enabled

    if (state != READY)
        return HAL_BUSY;               // No ISR enabled

    // ... setup DMA, configure DPSM ...

    errorstate = SDMMC_SDIO_CmdReadWriteExtended(...);
    if (errorstate != HAL_SDIO_ERROR_NONE) {
        hsdio->ErrorCode |= errorstate;
        if (errorstate != (ADDR_OUT_OF_RANGE | ILLEGAL_CMD | COM_CRC_FAILED | GENERAL_UNKNOWN_ERR)) {
            // cleanup
            return HAL_ERROR;          // No ISR enabled
        }
    }

    // Enable interrupts - only reached if no early return
    __HAL_SDIO_ENABLE_IT(hsdio, (DCRCFAIL | DTIMEOUT | TXUNDERR | DATAEND));

    return HAL_OK;
}

When HAL_SDIO_WriteExtended_DMA or HAL_SDIO_ReadExtended_DMA returns
an error, interrupts are not enabled so the semaphore would never be
given, and it will always timeout.

Some drivers expect certain functions to fail during normal operation.
For example, WHD calls whd_kso_enable during sleep/wakeup cycles which
can fail. This would waste 200ms (CONFIG_SD_CMD_TIMEOUT default) on
every such failure.

Signed-off-by: Ibrahim Abdalkader <[email protected]>
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants