-
Notifications
You must be signed in to change notification settings - Fork 409
Open
Description
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;
}
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
Metadata
Metadata
Assignees
Labels
No labels
