Skip to main content
JC Lebreton
Associate III
February 21, 2018
Question

FatFs - SDMMC - STM32H7

  • February 21, 2018
  • 15 replies
  • 6018 views
Posted on February 21, 2018 at 16:20

Hi,

I have the problem that many of us have as seen on the number of post on the forum. Unfortunatly for me nobody have the same issue as i have!

Let s point out first what i'm trying to do.

I'm on a small project of data gathering. Of course I need to store the data somewhere and the card won't have acces to LoraWan or any similar network. So the only idea i got was using an USB stick or an SD card. I came with the idea to use an SD card for its small size. If some of you think it's easier to implement USB stick we can explore this option.

 

OK. this settled, let me explain what i did at the moment.

I try the code given by ST and adafruit, where they are using the SPI connection with the SD card. But i don't really like this technique.

So i try with the Cube to implement the SDMMC (1bit bus at the moment) and FatFs interface for an SD card. (configuration of the Cube on attachement).

I then create a projet on eclipse and try so stuff.

I use the function BSP_SD_Init(), wich result in a succes

I then try functions lie : f_mount(), 

FATFS_LinkDriver(&SD_Driver, SDPath),

f_mount()... But none of them seems to work!

I'm totaly lost... 

Do I have to Initialise more things? 

Do I have to complete .c files? like sd_diskio.c ?

well, if some of you have some clue or some working sample code it will be awesome.

Best regards,

JC

    This topic has been closed for replies.

    15 replies

    Tesla DeLorean
    Guru
    February 21, 2018
    Posted on February 21, 2018 at 17:27

    My approach has been to port the HAL code from the STM32H743xI-EVAL board to the NUCLEO-H743ZI, creating a stm32h7xx_nucleo_sd.c

    0690X0000060421QAA.jpg0690X00000604POQAY.jpg
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    JC Lebreton
    Associate III
    February 21, 2018
    Posted on February 21, 2018 at 17:53

    So far, the pinout i'm using is OK. 

    I can say that because my SD card is answering me.

    The command BSP_SD_IsDetected() provided by the cube is working 

    it returns me 1 if there is an SD card and 0 if there is none.

    Second point that can confirm what i'm saying is that f_mount(&SDFatFS, (TCHAR const*)SDPath, 0) answer me 'FR_OK'

    I dig up a few an come to f_open(&SDFile, 'STM32.TXT', FA_CREATE_ALWAYS | FA_WRITE). but this one is not working. Indeed, i code the answer

    FR_NOT_ENABLED

    Note : &SDFile is declared like so : 'FIL SDFile'

    And ... well  i have no clue at the moment why it's not working ...

    Tesla DeLorean
    Guru
    February 21, 2018
    Posted on February 21, 2018 at 18:17

    Is your FatFs built as read-only? 

    ffconf.h

    ...

    ♯ define _FS_READONLY 0

    /* This option switches read-only configuration. (0:Read/Write or 1:Read-only)

    / Read-only configuration removes writing API functions, f_write(), f_sync(),

    / f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree()

    / and optional writing functions as well. */

    ...

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    JC Lebreton
    Associate III
    February 22, 2018
    Posted on February 22, 2018 at 09:33

    two things in one!

    First of all, it works like a charm! (some issue about permissions but that's not a big of a deal now!)

    I remove as mentionned before the '0ohm' resistor on pin SB116 and SB117 

    and ... well it makes things work! 

    if also changed a bit two functions :
    • FATFS_LinkDriver(&SD_Driver,(TCHAR const*)SDPath)

       ->

      FATFS_LinkDriver(&SD_Driver,'')
    • f_mount(&SDFatFS, (TCHAR const*)SDPath, 0) 

      ->f_mount(&SDFatFS, '', 0)

    I keep things simple here to start understanding how things work!

    thank you Clive for the help you provide me!

    And for the others who would like to make the same stuff work, here is an easly understandable code!
    JC Lebreton
    Associate III
    February 22, 2018
    Posted on February 22, 2018 at 09:35

    Add after all the MX_XX_ init()

    /* USER CODE BEGIN 2 */

     FRESULT res;

    BSP_SD_Init();

    if(FATFS_LinkDriver(&SD_Driver,'')!=0)

    {

    }

    if(BSP_SD_IsDetected())

    {

    if(f_mount(&SDFatFS, '', 0)==FR_OK)

    {

    res = f_open(&SDFile, 'STM32.TXT', FA_CREATE_NEW | FA_WRITE | FA_READ);

    datasend(res);

    if(res == FR_OK)

    {

    HAL_GPIO_WritePin(GPIOB,GPIO_PIN_7,GPIO_PIN_SET);

    res = f_write(&SDFile, wtext, sizeof(wtext), (void *)&byteswritten);

    datasend(res);

    if((byteswritten>0)&&(res == FR_OK))

    {

    f_close(&SDFile);

    }

    }

    else

    {

    HAL_GPIO_WritePin(GPIOB,GPIO_PIN_14,GPIO_PIN_SET);

    }

    }

    }

    /* USER CODE END 2 */

    /* Infinite loop */

    /* USER CODE BEGIN WHILE */

    while (1)

    {

    }
    asdfasdf
    Associate III
    April 21, 2018
    Posted on April 21, 2018 at 15:07

    Hi JC!

    Would you be able to share your test-project for the Nucleo here? I'm also struggling with the H7 and SD-card, and am starting to suspect I'm somehow doing something completely stupid and a working demo-project would be helpful!

    Thanks a lot,

    Michael