LittleFS problem while mounting external SPI flash memory with STM32L4xx

Last days I have been facing an issue with the LittleFS library. I need to mount my external flash AT45DB041E, which has the following characteristics:
(I can communicate with the flash properly)

FLASH SIZE: 4MBit, Block size: 2048 bytes, Page size: 256 Bytes, Num_Blocks = 256, Num_Pages = 2048, Num_Sectors = 8

After mounting the main purpose of my task is to find a binary file that had been written to this external flash with LittleFS as well, in order to store its contents to a buffer.

For that reason I have implemented some functions based on AT45DB041E_datasheet where I can read-write-erase a page properly(I have test it and it works properly). Also I have a function that erases a block(8 pages, also tested). All I am doing

lfs_t lfs;
const struct lfs_config cfg = {

    .read               = block_device_read,
    .prog               = block_device_prog,
    .erase              = block_device_erase,
    .sync               = block_device_sync,

    // block device configuration
    .read_size          = 256,
    .prog_size          = 256,
    .block_size         = 2048,
    .block_count        = 256,
    .cache_size         = 256,
    .lookahead_size     = 2048,
    .block_cycles       = 500,
}

Subsequently, I am connecting the implemented functions which are interacting properly with the external flash memory with that way (Those are the functions of littlefs where I implement them with my functions):

(The status register doesn’t report any error when programming operation finishes).

int block_device_prog(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size)
{
    uint8_t status_register[2];
    /*Calculate the page address based on block and offset*/
    uint16_t page_address = (block * c->block_size) + off;

    /*Write the page to flash memory*/
    at45db_write_page(page_address, (uint8_t *)buffer, size);

    /*Read the status register*/
    at45db_read_status(status_register);

    /*Check the 5bit of second byte*/
    uint16_t res = READ_BIT(status_register[1], (1U<<5));

    /*Check for fault operation*/
    if (res == 1)
    {
        /*Error detected while programming the specified page*/
        printf("An error has been detected while programming the page address: %Xnr", page_address);
        return -1;
    } else
    {
        /*No errors detected while programming the flash memory*/
        printf("Successful programming the page address: 0x%08Xnr", page_address);
        return 0;
    }
}

(The erase operation doesn’t report any error when it finishes as well)

int block_device_erase(const struct lfs_config *c, lfs_block_t block)
{
    /*Calculate the address*/
    uint32_t address = block * c->block_size;

    uint16_t res = at45db_block_erase(address);

    /*Check for fault conditions*/
     if (res == 1) {

         /*Success*/
         return LFS_ERR_OK;
     } else {
         printf("Error in erase operation of address: 0x%Xnr", address);
         /*False*/
         return -1;
     }
}

This is the read operation

int block_device_read(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size)
{
    uint16_t page_address = (block * c->block_size) +off;

    at45db_read_page(page_address, buffer);

    return LFS_ERR_OK;
}

Now the problem is when I am using that code:

 at45db_init();
 at45db_chip_erase();
 int res = lfs_mount(&lfs, &cfg);
 if (res != LFS_ERR_OK) {
     printf("Errornr");
     lfs_format(&lfs, &cfg);
     lfs_mount(&lfs, &cfg);
 }

The first mount return -84, which is an indication of corruption. More specifically it returns this:

trace: lfs_mount(...)
Corrupted dir pair at {0x0, 0x1}
lfs_mount -> -84
Error

After that the format function returns -28 which is (No space left on device indication). I tries to add to the cfg struct some buffers one for reading one for writing and another one where each buffer had the same size 256, but I was getting the same error again). More specifically it returns this :

lfs_format()
Successful programming the page address: 0x00000000
Bad block at 0x0
Superblock 0x0 has become unwritable
lfs_format -> -28

And finally, when it uses the mount function again it also fails with the same error as the first time.

Can anyone help me with that?

My questions are:

  1. Lfs doc had block_device_read/write/erase is that a problem that I use read/write/erase to pages?
  2. Is the values at the configurations correct based on the characteristics of the external flash memory?
  3. Am I missing something before mounting?

I need to tell you that the external flash memory which I am trying to mount is not corrupted since I am able to mount it with the mbed library. But I need to make this program work with CubeIDE.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật