Skip to main content
Graduate
January 8, 2025
Solved

STM32U5 Nucleo-U5A5ZJ-Q large SD card and 1 bit problem

  • January 8, 2025
  • 5 replies
  • 3320 views

Hi
I'm trying to connect an SD card to my Nucleo U5A5ZJ-Q board using SDMMC peripheral and use it with FatFS library. When I use 1GB card and 4 bit mode, everything works fine. By "works fine" I mean that:

1. it passes this FatFS test: http://elm-chan.org/fsw/ff/res/app4.c

2. it is able to create a working text file.

But there are 2 problems:

1. 1 bit SDMMC mode doesn't work. When I'm trying to use it, the FatFS test fails at an SD card write. After clicking around in STM32CubeIDE debugger I found that there is a CRC error in SD callback being set as status, which then leads to a timeout and test fail. This problem isn't critical, because 4 bit mode seems to work, but it worries me a bit.

2. 16GB and 32GB cards don't work. They get a bit further (to reading), but fail in a simmilar way (SD callback -> CRC error -> timeout -> test fail). I haven't been able to test 2-8GB cards yet. This is more of a problem, because it's getting harder and harder to get such small capacity cards.

The whole project is attached below.

Ideas, anyone? Thanks in advance.
Adam

    This topic has been closed for replies.
    Best answer by AScha.3

    Try to connect the sd-adapter with short wires to the board.

     

    On my tests with a H563-nucleo i had disk-err with about 7cm cables ; using same adapter, but cables about 30mm is working fine. (4-bit mode at full speed, 50MHz card clock)

     

    And set pin speed medium and pullups ON on all lines.

    5 replies

    Super User
    January 8, 2025

    Hi,

    most probably a hardware problem.

    1-bit mode is less difficult, so it should work most times...even when 4-bit not working.

    So search/read here in forum, what i wrote about sd-card problems and what to do.

    ...set pin speed medium, pullups on...etc.

    + i have sd-cards on my H743 audio player and no problem, 2GB or 32 GB .

    awocrfAuthor
    Graduate
    January 8, 2025

    Ok, I'm gonna try these things tomorrow. I find it weird that 4 bit mode is working but 1 bit mode is not. It seems that everyone has the opposite situation.

    awocrfAuthor
    Graduate
    January 10, 2025

    I've tested some uSD cards and here are the results:
    1. 1 bit SDMMC mode isn't working at all. It's hanging at a first write with CRC error.
    2. 4 bit mode does work but only on 1GB and below cards. Anything above 1GB hangs with a CRC error on first read (so after writing).
    All pins exept for CLK are with pullups. All pins set to medium.

    Super User
    January 10, 2025

    So next: how long are your lines cpu/pin -> sd-card/pin ?

    and clk /speed setting for sdmmc ?

    +

    Please dont write or mkfs -never ever- as long , its not working perfect with mount and reading.

    Your just lucky, if cards survive these bad access trials.

    Only mount and read (existing) files , until this works 100% perfect. Then try a write or create file...

    awocrfAuthor
    Graduate
    January 20, 2025

    Sorry for slow reply, I've been quite busy lately.


    My CPU -> uSD lines are 20cm + Nucleo track length + uSD adapter track length. I know that these are long, but:

    I've used multiple clock speeds, fast and slow, both as SD clock and for SDMMC peripheral. Nothing helped.

     

    When using SPI, everything seems to be working. I used test code from this: https://01001000.xyz/2020-08-09-Tutorial-STM32CubeIDE-SD-card/. I wasn't able to solve SDMMC issues. I would like to use it (4 bits is more than 1) but right now I can't and I've ran out of ideas.

     

    My SPI test hardware setup is the same if not counting connecting cables to different Nucleo pins.

    AScha.3Answer
    Super User
    January 21, 2025

    Try to connect the sd-adapter with short wires to the board.

     

    On my tests with a H563-nucleo i had disk-err with about 7cm cables ; using same adapter, but cables about 30mm is working fine. (4-bit mode at full speed, 50MHz card clock)

     

    And set pin speed medium and pullups ON on all lines.

    awocrfAuthor
    Graduate
    January 21, 2025

    All SDMMC pins medium and pullup, 4 bit mode. With 4cm SDMMC cables the uSD card is working at 40MHz. Thank you very much for the suggestion! Was noise causing it to not work with most of the cards?
    But there's still one problem. Why 1 bit mode returns FatFS error 13 (FR_NO_FILESYSTEM)?

    awocrfAuthor
    Graduate
    January 23, 2025

    I've re-run the test from that .xyz website I linked earlier with mount 0 and 1.
    In 4 bit mode both are working.
    In 1 bit mode I get FR_NO_FILESYSTEM in both cases.
    With Chan's test (link in original post) 4 bit mode passes without problems. 1 bit mode fails - CRC error in write callback.

    Super User
    January 24, 2025

    So be glad, 4 bit mode working fine.

    And 1 bit also on read, but problem on write - if your info is correct.

    If you want find the reason for this, you have to find out : is hardware or software the problem.

    Because 4 bit mode working, which is much more problematic regarding the connection, i would look at the software first.

    So you could try to use a more recent version of the fatfs , see on Mr. Chan's downloads . (STM still have 2017 version...8 y old now.)

    AScha3_0-1737706040766.png

    And what you use: with DMA - or not ? Try both.

    awocrfAuthor
    Graduate
    January 24, 2025

    >So be glad, 4 bit mode working fine.

    Yeah, right now I only need 4 bit mode to work. I'm curious as to why 1 bit mode doesn't work, but I don't know if it's worth it for me to find out due to how much time I'm spending on this. Maybe the connections are still too long? But again, thank you very much for your help!

    >And 1 bit also on read, but problem on write - if your info is correct.

    The Chan's test stops on writing. Reading is after that, so it doesn't get there.

    The .xyz website test fails on f_mount with error 13 (FR_NO_FILESYSTEM)

     

    >So you could try to use a more recent version of the fatfs , see on Mr. Chan's downloads . (STM still have 2017 version...8 y old now.)

    I've updated FatFS to 0.15a w/patch 1, still the same.

    >And what you use: with DMA - or not ? Try both.
    I've been using DMA before. Changing BSP_SD_WriteBlocks_DMA to BSP_SD_WriteBlocks doesn't help.

    Super User
    January 24, 2025

    So maybe something coming from your hardware - but what then ? You could try with a really short connect - just to know. And making pin speed lower and higher - any change ?

    btw

    As i said, 1 bit (in my tests also) more easy , to get it running; worked on all cpus, i used: F401, F411, H563, H7A3, H743, H733 .

    H563 here should be similar to your U5 , same series with  M33 core. Just here big problem: sd didnt work at all, because the (generated) init for the sdmmc  set pin speed always hi , with no pullups. Didnt work.

    After i found out , changed it , then - it worked.

     /* USER CODE BEGIN SDMMC1_MspInit 1 */
     GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
     |GPIO_PIN_12;
     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
     GPIO_InitStruct.Pull = GPIO_PULLUP;
     	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
     	GPIO_InitStruct.Alternate = GPIO_AF12_SDMMC1;
     	HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
    
     	GPIO_InitStruct.Pin = GPIO_PIN_2;
     	GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
     	GPIO_InitStruct.Pull = GPIO_PULLUP;
     	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
     GPIO_InitStruct.Alternate = GPIO_AF12_SDMMC1;
     HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
     /* USER CODE END SDMMC1_MspInit 1 */