0

I'm using GD32F105RBT6 and I'm trying to save the text file to FAT32 flash drive. But f_mount() returns FR_NO_FILESYSTEM.

If I use a project that uses only USB host and try to save the file, everything works. In a project with other peripherals (rtc, timers, dma, adc) the function does not work and return FR_NO_FILESYSTEM.

I assume that some interrupts occur while the function is running and cause this error, but even when all interrupts are turned off (except for TIMER2_IRQHandler and USBFS_IRQHandler), the situation does not change. I can't use debug because I'm using a ready-made device board, not a debug board that I can only program.

int usbh_msc_usr_app(void) {
    
    FRESULT res;
    uint8_t WriteTextBuff[] = "Try to write text in";
    uint32_t bytesWritten, bytesToWrite;
    
    // register work area for logical drives
    usb_mdelay(100);
    res = f_mount(&fatfs, "0:/", 1);
    if (res != FR_OK) {
        return 1;
    }
    
    res = f_open(&file, "0:test.TXT", FA_CREATE_ALWAYS | FA_WRITE);
    if (res != FR_OK){
        f_mount(NULL, "0:/", 1);
        return 1;
    }
    
    bytesWritten = 0;
    bytesToWrite = sizeof(WriteTextBuff);
    res = f_write(&file, WriteTextBuff, bytesToWrite, (void*)&bytesWritten); 
    if ( (bytesToWrite != bytesWritten) || (res != FR_OK) ) {
        
    }
    
    usb_mdelay(1000);
    res = f_close(&file);
    if (res != FR_OK) {
        f_mount(NULL, "0:/", 1);
        return 1;
    }
   
    f_mount(NULL, "0:/", 1); 
    return 0;
}

The error appears here: f_mount(...) -> find_volume(...) -> check_fs(...) -> ld_word(fs->win + BS_55AA) != 0xAA55

I am using FatFs R0.13c.

What could be the reason?

Natr
  • 1
  • 1
  • In addition - this function is called not in the interrupt. – Natr Jun 20 '23 at 13:33
  • Welcome to StackOverflow! Please take the [tour] to learn how this site works. -- Please [edit] your question when you add new information. Comments are not the right thing, this is not a forum. -- Would you mind to check _which_ of the additions for other peripherals makes the mount fail? – the busybee Jun 21 '23 at 06:06
  • The problem is clearly not to be seen in the code fragment you have posted since that otherwise works, ant it is the introduction of one or more peripheral devices that causes the problem. The USB pins all have alternate functions. It seems likely that one or more of your peripherals is configured to use the same pins as those assigned to USB. That may not be the case, but it is the kind of information anyone would need when investigating the problem. – Clifford Jun 21 '23 at 07:08
  • Do not add information in comments - edit the question. This is not a discussion forum thread. – Clifford Jun 21 '23 at 07:09

0 Answers0