Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdcard: disable card detect pull-up resistor in card with ACMD42 #65

Closed
mcudev opened this issue Jul 23, 2018 · 1 comment
Closed

sdcard: disable card detect pull-up resistor in card with ACMD42 #65

mcudev opened this issue Jul 23, 2018 · 1 comment
Assignees
Labels
code Code improvements core Trezor Core firmware. Runs on Trezor Model T and T2B1. hardware only Issue which does not appear on the emulator - but on physical device only.
Milestone

Comments

@mcudev
Copy link
Contributor

mcudev commented Jul 23, 2018

Pin 2 of the microSD socket is CD/DAT3 (MCU pin PC11).
When the microSD card gets powered-on, it enables a pull-up resistor internal to the card on CD/DAT3.
This acts as a card detect pin since the card starts up in 1-bit mode and thus DAT3 is unused for data transfer at that time.
Later we change to use a 4-bit data bus, but don't disable the card's internal card detect pull-up resistor with ACMD42.
We should probably do that just to be safe before switching to 4-bit mode at https://github.com/trezor/trezor-core/blob/cb9e7b5885a47f900c24153e22e4f93b39cbb792/embed/trezorhal/sdcard.c#L149

vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_sdmmc.c is useful for seeing how the HAL does its work.

Here's some more example code:
https://github.com/LonelyWolf/stm32/blob/master/cube-usb-msc/sdcard-sdio.c

Will probably end up with something functionally similar to this, but need to factor code, etc...

    // disable the card's internal CD/DAT3 card detect pull-up resistor
    // to send ACMD42, we have to send CMD55 (APP_CMD) with with the card's RCA as the argument followed by CMD42 (SET_CLR_CARD_DETECT)
    if(SDMMC_CmdAppCommand(sd_handle.Instance, (uint32_t)(sd_handle.SdCard.RelCardAdd << 16U)) != SDMMC_ERROR_NONE) {
    	goto error;
    }
    SDIO_CmdInitTypeDef  sdmmc_cmdinit;
    sdmmc_cmdinit.Argument         = 0U; // disable card detect resistor
    sdmmc_cmdinit.CmdIndex         = SDMMC_CMD_SD_APP_SET_CLR_CARD_DETECT;
    sdmmc_cmdinit.Response         = SDIO_RESPONSE_SHORT;
    sdmmc_cmdinit.WaitForInterrupt = SDIO_WAIT_NO;
    sdmmc_cmdinit.CPSM             = SDIO_CPSM_ENABLE;
    SDIO_SendCommand(sd_handle.Instance, &sdmmc_cmdinit);

    if (SDMMC_GetCmdResp1(sd_handle.Instance, SDMMC_CMD_SD_APP_SET_CLR_CARD_DETECT, SDIO_CMDTIMEOUT) != SDMMC_ERROR_NONE) {
    	goto error;
    }

Reference:

http://envoydatamemory.com/datasheets/EN-L0J%20Industrial%20microSD%20Card%20Spec%20Rev1.6.pdf

https://www.kingston.com/datasheets/SDCIT-specsheet-8gb-32gb_en.pdf

trezor/trezor-core#279 (comment)

@prusnak prusnak transferred this issue from trezor/trezor-core Apr 17, 2019
@prusnak prusnak added this to the backlog milestone Apr 17, 2019
@prusnak prusnak added core Trezor Core firmware. Runs on Trezor Model T and T2B1. hardware only Issue which does not appear on the emulator - but on physical device only. and removed core Trezor Core firmware. Runs on Trezor Model T and T2B1. labels Apr 17, 2019
@tsusanka tsusanka added S4 Low code Code improvements labels Sep 12, 2019
@prusnak prusnak self-assigned this Sep 24, 2019
@prusnak prusnak modified the milestones: backlog, 2019-11 Sep 24, 2019
@prusnak
Copy link
Member

prusnak commented Sep 25, 2019

Implemented in dcff4ad

Thank you!

@prusnak prusnak closed this as completed Sep 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code Code improvements core Trezor Core firmware. Runs on Trezor Model T and T2B1. hardware only Issue which does not appear on the emulator - but on physical device only.
Projects
None yet
Development

No branches or pull requests

3 participants