Skip to content

Random loss/corruption of data when reading (errno -10004) #215

Closed

Description

@boreycutts

So I am not very experienced in working with NOR Flash memory or file systems so bear with me. I have somehow managed to create a 1MB spiffs partition on my NOR Flash chip with the following configuration:

cfg.phys_size = 1 * 1024*1024;              // Partition size       : 1MB
cfg.phys_addr = 0x50800000;                 // Partition location   : 0x50800000
cfg.phys_erase_block = 256 * 1024;          // Erase Block Size     : 256kB
cfg.log_block_size = 256 * 1024;            // Block Size           : 256kB
cfg.log_page_size = LOG_PAGE_SIZE;          // Page Size            : 256B

typedef u16_t spiffs_block_ix;
typedef u16_t spiffs_page_ix;
typedef u16_t spiffs_obj_id;
typedef u16_t spiffs_span_ix;

With this I am able to create small files and read them back however my implementation requires the ability to write ~50kB files. Writing these files gives me no errors however when I read the contents of memory there are missing file headers and missing/corrupt data. When this occurs the read function will typically give the error -10004. This occurs very randomly so it has been difficult to figure out exactly what's happening.

I'm almost certain that it's not a driver error because I was able to write a 50kB string to the flash and read it back. However I do think that it has something to do with my configuration because when I change spiffs_page_ix to 32 bit, writing works perfectly but when I try to open the file I get the error -10072 which correlates to SPIFFS_VIS_END. If more info is needed just let me know.

Activity

  1. changed the title [-]Random loss/corruption of data when writing (errno -10004)[/-] [+]Random loss/corruption of data when reading (errno -10004)[/+] on Jul 5, 2018
  2. boreycutts commented on Jul 5, 2018

    @boreycutts
    Author

    Upon further debugging I have noticed that the files are intact immediately after writing. However when i execute SPIFFS_read(), when I check the contents of the memory through the debugger, in random locations there will be missing/corrupted data. There is typically a series of 0x00, 0x55 (0b01010101) or 0xaa (0b10101010) bytes where the original data was. Once again I tested this only using driver operations and no corruption occurred so I don't think it's my drivers.

  3. boreycutts commented on Jul 9, 2018

    @boreycutts
    Author

    Ok my bad I realized it was a problem with the cache. I disabled caching during reads and the file system works perfectly. Apparently I'm not flushing the cache correctly so if anyone has any advice on how to do so let me know.

  4. pellepl commented on Jul 14, 2018

    @pellepl
    Owner

    This seems more like a memory corruption to me. Probably something, not being spiffs, is writing in your cache buffers. Oxaa and 0x55 feels like specific patterns to me, could this give you a clue of what it could be?
    You can try moving the cache buffers in memory or assigning the double amount of cache memory just to test.

  5. boreycutts commented on Jul 24, 2018

    @boreycutts
    Author

    So the issue did turn out to be a driver issue. Not flushing the cache after reads must have caused some memory corruption. I figured out how to flush the cache properly and spiffs works perfectly now. My apologies, I'll close the issue now.

  6. fvpalha commented on Aug 1, 2018

    @fvpalha

    @boreycutts , What is the solution? How flush the cache properly? This is important to the developer community.

  7. boreycutts commented on Aug 1, 2018

    @boreycutts
    Author

    @fvpalha So I'm using spiffs on top of the MQX RTOS which has its own function for flushing the cache DCACHE_FLUSH(). I call that function after every NOR flash read and so far there hasn't been any more data corruption.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions