R128驱动SD卡失败
-
menuconfig配置如下:
引脚配置如下:
报错信息如下:
-
硬件是怎么接入的呢?
-
正常挂载log
card_detect removed sdmmc_test->card_id=0 [WRN] SDC:sdc:0000000008280E50 no medium present SDC:Not imp HAL_SDC_PowerOff,2028 SDC:Not implement __mci_hold_io,823 SD:mmc_card_delete card:00000000081A3370 id:0 card_detect insert sdmmc_test->card_id=0 card id is 0 SD:mmc_card_create card:00000000081A3370 id:0 card debug mask 3c SDC:Not implement __mci_restore_io,838 HAL_GetHFClock,53 Warning Use fix value 24000000 HAL_GetHFClock,53 Warning Use fix value 24000000 HAL_GetHFClock,53 Warning Use fix value 24000000 SDC:SDC clock=416666 kHz,src:0, n:2, m:11 HAL_GetHFClock,53 Warning Use fix value 24000000 HAL_GetHFClock,53 Warning Use fix value 24000000 HAL_GetHFClock,53 Warning Use fix value 24000000 SDC:SDC clock=416666 kHz,src:0, n:2, m:11 [ERR] SDC:__mci_irq_handler,924 raw_int:100 err! [ERR] SDC:SDC err, cmd 52, RTO [ERR] SDC:sdc 701 abnormal status: RespErr [ERR] SDC:__mci_irq_handler,924 raw_int:100 err! [ERR] SDC:SDC err, cmd 52, RTO [ERR] SDC:sdc 701 abnormal status: RespErr SD:***** Try sdio ***** [ERR] SDC:__mci_irq_handler,924 raw_int:100 err! [ERR] SDC:SDC err, cmd 5, RTO [ERR] SDC:sdc 701 abnormal status: RespErr SD:***** Try sd ***** mmc_send_app_op_cond,89 SD:card ocr: c0ff8000 SD:Card CID number:2544d53 SD:card raw cid: SD:card raw csd: m:29567, e:2, dtr:25000000, cl:1461, len:9, cap:30277632 str:1 SD:card raw scr: SD:card raw SD status: HAL_GetHFClock,53 Warning Use fix value 24000000 HAL_GetDevClock,90 Warning Use fix value 192000000 HAL_GetDevClock,90 Warning Use fix value 192000000 SDC:SDC clock=48000000 kHz,src:1, n:0, m:1 SD:card is switched to high speed mode, clk:50000 KHz SD:Set bus width type: 2 SD: ============= card information ============== SD:Card Type : SDHC SD:Card Spec Ver : 5.0 SD:Card RCA : 0x1234 SD:Card OCR : 0x40ff8000 SD: vol_window : 0x00ff8000 SD: to_1v8_acpt : 0 SD: high_capac : 0 SD:Card CSD : SD: speed : 50000 KHz SD: cmd class : 0x5b5 SD: capacity : 14784MB SD:Card CUR_STA : SD: speed_mode : HS: 50 MHz SD: bus_width : 2 SD: speed_class : 10 SD:============================================= SD:***** sd init ok ***** Initial card success mount successully
-
可以尝试打入这个补丁
diff --git a/hal/source/sdmmc/_sdhost.h b/hal/source/sdmmc/_sdhost.h index ef910bd..b570026 100644 --- a/hal/source/sdmmc/_sdhost.h +++ b/hal/source/sdmmc/_sdhost.h @@ -404,6 +404,9 @@ #define SDXC_REG_DAT1_CRC (0x12C) #define SDXC_REG_DAT0_CRC (0x130) #define SDXC_REG_CRC_STA (0x134) +#define SDXC_REG_DRV_DL (0x140) +#define SDXC_REG_SAMP_DL (0x144) +#define SDXC_REG_DS_DL (0x148) #define SDXC_REG_FIFO (0x200) /* SMC FIFO Access Address */ #define SDXC_REG_FCTL (0x64) /* SMC FIFO Access Address */ diff --git a/hal/source/sdmmc/hal_sdhost.c b/hal/source/sdmmc/hal_sdhost.c index dedf897..e47b3da 100644 --- a/hal/source/sdmmc/hal_sdhost.c +++ b/hal/source/sdmmc/hal_sdhost.c @@ -1017,6 +1017,7 @@ uint32_t rval; uint32_t src = 0; uint32_t m, n; + uint32_t clk_2x; if (cclk > DEFINE_SYS_CRYSTAL/2) { #ifdef NUSE_STANDARD_INTERFACE @@ -1033,8 +1034,8 @@ #endif sclk = DEFINE_SYS_CRYSTAL; } - cclk = cclk * 2; /* 2x MODE clock configure */ - div = (2 * sclk + cclk) / (2 * cclk); + clk_2x = cclk * 2; /* 2x MODE clock configure */ + div = (2 * sclk + clk_2x) / (2 * clk_2x); div = div == 0 ? 1 : div; if (div > 128) { n = 3; @@ -1142,6 +1143,37 @@ mci_writel(rval, host, SDXC_REG_CLKCR); sdc_hex_dump_word((void *)SDC_CCM_BASE ,0x900); +#ifdef CONFIG_ARCH_SUN20IW2 +#define CFGDLY (0x3F<<0) +#define ENABLEDLY (1<<7) + uint32_t samclk_pha = 0; + + if (cclk <= 50000000) { + samclk_pha = 6;//6; //63 + } else if (cclk <= 100000000) { + samclk_pha = 21; + } else if (cclk <= 150000000) { + samclk_pha = 24;//11;//23;3-24 + } else if (cclk <= 200000000) { + samclk_pha = 24;//6;//15;//33; + } + rval = mci_readl(host, SDXC_REG_NTSR); + rval &= ~(0x1<<31); // old timming mode + mci_writel(rval, host, SDXC_REG_NTSR); + + rval = mci_readl(host, SDXC_REG_SAMP_DL); + rval &= ~CFGDLY; + rval |= ENABLEDLY | samclk_pha; + mci_writel(rval, host, SDXC_REG_SAMP_DL); + + rval = mci_readl(host, SDXC_REG_DS_DL); + rval &= ~CFGDLY; + rval |= ENABLEDLY | samclk_pha; + mci_writel(rval, host, SDXC_REG_DS_DL); + + mci_writel(0x0, host, SDXC_REG_DRV_DL); +#endif + return cclk; } @@ -1949,11 +1981,6 @@ mci_writel(rval, host, SDXC_REG_GCTRL); #endif -#ifdef CONFIG_ARCH_SUN20IW2 - mci_writel(mci_readl(host, SDXC_REG_NTSR) | 0x110, host, SDXC_REG_NTSR); - mci_writel(0x00030000, host, 0x140); -#endif - if (host->sdc_id == 0) { SDC_ENABLE_IRQ(SDC0_IRQn); } diff --git a/hal/source/sdmmc/sd.c b/hal/source/sdmmc/sd.c index f569730..957250d 100644 --- a/hal/source/sdmmc/sd.c +++ b/hal/source/sdmmc/sd.c @@ -732,6 +732,24 @@ return err; } +static int32_t mmc_sd_switch_hs_mode(struct mmc_card *card) +{ + uint32_t status[64/sizeof(uint32_t)] = {0}; + int32_t err; + uint32_t timing = 0; + uint8_t *p_sta = (uint8_t *)status; + + err = mmc_sd_switch(card, SD_SWITCH_SET, SD_SWITCH_GRP_ACCESS_MODE, card->sd_bus_speed, p_sta); + if (err) + return err; + + if ((p_sta[16] & 0xF) != card->sd_bus_speed) { + SD_LOGW("%s: Problem setting bus speed mode!\n", __func__); + } + + return 0; +} + /* * Test if the card supports high-speed mode and, if so, switch to it. */ @@ -993,9 +1011,12 @@ if (err) return -1; } else { - mmc_card_set_highspeed(card); card->sd_bus_speed = HIGH_SPEED_BUS_SPEED; - + err = mmc_sd_switch_hs_mode(card); + if (err) { + SD_LOGW("switch to high speed error, use DS: 25 MHz\n"); + } + mmc_card_set_highspeed(card); clk = mmc_sd_get_max_clock(card); err = HAL_SDC_Update_Clk(card->host, clk); if (err)
-
@awwwwa 问题没解决,应该是我用杜邦线飞线的原因,后面画个pcb再试试看看
-
[sdc0] card_ctrl = 0 card_high_speed = 0 card_line = 4 sdc_d1 = port:PA27<2><1><3><default> sdc_d0 = port:PA26<2><1><3><default> sdc_clk = port:PA29<2><1><3><default> sdc_cmd = port:PA25<2><1><3><default> sdc_d3 = port:PA24<2><1><3><default> sdc_d2 = port:PA28<2><1><3><default> [sdc0det_para] sdc0_det = port:PA23<0><1><3><1>
适配 EVT 的测试镜像:
be810818-4bc0-447f-8705-d5d70abd8813-rtos_freertos_r128s2_evt_uart0_16Mnor.img -
@awwwwa 现在变成这样了:
-
@biubiu 试试换一张卡看看,可能是不支持这个卡的型号
-
@awwwwa 你用的是什么卡?我这三张卡都不行。。。
-
@biubiu 闪迪128G SDXC 和无标山寨卡 SDHC 都测试通过
-
- SanDisk HIGH ENDURABCE 32G SDHC Pass
- SanDisk Ultra 128G SDXC Pass
- NOKIA 2.0G Fail
- Unknow SD 120M SDHC Pass
- Kingston 4G SDHC Pass
- Micro SD 512M SDHC Pass
- ADATA Micro SD 2G SDHC Pass
- Kioxia exceria 32G SDHC Pass
- SanDisk Ultra 16GB SDHC Pass
- SanDisk HIGH ENDURABCE 32G SDHC Pass
-
@awwwwa 我这试了四张卡,只有这张可以:
输出log:
c906> c906>card_detect insert sdmmc_test->card_id=0 card id is 0 SD:mmc_card_create card:00000000084601D0 id:0 card debug mask 3c SDC:Not implement __mci_restore_io,838 HAL_GetHFClock,53 Warning Use fix value 24000000 HAL_GetHFClock,53 Warning Use fix value 24000000 HAL_GetHFClock,53 Warning Use fix value 24000000 SDC:SDC clock=416666 kHz,src:0, n:2, m:11 HAL_GetHFClock,53 Warning Use fix value 24000000 HAL_GetHFClock,53 Warning Use fix value 24000000 HAL_GetHFClock,53 Warning Use fix value 24000000 SDC:SDC clock=416666 kHz,src:0, n:2, m:11 [ERR] SDC:__mci_irq_handler,924 raw_int:100 err! [ERR] SDC:SDC err, cmd 52, RTO [ERR] SDC:sdc 701 abnormal status: RespErr [ERR] SDC:__mci_irq_handler,924 raw_int:100 err! [ERR] SDC:SDC err, cmd 52, RTO [ERR] SDC:sdc 701 abnormal status: RespErr SD:***** Try sdio ***** [ERR] SDC:__mci_irq_handler,924 raw_int:100 err! [ERR] SDC:SDC err, cmd 5, RTO [ERR] SDC:sdc 701 abnormal status: RespErr SD:***** Try sd ***** mmc_send_app_op_cond,89 SD:card ocr: c0ff8000 SD:Card CID number:27504853 SD:card raw cid: SD:card raw csd: m:59159, e:2, dtr:25000000, cl:1461, len:9, cap:60579840 str:1 SD:card raw scr: SD:card raw SD status: HAL_GetHFClock,53 Warning Use fix value 24000000 HAL_GetDevClock,90 Warning Use fix value 192000000 HAL_GetDevClock,90 Warning Use fix value 192000000 SDC:SDC clock=48000000 kHz,src:1, n:0, m:1 SD:card is switched to high speed mode, clk:50000 KHz SD:Set bus width type: 2 SD: ============= card information ============== SD:Card Type : SDHC SD:Card Spec Ver : 5.0 SD:Card RCA : 0x5048 SD:Card OCR : 0x40ff8000 SD: vol_window : 0x00ff8000 SD: to_1v8_acpt : 0 SD: high_capac : 0 SD:Card CSD : SD: speed : 50000 KHz SD: cmd class : 0x5b5 SD: capacity : 29580MB SD:Card CUR_STA : SD: speed_mode : HS: 50 MHz SD: bus_width : 2 SD: speed_class : 10 SD:============================================= SD:***** sd init ok ***** Initial card success mount successully
Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号