littlefs icon indicating copy to clipboard operation
littlefs copied to clipboard

porting littlefs on STM32 with W25Q16JV Flash

Open e135193 opened this issue 6 years ago • 8 comments

Hello,

  I would like to port the littlefs on my STM32 MCU with W25Q16JV flash. 

  In order to port it, What steps should I follow?

  Where should I put my SPI_Read and SPI_Write function in the littlefs source code?

Best Regards

e135193 avatar Aug 15 '18 12:08 e135193

Hi, I have done it on STM32f103. the code shows below:

int fs_flash_read(const struct lfs_config *cfg, lfs_block_t block,
        lfs_off_t off, void *buffer, lfs_size_t size)
{
    assert(off  % cfg->read_size == 0);
    assert(size % cfg->read_size == 0);
    assert(block < cfg->block_count);
    uint32_t addr = SPI_FLASH_FS_BASE_ADDR + block*4096 + off;
    int ret = lsspi_flash_read(buffer, addr, size);

    if (ret == -1)
    {
        return -1;
    }
    else
    {
        return 0;
    }
}
int fs_flash_prog(const struct lfs_config *cfg, lfs_block_t block,
            lfs_off_t off, const void *buffer, lfs_size_t size)
{

    assert(off  % cfg->prog_size == 0);
    assert(size % cfg->prog_size == 0);
    assert(block < cfg->block_count);  

    uint32_t addr = SPI_FLASH_FS_BASE_ADDR + block*4096 + off;
    int ret = lsspi_flash_write((u8*)buffer, addr, size);

    if (ret == -1)
    {
        return -1;
    }
    else
    {
        return 0;
    }
}
int fs_flash_erase(const struct lfs_config *cfg, lfs_block_t block)
{
    assert(block < cfg->block_count);  
    
    int block_addr = SPI_FLASH_FS_BLOCK_OFF + block;
    
    int ret = lsspi_flash_erase_sector(block_addr);

    if (ret == -1)
    {
        return -1;
    }
    else
    {
        return 0;
    }
}
int fs_flash_sync(const struct lfs_config *c)
{
    return 0;
}

fzhenyu avatar Aug 31 '18 05:08 fzhenyu

Hello, I can not see functions to read via SPI hardware.

HAL_SPI_Transmit(); HAL_SPI_Receive();

Could you please share the full source code to my email address; [email protected]

e135193 avatar Aug 31 '18 08:08 e135193

stm32 has supported the hal driver.

fzhenyu avatar Sep 13 '18 02:09 fzhenyu

Hi @e135193, you'll need to provide the driver to communicate to the W25Q16JV over the STM32 SPI bus. This code is different for each SPI driver.

It looks like this may be provided by the "lsspi" functions in @fzhenyu's example, but I'm unfamiliar with the STM libaries.

In Mbed OS this is provided by the SPIFBlockdevice class. It's in C++ but may help as a starting point: https://github.com/ARMmbed/spif-driver/blob/master/SPIFBlockDevice.cpp

geky avatar Sep 19 '18 21:09 geky

Could you please send the source code for block device driver based HAL-CUBE STM32 + W25 [email protected].

manymix avatar Jan 04 '19 19:01 manymix

@fzhenyu . You have mentioned 4096 (block*4096). Is that your Block size. By seeing this It seems you are writing to and reading from absolute addresses , is that right?. can you provide your config structure for LFS.

visakh-png avatar Jan 06 '20 10:01 visakh-png

I would like to use littlefs on my STM32 MCU with W25N01 flash.

Could someone provide me or send me a code already made that serves as a reference?

joserp93 avatar Mar 24 '22 01:03 joserp93