cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX, FatFS and SDIO?

antonius
Senior
Posted on February 20, 2017 at 22:57

Everyone,

How can I use cubeMX for SDcard ? I have generated for MDK but :

this function doesn't work , from UM1721

User manual

Developing Applications on STM32Cube with FatFs page 21.

:

uint32_t wbytes; /* File write counts */

uint8_t wtext[] = 'text to write logical disk'; /* File write buffer */

if(FATFS_LinkDriver(&mynewdisk_Driver, mynewdiskPath) == 0)

{

if(f_mount(&mynewdiskFatFs, (TCHAR const*)mynewdiskPath, 0) == FR_OK)

{

if(f_open(&MyFile, 'STM32.TXT', FA_CREATE_ALWAYS | FA_WRITE) == FR_OK)

{

if(f_write(&MyFile, wtext, sizeof(wtext), (void *)&wbytes) == FR_OK);

{

f_close(&MyFile);

}

}

}

}

FATFS_UnLinkDriver(mynewdiskPath);

This variable :

&mynewdisk_Driver doesn't exist, which file is related ?

Thank you

54 REPLIES 54
Posted on February 28, 2017 at 01:39

Here you can find an example

https://github.com/nichtgedacht/mini-sys

 

You should really learn to analyze things by your self.

antonius
Senior
Posted on February 28, 2017 at 11:18

Yes I tried analyzing myself, but it seems that STM32CubeMX is not straighfoward, and,

Some question,

1. After I initialized SDIO with SDcard option, is it initialized already ?

2. I saw FATFs init as well on the code ? so if it's already initialized, SD card must be initialized, otherwise FATFs can not be initialized, I got until f_mount but can not do f_open ?

Confusing me...it would be nice if I used SDIO and FatFS in straightforward.

Thanks

antonius
Senior
Posted on February 28, 2017 at 13:11

what's this function for ??

MX_SDIO_SD_Init(); ??

antonius
Senior
Posted on February 28, 2017 at 13:37

I tried to follow the step on UM1718 page 193, but I think it's not working properly.. ??

Does it work at all ? Has it it been tested on Eval board from ST ? or just an abstract and confusing ST end user like me ?

antonius
Senior
Posted on February 28, 2017 at 15:52

I diagnosed until ff.c :

FRESULT f_open (

    FIL* fp,            /* Pointer to the blank file object */

    const TCHAR* path,    /* Pointer to the file name */

    BYTE mode            /* Access mode and file open mode flags */

)

{

    FRESULT res;

    DIR dj;

    BYTE *dir;

    DEFINE_NAMEBUF;

    printf('f_open function Line 2533 ff.c! \n'); ===> stop here for now

#if !_FS_READONLY

    DWORD dw, cl;

#endif
Posted on February 28, 2017 at 17:07

>>I tried to follow the step on UM1718 page 193, but I think it's not working properly.. ??

Top level functionality of FatFs is predicated on the correct functionality of the block read/write layer below. If that can't perform a basic job of returning blocks previously written accurately and repeatedly then anything built on top is going to fail in some form or fashion. The manual describes FatFs usage on a board you aren't using, and is dependent on drivers below to be functioning correctly.

>>Does it work at all ? Has it it been tested on Eval board from ST ? or just an abstract and confusing ST end user like me ?

You are wasting your time debugging the FatFs level, this isn't the root of your problem, and doesn't have any chronic bugs. The confusion is mostly of your own making, validate the SDIO layer FIRST, the clocking and connectivity is important, but it is CRITICAL that blocks are read/written correctly, to the correct spot on the media, and with 100% reliability. It is like delivering mail, if you keep delivering to the wrong houses in the wrong streets, you are going to get fired. Or a taxi driver who always gets lost and has no sense of direction.

Do you have an ST EVAL board?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
antonius
Senior
Posted on February 28, 2017 at 22:36

If this board doesn't work, it will not working with my old code for SDIO and USB mass storage,

It's working now with 16GB SDcard and USB as mass storage I can read and write file correctly...

I don't understand at all, probably I put a wrong speed for SDIO ?? any clues ? really confusing me..

Posted on February 28, 2017 at 22:31

1.I'm currently using STM32F103VET6 and it's my own board, so I need to trace the SDIO timing and connection ?

Any ideas how ?

I have USART1 as diagnostic

2. I have STM32F4 discovery and STM32F429 discovery board, will they help ? but I wanna make it work on STM32F103, because I have connected SDCARD module on it and tested with old STM32F103 library and it worked ok.

Making me confused, it's working with old code but not working with STM32CubeMX ??

Posted on February 28, 2017 at 22:38

0690X00000603hWQAQ.jpg

Probably I put this clock too fast ? 0 = 24 MHz ??

Posted on February 28, 2017 at 22:40

This is from my Old code :

♯ define SDIO_TRANSFER_CLK_DIV            ((uint8_t)0x3)

♯ define SD_DETECT_PIN                    GPIO_Pin_14                 /* PB.14 */

♯ define SD_DETECT_GPIO_PORT              GPIOB                       /* GPIOB */

♯ define SD_DETECT_GPIO_CLK               RCC_APB2Periph_GPIOB

/**

  * @brief  SDIO Intialization Frequency (400KHz max)

  */

♯ define SDIO_INIT_CLK_DIV                ((uint8_t)0xB2)

♯ define SDIO_FIFO_ADDRESS                ((uint32_t)0x40018080)

Is there anything different with STM32CubeMX, where can I find this setting on STM32CubeMX generated code ? thanks Clive..