简体   繁体   English

STM32 SD 安装返回错误与 SDIO

[英]STM32 SD mounting returns error with SDIO

Overview概述

I'm using a STM32F407ZGT6 and I'm currently trying to mount SD cards (MicroSD 32GB HCI and 256GB XCI picture ) to the board using the FATFS library bare-metal.我正在使用STM32F407ZGT6 ,目前正在尝试使用 FATFS裸机将 SD 卡(MicroSD 32GB HCI 和 256GB XCI 图片)安装到板上。 To handle low level I/O, I'm using colosimo's code ( diskio_stm32f4xx.c ).为了处理低级 I/O,我使用了 colosimo 的代码( diskio_stm32f4xx.c )。

Setup设置

Edit: My initialization clock is 400kHz and then it's set to 4MHz.编辑:我的初始化时钟是 400kHz,然后设置为 4MHz。 Below is my circuit via SD adapter with 10K ohms:下面是我通过 10K 欧姆 SD 适配器的电路: Micro SD转SD适配器电路

The problem问题

Edit: On my previous edit, I noticed I wasn't setting SDIO_DCTRL_SDIOEN nor SDIO_DCTRL_RWSTART , therefore STBITERR was being raised.编辑:在我之前的编辑中,我注意到我没有设置SDIO_DCTRL_SDIOEN也没有设置SDIO_DCTRL_RWSTART ,因此引发了STBITERR Unfortunately, I currently can't enable the SDIO_STA_RXDAVL bit on SDIO->STA which indicates there is no data avaialbe in the FIFO, as indicated in the comments below:不幸的是,我目前无法启用SDIO->STA上的SDIO_STA_RXDAVL位,这表明 FIFO 中没有可用的数据,如下面的评论所示:

cmd = (count > 1) ? 18 : 17;
t = msTicks;
rd = 0;

SDIO->DCTRL = ((0b1001 << 4) | SDIO_DCTRL_DTDIR);
SDIO->DLEN = (512 * count);
SDIO->DTIMER = (400000);

sta = 0;
if (!send_cmd(cmd, sector, RESP_SHORT, &resp) || (resp & 0xc0580000))   /*!MOD REG?*/
    return RES_ERROR;
SDIO->ICR = (0xFF);
SDIO->DCTRL |= (SDIO_DCTRL_SDIOEN   | //<<---Newly set bits
                SDIO_DCTRL_RWSTART  |
                SDIO_DCTRL_DTDIR    |
                SDIO_DCTRL_DTEN
               );

while (elapsed(t) < 1000){

    sta = SDIO->STA;

    if (sta & (SDIO_STA_DTIMEOUT | SDIO_STA_RXOVERR | SDIO_STA_STBITERR)) {
        err("%s SDIO_STA: 0x%08X\n", __func__, (uint)sta);
        break;
    }

    if (sta & SDIO_STA_RXFIFOE)
        continue;

    if (rd == 0 && !(sta & SDIO_STA_RXDAVL))
        continue;      //<<---No data available, so can't get to FIFO

    data = SDIO->FIFO; //<<---Never gets here

    buf[rd++] = data;
    buf[rd++] = data >> 8;
    buf[rd++] = data >> 16;
    buf[rd++] = data >> 24;


    if (rd == 512 * count)
        break;
}

if (rd < 512 * count || cmd == 18)
    send_cmd(12, 0, RESP_SHORT, &resp);

return SDIO->DCOUNT ? RES_ERROR : RES_OK;

What am I forgetting?我忘记了什么? How can I make data available?如何使数据可用?

Not an absolute answer, but some issues/suggestions ...不是一个绝对的答案,而是一些问题/建议......

It helps to separate concerns:它有助于分离关注点:

  1. Does the raw diskio package talk to the disk device?原始 diskio 包是否与磁盘设备通信?
  2. Most FS software on development systems (that presumably create the initial FS image) want a partition table (eg MBR or GPT).开发系统上的大多数 FS 软件(可能会创建初始 FS 映像)需要一个分区表(例如 MBR 或 GPT)。 Do you need one?你需要一个吗?
  3. Does the FS library talk to the disk library correctly? FS 库是否与磁盘库正确通信?
  4. What FATFS are you using (eg FAT16 , FAT32 )?您使用的是什么 FATFS(例如FAT16FAT32 )?
  5. What sort of debug capability do you have (eg gdb or other STM32 specific debugger)?你有什么样的调试能力(例如gdb或其他 STM32 特定的调试器)?

So, I'd write a diagnostic that exercises the disk on the STM32 without regard to whether there is a FS on it or not.所以,我会写一个诊断程序,在 STM32 上运行磁盘,而不考虑上面是否有 FS。 That is, write some data to the [raw] disk.也就是说,将一些数据写入 [raw] 磁盘。 Can you read it back correctly?你能正确地读回来吗? Don't bother with the FS layer until you're convinced that the disk layer accesses the device correctly.在您确信磁盘层可以正确访问设备之前,不要打扰 FS 层。

Then, when you're convinced the raw disk I/O works, answer the question whether you need a partition table.然后,当您确信原始磁盘 I/O 可以正常工作时,请回答您是否需要分区表的问题。

It's not absolutely necessary.不是绝对必要的。 But, it allows the disk to [more easily] be plugged into a development system to create the FS, put some files on it, and later verify what the STM32 has done to the disk.但是,它允许磁盘[更容易]插入开发系统以创建 FS,在其上放置一些文件,然后验证 STM32 对磁盘做了什么。

So, using a development system, create the FS image.因此,使用开发系统创建 FS 映像。 Put the SD card in the target (STM32) system.将 SD 卡放入目标(STM32)系统中。 With a known good FS image, then that should help you determine whether the FS layer is talking to the disk.使用已知良好的 FS 映像,这应该可以帮助您确定 FS 层是否正在与磁盘通信。

The FS layer should be seeing the valid FS image. FS 层应该看到有效的 FS 映像。 If not, either it is not connected to the disk I/O layer correctly or it perceives the FS image to be bad.如果不是,要么它没有正确连接到磁盘 I/O 层,要么它认为 FS 映像是坏的。

On the development system, you should be able to get a hex dump of the image.在开发系统上,您应该能够获得图像的十六进制转储。

Presumably (hopefully) you can get the disk I/O layer to dump the raw data to the UART/screen in hex.大概(希望)您可以让磁盘 I/O 层以十六进制将原始数据转储到 UART/屏幕。

Again, it should be possible to get the FS layer to do the same.同样,应该可以让 FS 层做同样的事情。 The data should match at all layers of the process.数据应该在流程的所有层都匹配。

I finally got it fixed.我终于把它修好了。 My problem was with the hardware, Although I cannot put a finger on what was the problem.我的问题出在硬件上,尽管我无法确定问题所在。 I'll guess that the SD adapter was broken or had a weird pinout, Also, having only the internal GPIOs pull-ups ( 30k to 50k Ohms ) was enough and I didn't need the physical resistors I was adding to the circuit.我猜 SD 适配器坏了或有一个奇怪的引脚排列,此外,只有内部 GPIO 上拉( 30k 到 50k 欧姆)就足够了,我不需要添加到电路中的物理电阻。

Moreover, my breaking points were generating weird results since the SD is a microprocessor itself.此外,由于 SD 本身就是微处理器,因此我的断点产生了奇怪的结果。 Therefore, every breakpoint would influence clocks and couters from the SD and the were messing up my debugging.因此,每个断点都会影响 SD 中的时钟和计算机,并且会扰乱我的调试。 Once I got them out of the way, the response came out positive using the embedded SD slot that came with my board.一旦我把它们弄走,使用我的主板附带的嵌入式 SD 插槽得到的响应是积极的。

Another problem that I found was that only the FAT32 card was accepted.我发现的另一个问题是只接受 FAT32 卡。 ExFAT cards did not get recognized, always returning FR_NO_FILESYSTEM . ExFAT 卡没有被识别,总是返回FR_NO_FILESYSTEM Below the output of all my testing conditions:下面是我所有测试条件的output:

Card Type卡的种类 Circuit Type电路类型 GPIO_PUPDR Response回复
FAT32 FAT32 Embedded Circuit嵌入式电路 Pull-Up拉起 FR_OK
FAT32 FAT32 Embedded Circuit嵌入式电路 *Pull-No *拉-不 FR_NOT_READY
FAT32 FAT32 *SD Adapter Circuit *SD适配器电路 Any任何 FR_DISK_ERR
*ExFAT *ExFAT Embedded Circuit嵌入式电路 Any任何 FR_NO_FILESYSTEM

* The main factors that caused errors on each combination * 导致每个组合出现错误的主要因素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM