2024-06-28 10:00 AM
int main(void)
{
FATFS FatFs;
FIL fil;
FRESULT fr;
UINT bw;
fr = f_mount(&FatFs, "", 0);
if (fr != FR_OK) {
return (int)fr;
}
fr = f_open(&fil, "example.txt", FA_WRITE | FA_CREATE_ALWAYS);
if (fr != FR_OK) {
f_mount(NULL, "", 0);
return (int)fr;
}
f_close(&fil);
}
This is the main.c file. While running the code I get a hard fault issue at f_open.
I use SDIO mode SD 1 bit
Kindly help
2024-06-28 10:23 AM
Whatever is happening, it's not in this top-level code. No idea of STM32 or board involved.
Establish where the hard fault is actually occurring. Do this with a suitably instrumented HardFault_Handler() rather than a while(1) loop
Would suggest moving FATFS structure off the stack, and clearing the other structures.
Returning from main() will fail and potentially fault the MCU, where would it return too?
2024-06-28 10:26 AM
First you have to mount - successful ! -> check return , ok or not.
And do mount with "1" parameter, = now.
And WHAT you mount ? an empty string ??
see :
fresult = f_mount(&SDfs, (TCHAR const*)SDPath, 1); // SD card mount NOW
Then only if fresult = ok , can do any open or read ; NOT write, until this working fine !!!