Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

-10010 on example #298

Open
marriusco opened this issue Nov 17, 2023 · 0 comments
Open

-10010 on example #298

marriusco opened this issue Nov 17, 2023 · 0 comments

Comments

@marriusco
Copy link

marriusco commented Nov 17, 2023

HI,
Using this example: https://github.com/pellepl/spiffs/wiki/Integrate-spiffs
getting SPIFFS_write
mount res: 0
errno -10010
and fd = SPIFFS_open() returns -10001
Free pages = -508

  s32_t free_pages =
      (SPIFFS_PAGES_PER_BLOCK(fs) - SPIFFS_OBJ_LOOKUP_PAGES(fs)) * (fs->block_count-2)
      - fs->stats_p_allocated - fs->stats_p_deleted;   >>>>> -508
  int tries = 0;

Here is my example


constexpr const char* storage="/tmp/nvram.txt"
system("dd if=/dev/zero of=/tmp/nvram.txt bs=8M count=1");

void my_spiffs_mount() {
    spiffs_config cfg;
    cfg.phys_size        = 2*1024*1024; // use all spi flash
    cfg.phys_addr        = 0;            // start spiffs at start of spi flash
    cfg.phys_erase_block = 65535;      // according to datasheet
    cfg.log_block_size =   65535;      // let us not complicate things
    cfg.log_page_size =    256;        // as we said
    cfg.hal_read_f = my_spi_read;
    cfg.hal_write_f = my_spi_write;
    cfg.hal_erase_f = my_spi_erase;

    int res = SPIFFS_mount(&fs,
                           &cfg,
                           spiffs_work_buf,
                           spiffs_fds,
                           sizeof(spiffs_fds),
                           spiffs_cache_buf,
                           sizeof(spiffs_cache_buf),
                           0);
    printf("mount res: %i\n", res);
};

    spiffs_file fd = SPIFFS_open(&fs, "my_file", SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0);
    if (SPIFFS_write(&fs, fd, (uint8_t *)"Hello world", 12) < 0) printf("errno %i\n", SPIFFS_errno(&fs));
    SPIFFS_close(&fs, fd);

    fd = SPIFFS_open(&fs, "my_file", SPIFFS_RDWR, 0);
    if (SPIFFS_read(&fs, fd, (uint8_t *)buf, 12) < 0) printf("errno %i\n", SPIFFS_errno(&fs));
    SPIFFS_close(&fs, fd);


int32_t my_spi_read(uint32_t addr, uint32_t size, uint8_t *buffer)
{
   // std::cout << "read: " << int(addr) << "[" << int(size) <<"]\n";
    FILE* pf = fopen(storage,"rb");
    if(pf)
    {
        fseek(pf,addr,SEEK_SET);
        fread(buffer,1,size,pf);
        fclose(pf);
        return 0;
    }
    return -1;
}

int32_t my_spi_write(uint32_t addr, uint32_t size, uint8_t *buffer)
{
   // std::cout << "write: " << int(addr) << "[" << int(size) <<"]\n";
    FILE* pf = fopen(storage,"w+");
    if(pf)
    {
        fseek(pf,addr,SEEK_SET);
        fwrite(buffer,1,size,pf);
        fclose(pf);
        return 0;
    }
    return -1;
}
    

image

I reduced the size to see read/writes
as:

cfg.phys_size        = 2*1024; // use all spi flash
cfg.phys_addr        = 0;            // start spiffs at start of spi flash
cfg.phys_erase_block = 1024;      // according to datasheet
cfg.log_block_size =   1024;      // let us not complicate things
cfg.log_page_size =    256;        // as we said
read: 254[2]  <  shouldn't be this offset as well multiple of block size ? , or the offset in in blocks ?
read: 1278[2]
read: 0[256]
read: 1024[256]
mount res: 0
errno -10010
errno -10010
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant