pellepl / spiffs

Wear-leveled SPI flash file system for embedded devices
MIT License
1.52k stars 402 forks source link

SPIFF write err -10002 #256

Closed tk202111 closed 4 years ago

tk202111 commented 4 years ago

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

SPIFFS_mount sz:8388608 logpgsz:256 logblksz:4096 perasz:4096 addr:00000000 fdsz:128 cachesz:1152 page index byte len: 256 object lookup pages: 1 page pages per block: 16 page header length: 5 object header index entries: 105 object index entries: 124 available file descriptors: 2 free blocks: 0 mount 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; }

                    // 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 :

SPIFFS_write 1 256 append: 256 bytes @ offs 29696 of size 29696 append: 8001 find objix span_ix:0001 append: 8001 found object index at page 0d0e [fd size 29696] spi_flash_erase_sector >>> sectorAddr: 0xf0000 append: 8001 store to existing data page, 0f0b:0076 offset:78, len 173, written 0 append: 8001 wrote page 0f0b to objix entry 000d in mem spi_flash_erase_sector >>> sectorAddr: 0xf0000 spi_flash_erase_sector >>> sectorAddr: 0xf0000 spi_flash_erase_sector >>> sectorAddr: 0xf0000 append: 8001 store new data page, 0f0d:0077 offset:0, len 83, written 173 append: 8001 wrote page 0f0d to objix entry 000e in mem append: 8001 store objix page, 0d0e:0001, written 256 spi_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 append: 8001 store new size II 29952 in objix_hdr, 0f0e:0000, written 256, res 0 Size Written = 29952

SPIFFS_write 1 256 append: 256 bytes @ offs 29952 of size 29952 append: 8001 find objix span_ix:0001 append: 8001 found object index at page 0d0e [fd size 29952] spi_flash_erase_sector >>> sectorAddr: 0xf0000 append: 8001 store to existing data page, 0f0d:0077 offset:83, len 168, written 0 append: 8001 wrote page 0f0d to objix entry 000e in mem spi_flash_erase_sector >>> sectorAddr: 0xf0000 spi_flash_erase_sector >>> sectorAddr: 0xf0000 spi_flash_erase_sector >>> sectorAddr: 0xf0000 append: 8001 store new data page, 0f0f:0078 offset:0, len 88, written 168 append: 8001 wrote page 0f0f to objix entry 000f in mem append: 8001 store objix page, 0d0e:0001, written 256 spi_flash_erase_sector >>> sectorAddr: 0xd0000 append: 8001 store new size II 30208 in objix_hdr, 0020:0000, written 256, res -10002 FILE Write Error!!

tk202111 commented 4 years ago

it's the memory driver issue and resolved