Question
Using internal flash memory as FatFs drive
Posted on February 13, 2015 at 13:56
I'm trying to make internal flash on STM32F051xx to be seen as a drive.
This is the code on the top level:char
USER_Path[4];
/* USER logical drive path */
FATFS USER_FatFs;
/* File system object for User logical drive */
FIL USER_File;
/* File object */
uint32_t bytesWritten;
uint8_t text[] =
''Text to write to logical disk''
;
if
(FATFS_LinkDriver(&USER_Driver, USER_Path) == 0) {
if
(f_mount(&USER_FatFs, (TCHAR
const
*)USER_Path, 0) == FR_OK) {
if
(f_open(&USER_File,
''STMTXT''
, FA_CREATE_ALWAYS | FA_WRITE) == FR_OK) {
if
(f_write(&USER_File, text,
sizeof
(text), (
void
*)&bytesWritten) == FR_OK); {
f_close(&USER_File);
}
}
}
}
f_mount() returns FR_OK, but when it comes to creating a new file via f_open(), which calls find_volume(), which calls check_fs() which returns FR_NO_FILESYSTEM. I assume this is because a boot sector wasn't created, but I have no idea how to do that.
I've written USER_read(), USER_write() and USER_ioctl() functions, but I don't know what to write in the USER_initialize() function. Right now I've left it in it's original state, where it returns RES_OK without doing anything. I feel like that may be the source of the problem.
Any suggestions?
#fatfs #stm32 #flash #middleware