【发布时间】:2022-08-18 22:29:05
【问题描述】:
概述
我正在使用STM32F407ZGT6,我目前正在尝试使用FATFS library 将 SD 卡 (MicroSD 32GB HCI and 256GB XCI picture) 安装到板上。由于项目要求,我不想使用 STMCubeMX HAL,所以我将使用裸机。为了处理低级 I/O,我使用colosimo\'s 代码 (diskio_stm32f4xx.c)。
我知道的
编辑:我发现电路板实际上没有合适的上拉电阻。因此,我正在使用 SD 适配器测试Clive Turvey 建议的(47K 欧姆)和what was supposed to be on my board(10K 欧姆)(我已经测试了带有和不带有蓝色元素的电路):
引脚 PC8 到 PC12 和 PD2 设置为上拉模式并作为 SDIO 用于备用功能。在我之前对这个问题的编辑中,我实际上在程序tested for the presence of an SD 的地方被抓住了,因为我的卡检测器不起作用。
问题
编辑:使用我的新设置,f_mount 现在返回FR_NOT_READY /* (3) The physical drive cannot work */,因为\"cmd 1 failed\"。每次在send_cmd 上发送命令,都不会产生响应,保持SDIO->RESP = 0x0 并在超过100ms 时中断:
SDIO->CMD = cmd;
start = msTicks; //<<-----------SDIO->STA CTIMEOUT already set!!!
while (1) {
if (elapsed(start) > 100){
break; //<<-----------always breaks here
}
s = SDIO->STA;
if (resp_type == RESP_NONE)
return s & SDIO_STA_CMDSENT ? 1 : 0;
else {
/* check if timeout */
if (s & SDIO_STA_DTIMEOUT) {
err(\"%s timeout idx=%d arg=%08x\\n\", __func__, idx, (uint)arg); /*!!*/
return 0;
}
/* check if crc err */
if (s & SDIO_STA_DCRCFAIL) {
if (idx == 1 || idx == 12 || idx == 41)
break;
err(\"%s crcfail idx=%d arg=%08x\\n\", __func__, idx, (uint)arg); /*!!*/
return 0;
}
if (s & SDIO_STA_CMDREND)
break; //<<-----------never reaches here
}
}
buf[0] = SDIO->RESP1;
if (resp_type == RESP_LONG) {
buf[1] = SDIO->RESP2;
buf[2] = SDIO->RESP3;
buf[3] = SDIO->RESP4;
}
return 1;
奇怪的是,除了SDIO->STA CTIMEOUT 之外,没有设置任何标志,这发生在SDIO->CMD = cmd 之后。作为参考,这些是在diskio_initialize 上发送的 cmd 命令:
| Cart type test | cmd_param | SDIO->CMD |
|---|---|---|
| sdc v2 | 8 | 1096 (0b100 01 001000) |
| ACMD test | 55 | 1143 (0b100 01 110111) |
| MMC | 1 | 1089 (0b100 01 000001) |
两张卡都会发生同样的事情。在这一点上,我不确定这是硬件问题还是软件问题。
还有其他想法吗?
标签: c embedded stm32 sd-card spi