Code to create a file and perform multiple write:fd = SPIFFS_open(&ffs, filename, SPIFFS_CREAT | SPIFFS_WRONLY, 0);
for(i=0; i<sectors; i++) //number of sectors in a bank
{
PRINTF("Copy from sector user_start_sector1 + %d\r\n",i);
for (j=0;j<128;j++){ //128 page on each sector
fpage = ((i+user_start_sector1)128)+j;
faddress = fpage FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES;
memset(s_PageBuf,0,FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES);
for (k=0; k<buffer_size; k++){ //256 bytes on each page
s_PageBuf[k] = ((uint32_t )(faddress));
faddress = faddress + 4;
}
// write to it
**if (SPIFFS_write(&ffs, fd, (u8_t *)s_PageBuf,
FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES) < 0)**
{
PRINTF("FILE Write Error!!\r\n");
// close it
SPIFFS_close(&ffs, fd);
return false;
}
size = size +256;
PRINTF("Size Written = %d\r\n",size);
}
}
// close it
res = SPIFFS_close(&ffs, fd);
if (res < 0) {
PRINTF("FILE Close Error!!\r\n");
return false;
}
ERROR log when it failed :
[1m[7mSPIFFS_write 1 256
[0m[32mappend: 256 bytes @ offs 29696 of size 29696
[0m[32mappend: 8001 find objix span_ix:0001
[0m[32mappend: 8001 found object index at page 0d0e [fd size 29696]
[0mspi_flash_erase_sector >>> sectorAddr: 0xf0000
[32mappend: 8001 store to existing data page, 0f0b:0076 offset:78, len 173, written 0
[0m[32mappend: 8001 wrote page 0f0b to objix entry 000d in mem
[0mspi_flash_erase_sector >>> sectorAddr: 0xf0000
spi_flash_erase_sector >>> sectorAddr: 0xf0000
spi_flash_erase_sector >>> sectorAddr: 0xf0000
[32mappend: 8001 store new data page, 0f0d:0077 offset:0, len 83, written 173
[0m[32mappend: 8001 wrote page 0f0d to objix entry 000e in mem
[0m[32mappend: 8001 store objix page, 0d0e:0001, written 256
[0mspi_flash_erase_sector >>> sectorAddr: 0xd0000
spi_flash_erase_sector >>> sectorAddr: 0xf0000
spi_flash_erase_sector >>> sectorAddr: 0xf0000
spi_flash_erase_sector >>> sectorAddr: 0xf0000
spi_flash_erase_sector >>> sectorAddr: 0xf0000
spi_flash_erase_sector >>> sectorAddr: 0xf0000
[32mappend: 8001 store new size II 29952 in objix_hdr, 0f0e:0000, written 256, res 0
[0mSize Written = 29952
[1m[7mSPIFFS_write 1 256
[0m[32mappend: 256 bytes @ offs 29952 of size 29952
[0m[32mappend: 8001 find objix span_ix:0001
[0m[32mappend: 8001 found object index at page 0d0e [fd size 29952]
[0mspi_flash_erase_sector >>> sectorAddr: 0xf0000
[32mappend: 8001 store to existing data page, 0f0d:0077 offset:83, len 168, written 0
[0m[32mappend: 8001 wrote page 0f0d to objix entry 000e in mem
[0mspi_flash_erase_sector >>> sectorAddr: 0xf0000
spi_flash_erase_sector >>> sectorAddr: 0xf0000
spi_flash_erase_sector >>> sectorAddr: 0xf0000
[32mappend: 8001 store new data page, 0f0f:0078 offset:0, len 88, written 168
[0m[32mappend: 8001 wrote page 0f0f to objix entry 000f in mem
[0m[32mappend: 8001 store objix page, 0d0e:0001, written 256
[0mspi_flash_erase_sector >>> sectorAddr: 0xd0000
[32mappend: 8001 store new size II 30208 in objix_hdr, 0020:0000, written 256, res -10002
[0mFILE Write Error!!
I am trying to write 192KBytes to a file but it always failed at 29952Bytes Maybe anyone could share some light.
I am using a 8MBytes SPI flash memory, 256Bytes per page and 4096Bytes per sector
[1m[7mSPIFFS_mount sz:8388608 logpgsz:256 logblksz:4096 perasz:4096 addr:00000000 fdsz:128 cachesz:1152 [0m[32mpage index byte len: 256 [0m[32mobject lookup pages: 1 [0m[32mpage pages per block: 16 [0m[32mpage header length: 5 [0m[32mobject header index entries: 105 [0m[32mobject index entries: 124 [0m[32mavailable file descriptors: 2 [0m[32mfree blocks: 0 [0mmount res: 0
Code to create a file and perform multiple write: fd = SPIFFS_open(&ffs, filename, SPIFFS_CREAT | SPIFFS_WRONLY, 0); for(i=0; i<sectors; i++) //number of sectors in a bank { PRINTF("Copy from sector user_start_sector1 + %d\r\n",i); for (j=0;j<128;j++){ //128 page on each sector fpage = ((i+user_start_sector1)128)+j; faddress = fpage FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES; memset(s_PageBuf,0,FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES); for (k=0; k<buffer_size; k++){ //256 bytes on each page s_PageBuf[k] = ((uint32_t )(faddress)); faddress = faddress + 4; }
}
ERROR log when it failed :
[1m[7mSPIFFS_write 1 256 [0m[32mappend: 256 bytes @ offs 29696 of size 29696 [0m[32mappend: 8001 find objix span_ix:0001 [0m[32mappend: 8001 found object index at page 0d0e [fd size 29696] [0mspi_flash_erase_sector >>> sectorAddr: 0xf0000 [32mappend: 8001 store to existing data page, 0f0b:0076 offset:78, len 173, written 0 [0m[32mappend: 8001 wrote page 0f0b to objix entry 000d in mem [0mspi_flash_erase_sector >>> sectorAddr: 0xf0000 spi_flash_erase_sector >>> sectorAddr: 0xf0000 spi_flash_erase_sector >>> sectorAddr: 0xf0000 [32mappend: 8001 store new data page, 0f0d:0077 offset:0, len 83, written 173 [0m[32mappend: 8001 wrote page 0f0d to objix entry 000e in mem [0m[32mappend: 8001 store objix page, 0d0e:0001, written 256 [0mspi_flash_erase_sector >>> sectorAddr: 0xd0000 spi_flash_erase_sector >>> sectorAddr: 0xf0000 spi_flash_erase_sector >>> sectorAddr: 0xf0000 spi_flash_erase_sector >>> sectorAddr: 0xf0000 spi_flash_erase_sector >>> sectorAddr: 0xf0000 spi_flash_erase_sector >>> sectorAddr: 0xf0000 [32mappend: 8001 store new size II 29952 in objix_hdr, 0f0e:0000, written 256, res 0 [0mSize Written = 29952
[1m[7mSPIFFS_write 1 256 [0m[32mappend: 256 bytes @ offs 29952 of size 29952 [0m[32mappend: 8001 find objix span_ix:0001 [0m[32mappend: 8001 found object index at page 0d0e [fd size 29952] [0mspi_flash_erase_sector >>> sectorAddr: 0xf0000 [32mappend: 8001 store to existing data page, 0f0d:0077 offset:83, len 168, written 0 [0m[32mappend: 8001 wrote page 0f0d to objix entry 000e in mem [0mspi_flash_erase_sector >>> sectorAddr: 0xf0000 spi_flash_erase_sector >>> sectorAddr: 0xf0000 spi_flash_erase_sector >>> sectorAddr: 0xf0000 [32mappend: 8001 store new data page, 0f0f:0078 offset:0, len 88, written 168 [0m[32mappend: 8001 wrote page 0f0f to objix entry 000f in mem [0m[32mappend: 8001 store objix page, 0d0e:0001, written 256 [0mspi_flash_erase_sector >>> sectorAddr: 0xd0000 [32mappend: 8001 store new size II 30208 in objix_hdr, 0020:0000, written 256, res -10002 [0mFILE Write Error!!