cancel
Showing results for 
Search instead for 
Did you mean: 

Interfacing STM32H7 with uSD using SDMMC

DeepakY
Associate II

I referred a youtube video   https://www.youtube.com/watch?v=I9KDN1o6924

So i followed the steps 

/* USER CODE BEGIN 2 */

if(f_mount(&SDFatFS, (TCHAR const*)SDPath, 0) != FR_OK)

{

  Error_Handler();

}

  else

{

     if(f_mkfs((TCHAR const*)SDPath, FM_ANY, 0, rtext, sizeof(rtext)) != FR_OK)

      {

         Error_Handler();

      }

     else

       { //Open file for writing (Create)

          if(f_open(&SDFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)

           {

           Error_Handler();

           }

           else { //Write to the text file

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

                   if((byteswritten == 0) || (res != FR_OK))

                     {

                      Error_Handler();

                     }

                   else { f_close(&SDFile); } } } } f_mount(&SDFatFS, (TCHAR const*)NULL, 0);

 /* USER CODE END 2 */

In this code its unable to execute from f_mkfs

But its not showing any error during execution and i am also not understanding what is the error 

FYI: I determined it was not executing from that part by using transmit function 

 

7 REPLIES 7
AScha.3
Chief III

Did you verify, that you can READ without error or at all ?

Its very bad idea, to format (mkfs) on a device, you dont know , working or making nonsense on the sd-card.

So first try to read (an existing file) on card, then go on.

(Format is never needed, except you destroyed existing file system on card. )

If you feel a post has answered your question, please click "Accept as Solution".

I did not check for READ. i will see it

I know about mkfs, i want to format sdcard then write on it

 

All new sd-cards are formatted , so you just might do it worse. :)

If you feel a post has answered your question, please click "Accept as Solution".
DeepakY
Associate II

@AScha.3  I tried it is giving me FR_NOT_READY  and i have verified there no error while mounting (f_mount) and also sdcard is working normally when i connect it to laptop. 

I think there something wrong with initialization , i am unable to figure what's the problem.

You have to mount NOW , to see, its working - or not. (-> hardware problem ) 

 f_mount(&SDfs, (TCHAR const*)SDPath, 1);			// SD card mount, 1 = now!
If you feel a post has answered your question, please click "Accept as Solution".

Hey everything worked out, actually i had to first turn on the board then insert uSD and reset board.  If i turn on the board with uSD inserted it will not work.

So you are close...

Should work also on power up, so maybe..

Tip: insert a hal_delay , just 50 ms or so, before init card or any access. Many cards need some ms time before ready.

If you feel a post has answered your question, please click "Accept as Solution".