cancel
Showing results for 
Search instead for 
Did you mean: 

FatFS with Cube HAL address problem

ricardomiguel
Associate II
Posted on June 27, 2016 at 17:40

I'm using STM32F446RE to implement FatFS with Cube, using eval_sd.h file from F446RE_EVAL. I'm performing periodically writes in files and sometimes the code works, other it gives me a Hard fault at ff.c: validate, when accessing fil->fs:

static

FRESULT validate ( /* FR_OK(0): The object is valid, !=0: Invalid */

void* obj /* Pointer to the object FIL/DIR to check validity */

)

{

FIL *fil = (FIL*)obj; /* Assuming offset of .fs and .id in the FIL/DIR structure is identical */

if (!fil ||

!fil->fs ||

!fil->fs->fs_type ||

fil->fs->id != fil->id ||

(disk_status(fil->fs->drv) & STA_NOINIT))

return FR_INVALID_OBJECT;

ENTER_FF(fil->fs); /* Lock file system */

return FR_OK;

}

The problem is fil->is have address 0x9313330, so it seems that it was never addressed. Anyone having this problem? 

My custom HardFault Handler prints:

In Hard Fault Handler

SCB->HFSR = 0x40000000

Forced Hard Fault

SCB->CFSR = 0x00008200

PRECISERR at 0x9313530

2 REPLIES 2
troy1818
Senior
Posted on June 27, 2016 at 20:01

Hi,

Could you disclose the code that you use when open file and writing?

Make sure that the ''FIL'' structure is pointing to valid memory before you use it with fatFS f_ functions. FatFS will not do that for you if I recall correctly.

ricardomiguel
Associate II
Posted on June 28, 2016 at 18:05

Forget about it, one of my ''if'' didn't have the right condition so it kept filling a char array in the bss past it's limit, thus changing the memory after that (including the FIL structure with that pointer).