littlefs-project / littlefs

A little fail-safe filesystem designed for microcontrollers
BSD 3-Clause "New" or "Revised" License
5.25k stars 803 forks source link

No more space left with W25Q16 #1034

Open simon88 opened 1 month ago

simon88 commented 1 month ago

Hi, I'm tring to use w25q16 chip with little fs. I use this library for STM v1.20.0 So everything works with SPI I can find the chip etc. I've implemented lfs like this

#define LFS_BUFFER_SIZE     256
static uint8_t read_buffer[LFS_BUFFER_SIZE];
static uint8_t prog_buffer[LFS_BUFFER_SIZE];
static uint8_t lookahead_buffer[128];

struct lfs_config cfg_lfs = {
        .read = lfs_read,
        .prog = lfs_prog,
        .erase = lfs_erase,
        .sync = lfs_sync,

        .read_size = LFS_BUFFER_SIZE,
        .prog_size = LFS_BUFFER_SIZE,
        .block_size = 65536,
        .block_count = 32,
        .cache_size = LFS_BUFFER_SIZE,
        .lookahead_size = 128,
        .block_cycles = 500,

        .read_buffer = read_buffer,
        .prog_buffer = prog_buffer,
        .lookahead_buffer = lookahead_buffer
};

....

int lfs_sync(const struct lfs_config *c) {
  return 0;
}

int lfs_erase(const struct lfs_config *c, lfs_block_t block) {
  W25qxx_EraseBlock(&handler_spi, block * c->block_size);
  return 0;
}

int lfs_prog(const struct lfs_config *c, lfs_block_t block, lfs_off_t offset, const void *buffer, lfs_size_t size) {
  W25qxx_WritePage(&handler_spi, (uint8_t*)buffer, block*c->block_size, offset, size);
  return 0;
}

int lfs_read(const struct lfs_config *c, lfs_block_t block, lfs_off_t offset, void *buffer, lfs_size_t size) {
  W25qxx_ReadPage(&handler_spi, (uint8_t*)buffer, block*c->block_size, offset, size);
  return 0;
}

I'm able to format the chip and mount. But as soon as I try to create a file (size 757 bytes) I got lfs.c:691:error: No more free space 0x18

What I'm doing wrong? I've also try to change block_size and block_count to 4096 and 32, but with this conf, I'm not able to format and mount I got error -28 for formating part.