Skip to main content
Visitor II
November 19, 2021
Question

Can we mount the two devices i.e sd card and usb at a same time using FATFS in STM32F429ZI. I want to store the sensor data in SD card and copy that data to USB drive when the usb is detected.

  • November 19, 2021
  • 3 replies
  • 1281 views

i am using STM32F429ZIT6U board does the board support the mounting of SD card and USB at a time 

The main problem is both the devices get detected or get mounted when i use f_mount but the file that is get be stored in SD card is will be get stored in USB and SD card not have any file

void sd_card_write()

{

  FATFS_LinkDriver(&USER_Driver, USERPath);

fresult = f_mount(&sd_fs, (TCHAR const*)USERPath, 1);

if (fresult != FR_OK)

{

HAL_GPIO_WritePin(GPIOG, GPIO_PIN_14, 1);

HAL_GPIO_WritePin(GPIOG, GPIO_PIN_13, 0);

}

else

{

HAL_GPIO_WritePin(GPIOG, GPIO_PIN_13, 1);

HAL_GPIO_WritePin(GPIOG, GPIO_PIN_14, 0);

}

  fresult = f_open(&sd_file, "0:FILE.TXT", FA_OPEN_EXISTING | FA_WRITE| FA_WRITE | FA_OPEN_APPEND);

  sprintf(buffer,"Temperature:%f\n",Temp);

  fresult = f_write(&sd_file, (const void *)buffer, strlen(buffer), &bw);

  f_close(&sd_file);

  clear_buffer();

  FATFS_UnLinkDriver(USERPath);

}

void UsbTest_Write(void)

{

f_open(&sd_file, "0:FILE.TXT", FA_READ);

f_open(&usb_file, "1:FILE1.TXT", FA_OPEN_EXISTING |FA_WRITE | FA_OPEN_APPEND);

f_lseek(&sd_file, 0);

f_read(&sd_file, (void *)buffer1, strlen(buffer1), (void *)&bw1 );

f_write(&usb_file, buffer1, strlen(buffer1), (void *)&bw1);

f_close(&sd_file);

f_close(&usb_file);

}

switch(Appli_state)

   {

   case APPLICATION_IDLE:

   break;

   case APPLICATION_START:

      FATFS_LinkDriver(&USBH_Driver, USBHPath);

   if(f_mount(&usb_fs, (TCHAR const*)USBHPath, 0) == FR_OK)

   {

   HAL_GPIO_WritePin(GPIOG, GPIO_PIN_11, 1);

   }

   break;

   case APPLICATION_READY:

   {

   UsbTest_Write();

   HAL_GPIO_WritePin(GPIOG, GPIO_PIN_12, 1);

   HAL_Delay(5);

   }

   break;

   case APPLICATION_DISCONNECT:

      HAL_GPIO_WritePin(GPIOG, GPIO_PIN_11, 0);

      FATFS_UnLinkDriver(USBHPath);

   break;

   }

    This topic has been closed for replies.

    3 replies

    Graduate II
    November 19, 2021

    That's a chip number, not board​, and technically yes with the right software stack and settings two drive instances can work concurrently.

    Is strlen() appropriate for a string you haven't read yet?​

    Visitor II
    November 19, 2021

    STM32F429I-Disco

    i am using User define fatfs for SD card and Usb Disk for Usb Drive.

    strlen() is correct. same code working fine for individual interfacing.

    Explorer
    January 8, 2025

    i'm using stm32f105rct6 

    i'm also using the User define fatfs for SD card and Usb Disk for Usb Drive
    but sd card is not working only USB is working

    Graduate II
    November 19, 2021

    >>strlen() is correct. same code working fine for individual interfacing.

    I'll defer to your knowledge on the string library..

    You might want to review what errors/status the FatFs library throws, and if the top-level stuff is all in order start instrumenting the DISKIO and ST's dispatch methods.