I am using a SPI NOR Flash (AT45DB641E) with Keil MDK5 Flash File System v6.8 and EFS. Init, Mounting and formatting works. Even "finfo()" works an delivers information about FS and overall flash size of 8MB. But creating a file and then re-open it in read mode doesnt work. Like shown in this snippet:
file = fopen("reinhard.keil","w"); // open file in write mode if(file != NULL) printf("Success: created \"reinhard.keil\" \r\n"); // this works! if(fputs("This is an example for fputs.\n", file) >=0) // write a string to file printf("Success: wrote string to file \"reinhard.keil\" \r\n"); // this works too! if(fclose(file)==NULL) // close file printf("Success: file \"reinhard.keil\" closed\r\n"); // this also works! file = fopen("reinhard.keil","r"); // (re)open file in read mode if(file == NULL) { printf("Error: failed to re-open \"reinhard.keil\" \r\n"); // Hmmm, why is that? fsStat = ffind("reinhard.keil", &fsFileInfo); // lets look for this file if(fsStat != fsOK) printf("Can't find file"); // file still not present }
What am i doing wrong? I already worked with Keil FS, but with SD-Card and FAT32...and it was doing well. Am I missing something with EFS? I know about the EFS-limitations, but I think I avoided them.
The reason why I am using Keil FS, is that the whole chain SPI-driver -> flash driver -> File System is working (theoretically) out of the box. I initialized with all the default settings. Since I am using SPI2 all I have changed is the value DRIVER_SPI_NUM from 1 to 2 in the file AT45DB641E.c. I think, if somethings is wrong with this lowest driver in stack, i couldn't have done the init of flash nor the mounting in file system. But they run smoothly with the return ARM_DRIVER_OK and fsOK. The only uncertainty I have with SPI driver is the NSS (CS) Pin. In RTE_Device.h I assigned SPI2-NS-Pin to PB9. If I leave it unassigned the function drv_flash->PowerControl(ARM_POWER_FULL) will return ARM_DRIVER_ERROR. But for real I have on my prototype PCB the CS to the Flash-IC on PD4 (PB9 is open). So I initialized PD4 GPIO manually as Out-PP and set it to low. Since then all inits ran without errors. And finfo() also delivers correct information. I really don't get what I am missing here.