GD32 FATFS: f_mount() return FR_NO_FILESYSTEM

216 views Asked by At

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?

0

There are 0 answers