Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Question about W25N01 chip with SPI #1023

Open
simon88 opened this issue Sep 6, 2024 · 0 comments
Open

Question about W25N01 chip with SPI #1023

simon88 opened this issue Sep 6, 2024 · 0 comments

Comments

@simon88
Copy link

simon88 commented Sep 6, 2024

Hi all,

I'm trying to use littlefs instead of fatfs but i'm stuck. My hardware :

  • STM32F405
  • W25N01G SPI

For w25n I'm using this driver https://github.com/masoud-babaabasi/W25N01-flash-library/tree/main/W25N_SPI_dual for the moment i'm working with fatfs.

So I've added littlefs library to my project and I've created littlfs fonction like that :

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

int lfs_erase(const struct lfs_config *c, lfs_block_t block) {
  W25NXX_Erase_Block128K(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) {
  W25NXX_Write((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) {
  W25NXX_Read((uint8_t *)buffer , (block * c->block_size + offset), size);
  return 0;
}

and here is my configuration

struct lfs_config cfg_lfs_w25n = {
        .read = lfs_read,
        .prog = lfs_prog,
        .erase = lfs_erase,
        .sync = lfs_sync,
        .read_size = 16, 
        .prog_size = 16, 
        .block_size = 4096, 
        .block_count = 1024, 
        .cache_size = 256,
        .lookahead_size = 16,
        .block_cycles = 500, 
};

in my main I'm trying to create file example

      lfs_t lfs;
      int err = lfs_mount(&lfs, &cfg_lfs_w25n);

      if (err) {
        D_LOG_DEBUG("format %d", err);
        lfs_format(&lfs, &cfg_lfs_w25n);
        D_LOG_DEBUG("end format");
        lfs_mount(&lfs, &cfg_lfs_w25n);
      }


      lfs_file_t file;
      lfs_file_open(&lfs, &file, "hello.txt", LFS_O_WRONLY | LFS_O_CREAT);
      lfs_file_write(&lfs, &file, "Hello, World!", 13);
      lfs_file_close(&lfs, &file);

I never see my debug message end format, what i'm doing bad ?

EDIT :
with these configuration

    .read = lfs_read,
    .prog = lfs_prog,
    .erase = lfs_erase,
    .sync = lfs_sync,
    .read_size = 2048,
    .prog_size = 2048,
    .block_size = 128 * 1024,
    .block_count = 1024,
    .cache_size = 2048,
    .lookahead_size = 128,
    .block_cycles = 1000,

I can format my card, but after creating 2 files i got lfs.c:2072:debug: Bad block at 0x1if I try to create third file

EDIT 2 :format doesn't work, right now, I always got -28 LFS_ERR_NOSPC error code from lfs_format and comming from format command I have :

lfs.c:2072:debug: Bad block at 0x0
lfs.c:2078:warn: Superblock 0x0 has become unwritable

So for now, I'm not sure about my erase function W25NXX_Erase_Block128Kand/or my lfs_config

EDIT 3 : Ok so I have news, for now I can format/mount and create files on my w25n01 chip. But After creating 6 files when I'm trying to create next file I got corrupt pair adress (I think this happen when I pass to next block), so right now I'm not sure about how to use block offset and size

If I add offset like that :

int lfs_prog(const struct lfs_config *c, lfs_block_t block, lfs_off_t offset, const void *buffer, lfs_size_t size) {
  W25NXX_Write((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) {
  W25NXX_Read((uint8_t *)buffer , (block * c->block_size) + offset, size);
  return 0;
}

I got error as soon as I try to create file and if I remove offset like that :

int lfs_prog(const struct lfs_config *c, lfs_block_t block, lfs_off_t offset, const void *buffer, lfs_size_t size) {
  W25NXX_Write((uint8_t *)buffer , (block * c->block_size) , 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) {
  W25NXX_Read((uint8_t *)buffer , (block * c->block_size) , size);
  return 0;
}

I can create 6 files but for the seven I got errors :

Bad block at 0x1
Superblock 0x1 has become unwritable
Corrupted dir pair at {0x0, 0x1}

here is my configuration :

struct lfs_config cfg_lfs_w25n = {
    .read = lfs_read,
    .prog = lfs_prog,
    .erase = lfs_erase,
    .sync = lfs_sync,
    .read_size = 2048,
    .prog_size = 2048,
    .block_size = 128 * 1024,
    .block_count = 1024,
    .cache_size = 2048,
    .lookahead_size = 128,
    .block_cycles = 500,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant