cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX : Accessing Both SDCards with SDMMC1 , SDMMC2 Simultaneously

Karan 123
Senior
Posted on July 10, 2018 at 17:29

Hello,

This is continuation of below Topic.

I have

/external-link.jspa?url=http%3A%2F%2Fwww.st.com%2Fen%2Fevaluation-tools%2Fnucleo-f722ze.html

And Trying to access Two microSDCards Simultaneously . One by One (Either SDMMC1 or SDMMC2 is working fine) 

https://community.st.com/0D50X00009XkWKfSAN

 

Below is my STM32Cube Configuration Setting

0690X0000060CGPQA2.png0690X0000060CGZQA2.png0690X0000060CGeQAM.png

Rest all default .

/* USER CODE BEGIN 0 */

FATFS myFATFS;

FIL myFILE, myFILE2 ;

UINT testByte ;

char myRDdata[15] ;

/* USER CODE END 0 */

MX_GPIO_Init();

MX_SDMMC1_SD_Init();

MX_SDMMC2_SD_Init();

MX_FATFS_Init();

void MX_FATFS_Init(void)

{

/*♯♯ FatFS: Link the SD driver ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/

retSD = FATFS_LinkDriver(&SD_Driver, SD_Path);

/* USER CODE BEGIN Init */

/* additional user code for init */

/* USER CODE END Init */

}

/* USER CODE BEGIN 2 */

if(f_mount(&myFATFS,SD_Path,0) == FR_OK)

{

char mypath[] = {''0:OneDrive.txt\0''} ;

f_open(&myFILE,mypath , FA_WRITE | FA_CREATE_ALWAYS) ;

char mydata[] = {''SD Card 1 Testing \0''} ;

f_write(&myFILE, mydata , sizeof(mydata),&testByte ) ;

f_close(&myFILE) ;

}

if(f_mount(&myFATFS,SD_Path, 1) == FR_OK)

{

char mypath2[] =

{''1:SecondDrive.txt\0''} ;

f_open(&myFILE2,mypath2 , FA_WRITE | FA_CREATE_ALWAYS) ;

char mydata2[] = {''SD Card 2 Testing \ \0''} ;

f_write(&myFILE2, mydata2 , sizeof(mydata2),&testByte ) ;

f_close(&myFILE2) ;

}

With above code I can only access one microSD Card Only. 

I am not able to access both micro SDCards simultaneously . By Added Drive number .

Please help me to resolve this ..

Thanks In advance .

--

Karan

null
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on July 10, 2018 at 20:32

Pretty sure that's not how you mount two drives,

STM32Cube_FW_F4_V1.16.0\Projects\STM32446E_EVAL\Applications\FatFs\FatFs_MultiDrives\Src\main.c

FATFS RAMFatFs, SDFatFs;    /* File system objects logical drives */

FIL RAMFile, SDFile;        /* File objects */

char RAMpath[4], SDpath[4]; /* RAM disk and SD card logical drives paths */

...

  /*##-1- Link the disk I/O drivers ##########################################*/

  if((FATFS_LinkDriver(&SDRAMDISK_Driver, RAMpath) == 0) && (FATFS_LinkDriver(&SD_Driver, SDpath) == 0))

  {

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

    res1 = f_mount(&RAMFatFs, (TCHAR const*)RAMpath, 0);

    res2 = f_mount(&SDFatFs, (TCHAR const*)SDpath, 0);

    if((res1 != FR_OK) || (res2 != FR_OK))

    {

      /* FatFs Initialization Error */

      Error_Handler();

    }

...

        /*##-4- Create and Open new text file objects with write access ######*/

        res1 = f_open(&RAMFile, '0:STM32.TXT', FA_CREATE_ALWAYS | FA_WRITE);

        res2 = f_open(&SDFile, '1:STM32.TXT', FA_CREATE_ALWAYS | FA_WRITE);

        if((res1 != FR_OK) || (res2 != FR_OK))

        {

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

          Error_Handler();

        }

...

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

View solution in original post

6 REPLIES 6
Posted on July 10, 2018 at 20:32

Pretty sure that's not how you mount two drives,

STM32Cube_FW_F4_V1.16.0\Projects\STM32446E_EVAL\Applications\FatFs\FatFs_MultiDrives\Src\main.c

FATFS RAMFatFs, SDFatFs;    /* File system objects logical drives */

FIL RAMFile, SDFile;        /* File objects */

char RAMpath[4], SDpath[4]; /* RAM disk and SD card logical drives paths */

...

  /*##-1- Link the disk I/O drivers ##########################################*/

  if((FATFS_LinkDriver(&SDRAMDISK_Driver, RAMpath) == 0) && (FATFS_LinkDriver(&SD_Driver, SDpath) == 0))

  {

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

    res1 = f_mount(&RAMFatFs, (TCHAR const*)RAMpath, 0);

    res2 = f_mount(&SDFatFs, (TCHAR const*)SDpath, 0);

    if((res1 != FR_OK) || (res2 != FR_OK))

    {

      /* FatFs Initialization Error */

      Error_Handler();

    }

...

        /*##-4- Create and Open new text file objects with write access ######*/

        res1 = f_open(&RAMFile, '0:STM32.TXT', FA_CREATE_ALWAYS | FA_WRITE);

        res2 = f_open(&SDFile, '1:STM32.TXT', FA_CREATE_ALWAYS | FA_WRITE);

        if((res1 != FR_OK) || (res2 != FR_OK))

        {

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

          Error_Handler();

        }

...

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Karan 123
Senior
Posted on July 11, 2018 at 06:45

Thanks for update...

'if((FATFS_LinkDriver(&SDRAMDISK_Driver, RAMpath) == 0) && (FATFS_LinkDriver(&SD_Driver, SDpath) == 0))'

But In my case   in 

sd_diskio.h

Only 

extern Diskio_drvTypeDef  SD_Driver;

How single instance (

SD_Driver) will handle both SDMMC(s) cards. ? 

Please update.

Thanks Again..

--

Karan

Posted on July 11, 2018 at 08:22

>>

Please update

Perhaps you can dig deeper into all the available examples and find something you can just drop in. It would probably take me a hour or two to conjure something up, if you want to pick up the billable hours?

As far as I'm aware the 'XXXpath' variable provides instance specific data for ST's link driver mechanism. The DISKIO layer from FatFs (Chan) does provide it's own way to instantiate multiple drives. As I recall the STM32F779-EVAL supports multiple cards.

Like I said, use your favorite File Manager and trawl the examples, or review the mechanics of the LinkDriver

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Karan 123
Senior
Posted on July 11, 2018 at 13:31

Thanks for update... Again...

I have dig in to below code

...\en.stm32cubef7\STM32Cube_FW_F7_V1.8.0\Projects\STM32F769I_EVAL\Applications\FatFs\FatFs_MultiDrives\MDK-ARM and find  'sdram_diskio.h' and 'sd_diskio.h'

and found different xxx_Driver

const Diskio_drvTypeDef SDRAMDISK_Driver =

{

SDRAMDISK_initialize,

SDRAMDISK_status,

SDRAMDISK_read,

#if _USE_WRITE

SDRAMDISK_write,

#endif /* _USE_WRITE == 1 */

#if _USE_IOCTL == 1

SDRAMDISK_ioctl,

#endif /* _USE_IOCTL == 1 */

};

const Diskio_drvTypeDef SD_Driver =

{

SD_initialize,

SD_status,

SD_read,

#if _USE_WRITE == 1

SD_write,

#endif /* _USE_WRITE == 1 */

#if _USE_IOCTL == 1

SD_ioctl,

#endif /* _USE_IOCTL == 1 */

};

>> As far as I'm aware the 'XXXpath' variable provides instance specific data for ST's link driver mechanism. The DISKIO layer from FatFs (Chan) does provide it's own way to instantiate multiple drives. As I recall the STM32F779-EVAL supports multiple cards.

I have tried below :

/* USER CODE BEGIN Variables */

FATFS        SDCardFatFs_1, SDCardFatFs_2; /* File system objects logical drives */

FIL              SDCardFile_1, SDCardFile_2; /* File objects */

FRESULT ReturnSDCard_1 , ReturnSDCard_2; /* Return value for SD */

char SDCardPath_1[4], SDCardPath_2[4]; /* SD Card 1 logical and SD card 2 logical drives paths */

uint32_t byteswritten1, byteswritten2; /* File write counts */

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

/* USER CODE END Variables */

/* ## FatFS: Link the SD driver ########################### */

// Link First micrSD Card

if((FATFS_LinkDriver(&SD_Driver, SDCardPath_1) == 0) && FATFS_LinkDriver(&SD_Driver, SDCardPath_2) == 0)

{

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

ReturnSDCard_1 = f_mount(&SDCardFatFs_1, (TCHAR const*)SDCardPath_1, 0);

ReturnSDCard_2 = f_mount(&SDCardFatFs_2, (TCHAR const*)SDCardPath_2, 0);

if(( ReturnSDCard_1 != FR_OK))

{

/* FatFs Initialization Error */

Error_Handler();

}

if(( ReturnSDCard_2 != FR_OK))

{

/* FatFs Initialization Error */

Error_Handler();

}

ReturnSDCard_1 = f_open(&SDCardFile_1, '0:D332.TXT', FA_CREATE_ALWAYS | FA_WRITE);

ReturnSDCard_2 = f_open(&SDCardFile_2, '1:SD32.TXT', FA_CREATE_ALWAYS | FA_WRITE);

if(( ReturnSDCard_1 != FR_OK))

{

/* FatFs Initialization Error */

Error_Handler();

}

if(( ReturnSDCard_2 != FR_OK))

{

/* FatFs Initialization Error */

Error_Handler();

}

/*##-5- Write data to the text files ###############################*/

ReturnSDCard_1 = f_write(&SDCardFile_1, wtext, sizeof(wtext), (void *)&byteswritten1);

ReturnSDCard_1 = f_write(&SDCardFile_2, wtext, sizeof(wtext), (void *)&byteswritten2);

/*##-6- Close the open text files ################################*/

f_close(&SDCardFile_1);

f_close(&SDCardFile_2);

Problem still persist... Please Update Again...

--

Karan

Posted on July 11, 2018 at 15:30

Would take several hours to create a working example, I'm open to reasonable offers.

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

Thanks .. Worked...

I have created new &SD_Driver_2 in diskio.c Now Both SDCard working fine ..

const Diskio_drvTypeDef SD_Driver_2 =

{

SD_initialize_2,

SD_status_2,

SD_read_2,

#if _USE_WRITE == 1

SD_write_2,

#endif /* _USE_WRITE == 1 */

#if _USE_IOCTL == 1

SD_ioctl_2,

#endif /* _USE_IOCTL == 1 */

};

Thanks again

--

Karan