2018-09-19 09:16 AM
Hi,
Another one for you.
I am having problems with the FatFs library, specifically I cannot mount the SD card. I am using the HAL libraries and have generated the configuration using STMCubeMX. I cannot get this to work on either my own hardware of the STM32L476 eval board.
When I run this simple bit of code, i get the result '1' (FR_DISK_ERR), which apparently relates to a low level IO error.
I have tried;
adding 47K resistors to the I/O and clock lines.
changing the clock frequency (to the SDMMC module)
Formatting the SD card
Using a variety of SD cards
Running the code on my STM32L476 EVAL.
Given that I get the same result on the eval board, I would suggest that my hardware isn't the problem. The example software supplied in the STM32L4 mxcube package is massively different to the examples that apparently work on the web.
FATFS SDFatFs;
FIL MyFile;
UINT testByte;
uint8_t res;
char bufferout[20];
//char myPath[] = "testicle.txt\0";
//char myData[] = "This is a test!!\0";
//char bufferout[20];
//res = disk_initialize(0);
res = f_mount(&SDFatFs, (TCHAR const*)SDPath, 11);
sprintf(bufferout, "FR_res: %d", res);
HAL_UART_Transmit(&hlpuart1, (uint8_t*)bufferout, 10, 1000);
I have scoured the internet for information, but cannot find any good examples to help me out, so I'm reaching to you guys.
Kind regards,
Peter
2018-09-19 09:40 AM
Sorry not a CubeMX user/fan.
Type of issue here sounds more code related than the hardware/card level stuff you've mentioned. You'd do better instrumenting the DISKIO and SDIO/SDMMC layers to understand the failure mechanism.
I have working FatFS/L476 code on the NUCLEO, and frankly several L4/L4+ platforms. The BSP for the EVAL board should have some working code, and examples using the code along with FatFs.
A good working example for a commercial custom board will run you several hundred dollars of my time.
2018-09-20 04:15 AM
Hi,
After going through the 'tree' and adding lots of debug stuff, I've narrowed the problem down to the 'disk_read(fs->drv, fs->win, sector, 1) != RES_OK)' function in diskio.c (called in ff.c by move_window( ) ). A quick test on disk_write also shows a fail. Any ideas on where to look next?
Thanks
Peter
2018-09-20 04:36 AM
Neither I'm a Cube fan/user.
I would check why disk_read() fails, i.e. what error it throws. "!= RES_OK" is not really descriptive.
Usually, the "breaking point" is between the FATFS layer and the device-specific HAL code.
And perhaps watch the lines with a scope.
2018-09-20 08:50 AM
I'd look at the ErrorCode in the SD_HandleTypeDef for more precise detail. The first failure tends to be critical, and tends to cascade.
Write is sensitive to waiting for completion, typically handled via a BSP_SD_GetCardState() type spin loop.
2018-10-17 03:21 PM
Hi All,
I have made some progress - ish. I can mount, read and write to a SD card, but only in 1bit SD mode. The SD card will still not mount in 4 bit (wide) mode.
2019-07-16 06:02 AM
I have the same problem....f_mount does not work.
Would you share your code?
Best regards