cancel
Showing results for 
Search instead for 
Did you mean: 

call to fmount fails in stm32f779I eval board

yalamanda dosakayala
Associate II
Posted on January 04, 2018 at 07:30

Hi STM Community, I am working on one project , for reading a file from sd card and  writing it back, And I am using STM32F779I Eval board for it. I am using STM CUBE Mx for generating the code for fatFs and SD card. I am using System workbench for STM32(Ac6) IDE for it. I referred some sample examples. So I made  code for like below. But it is always failing at call  f_mkfs() goes to error_handler. When I debug into f_mkfs it is failing at disk_write function(

if (disk_write(pdrv, buf, b_vol, 1) != RES_OK) return FR_DISK_ERR;    /* Write it to the VBR sector */)

FRESULT res;                                          /* FatFs function common result code */

    uint32_t byteswritten, bytesread;                     /* File write/read counts */

    uint8_t wtext[] = 'This is STM32 working with FatFs'; /* File write buffer */

    uint8_t rtext[100];                                   /* File read buffer */

    /*♯♯-1- Link the micro SD disk I/O driver ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/

    if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0)

    {

        if(BSP_SD_Init() == MSD_OK)

        {

      /*♯♯-2- Register the file system object to the FatFs module ♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/

      if(f_mount(&SDFatFs, SDPath, 0) != FR_OK)

      {

        /* FatFs Initialization Error */

        Error_Handler();

      }

      else

      {

//        ♯♯-3- Create a FAT file system (format) on the logical drive ♯♯♯♯♯♯♯♯♯

//         WARNING: Formatting the uSD card will delete all content on the device

        if(f_mkfs(SDPath, FM_ANY, 0, workBuffer, sizeof(workBuffer)) != FR_OK)

        {

//           FatFs Format Error

          Error_Handler();

        }

        else

      {

          /*♯♯-4- Create and Open a new text file object with write access ♯♯♯♯♯*/

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

          {

            /* 'STM32.TXT' file Open for write Error */

            Error_Handler();

          }

         

#fatfs-sdio #sdcard #f_mount-sdcard
1 REPLY 1
Posted on January 05, 2018 at 23:21

You'll likely need to dig into the diskio.c layer to understand why your write is failing.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..