FATfs on STM32F767 and external Flash
I'm using FATfs library for implementing file system on external flash.
Flash is 16MB memory where I can erase minimum of 4kb subsector and total no of subsectors are 4096, so there will be 1 sector per cluster. I've created 2 files
but I see both files are assigned with same sector no i.e sector 10.
So if I write 2nd file data written into first file gets erased.
Do we've to assign sector nos manually?
/* Create and Open a new text file object with write access */
if(f_open(&MyFile, "0:/0:/STM.TXT.TXT", FA_READ | FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)//FA_CREATE_ALWAYS | FA_WRITE
{
/* 'STM32.TXT' file Open for write Error */
Error_Handler();
}
else
{
/* Write data to the text file */
res = f_write(&MyFile, wtext, sizeof(wtext), (void *)&byteswritten);
if((byteswritten == 0) || (res != FR_OK))
{
/* 'STM32.TXT' file Write or EOF Error */
Error_Handler();
}
else
{
/* Close the open text file */
if(f_open(&MyFile2, "0:/RTM.TXT", FA_READ | FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)//FA_CREATE_ALWAYS | FA_WRITE
{
/* 'STM32.TXT' file Open for write Error */
Error_Handler();
}
/* Open the text file object with read access */
else
{
res = f_write(&MyFile2, wtext2, sizeof(wtext2), (void *)&byteswritten);
if((byteswritten == 0) || (res != FR_OK))
{
/* 'STM32.TXT' file Write or EOF Error */
Error_Handler();
}
/* Read data from the text file */
f_close(&MyFile);
f_close(&MyFile2);
f_open(&MyFile, "0:/STM.TXT", FA_READ | FA_OPEN_EXISTING);
res = f_read(&MyFile, rtext, sizeof(rtext), (void *)&bytesread);
f_open(&MyFile2, "0:/RTM.TXT", FA_READ | FA_OPEN_EXISTING);
res = f_read(&MyFile2, rtext2, sizeof(rtext2), (void *)&bytesread);
if((bytesread == 0) || (res != FR_OK))
{
//'STM32.TXT' file Read or EOF Error
Error_Handler();
}Thanks,
