[NUCLEO-L476RG] Configure SDMMC peripheral

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
vinz-uts
Posts: 22
Joined: Fri Sep 10, 2021 9:22 am

[NUCLEO-L476RG] Configure SDMMC peripheral

Post by vinz-uts » Fri Sep 10, 2021 11:11 am

Hi All,
I'm using a STM32 NUCELO-L476RG board with an external SDCARD shield that use the SDMMC peripherl (only CMD, CLK and D0 pins). I've tested the shield with STM32CubeIDE and C programming and it works. Now I've cloned micropython from git repo and I've compiled it as it's write in the ports/stm32/readme.md file, and all works fine (REPL, import modules, etc.). I'm trying to enable SDMMC peripheral that it's wired to the shield, but I don't understand how I can configure it, I've tried to add the line

Code: Select all

#define MICROPY_HW_ENABLE_SDCARD (1)
#define MICROPY_HW_SDCARD_SDMMC (1)

#define MICROPY_HW_SDMMC_D0                 (pin_C8)
#define MICROPY_HW_SDMMC_D1                 (pin_C9)
#define MICROPY_HW_SDMMC_D2                 (pin_C10)
#define MICROPY_HW_SDMMC_D3                 (pin_C11)
#define MICROPY_HW_SDMMC_CK                 (pin_C12)
#define MICROPY_HW_SDMMC_CMD                (pin_D2)
in the mpconfigboard.h in boards/NUCLEO_L476RG folder, but when the board runs, it waits long time (I think it tries to mount the SD Card) and the message MPY: can't mount SD card is shown before starting the REPL:

Code: Select all

MPY: sync filesystems
MPY: soft reboot
MPY: can't mount SD card
MicroPython v1.17-8-gbbbdef4cc-dirty on 2021-09-09; NUCLEO-L476RG with STM32L476RG
Type "help()" for more information.
>>>
I get also a OSError: [Errno 19] ENODEV if I try to mount the SD using os module and pyb.SDCard class. Could someone help me to understand how I've to correctly configure the SDMMC peripheral? Thanks all for the support...

dragon12
Posts: 3
Joined: Fri Sep 10, 2021 5:21 pm

Re: [NUCLEO-L476RG] Configure SDMMC peripheral

Post by dragon12 » Fri Sep 10, 2021 5:42 pm

Did you try to mound SD card in SPI mode? I'm trying right now and I'm getting OSError: timeout waiting for response

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: [NUCLEO-L476RG] Configure SDMMC peripheral

Post by Roberthh » Fri Sep 10, 2021 6:28 pm

Is the SD card properly formatted with a single FAT partition?

vinz-uts
Posts: 22
Joined: Fri Sep 10, 2021 9:22 am

Re: [NUCLEO-L476RG] Configure SDMMC peripheral

Post by vinz-uts » Mon Sep 13, 2021 8:41 am

dragon12 wrote:
Fri Sep 10, 2021 5:42 pm
Did you try to mound SD card in SPI mode? I'm trying right now and I'm getting OSError: timeout waiting for response
No I didn't try to use SPI mode. To do this I've to use the pyb.SPI class, right?

vinz-uts
Posts: 22
Joined: Fri Sep 10, 2021 9:22 am

Re: [NUCLEO-L476RG] Configure SDMMC peripheral

Post by vinz-uts » Mon Sep 13, 2021 8:42 am

Roberthh wrote:
Fri Sep 10, 2021 6:28 pm
Is the SD card properly formatted with a single FAT partition?
Yes, the SD is 8GB and has one FAT32 partition. I check this from my OS. Thanks for your suggest!

vinz-uts
Posts: 22
Joined: Fri Sep 10, 2021 9:22 am

Re: [NUCLEO-L476RG] Configure SDMMC peripheral

Post by vinz-uts » Thu Sep 16, 2021 9:35 am

I try to understand where is the problem but I'm not lucky... Another question is: why on the official documentation on https://docs.micropython.org/en/v1.17/l ... DCard.html the SDCard class is in machine but when I import machine module no class with this name is found? I'm using MicroPython v1.17-8-gbbbdef4cc-dirty on 2021-09-16...I don't understand if the docs is reliable, I found a lot of inconsistencies...
Thanks for support.

Post Reply