Skip to content

wip: littlefs updates - #10

Closed
andrewleech wants to merge 14 commits into
dpgeorge:masterfrom
andrewleech:lfs
Closed

andrewleech wants to merge 14 commits into
dpgeorge:masterfrom
andrewleech:lfs

Conversation

@andrewleech

Copy link
Copy Markdown

Just as an fyi, this is my rebased copy of your littlefs branch with the additional changes I mentioned on top.

  • a (somewhat brute force) patch to uos.sync()
  • configuring flash specs from board config
  • update to littlefs 2.0

first commit of mine replaces fat with lfs entirely on "/flash", then in third revert the change again two filesystems. That one fails with my current config though, the pair corrupt each other.

// Disable internal flash, use external spi flash instead
#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (0)
#define MICROPY_HW_SPIFLASH_SIZE_BITS (256 * 1024 * 1024)

#define MICROPY_HW_SPIFLASH_PART1_BITS (128 * 1024 * 1024)
// #define MICROPY_HW_SPIFLASH_PART2_BITS (128 * 1024 * 1024)

#define MICROPY_VFS_LITTLEFS         (1)
#define MICROPY_HW_ENABLE_NATIVE_LFS (1)
#define MICROPY_VFS_LITTLEFS_START_OFFSET_BYTES (MICROPY_HW_SPIFLASH_PART1_BITS/8)

// HW Mode
#define MICROPY_HW_QSPIFLASH_SIZE_BITS_LOG2 (28) // 2^28 == 256Mb
#define MICROPY_HW_QSPIFLASH_CS      (pin_B10)
#define MICROPY_HW_QSPIFLASH_SCK     (pin_F10)
#define MICROPY_HW_QSPIFLASH_IO0     (pin_F8)
#define MICROPY_HW_QSPIFLASH_IO1     (pin_F9)
#define MICROPY_HW_QSPIFLASH_IO2     (pin_F7)
#define MICROPY_HW_QSPIFLASH_IO3     (pin_F6)

// block device config for SPI flash
extern struct _mp_spiflash_config_t spiflash_config;
extern struct _spi_bdev_t spi_bdev;
#define MICROPY_HW_BDEV_IOCTL(op, arg) ( \
    (op) == BDEV_IOCTL_NUM_BLOCKS ? (MICROPY_HW_SPIFLASH_PART1_BITS / 8 / FLASH_BLOCK_SIZE) : \
    (op) == BDEV_IOCTL_INIT ? spi_bdev_ioctl(&spi_bdev, (op), (uint32_t)&spiflash_config) : \
    spi_bdev_ioctl(&spi_bdev, (op), (arg)) \
)
#define MICROPY_HW_BDEV_READBLOCKS(dest, bl, n) spi_bdev_readblocks(&spi_bdev, (dest), (bl), (n))
#define MICROPY_HW_BDEV_WRITEBLOCKS(src, bl, n) spi_bdev_writeblocks(&spi_bdev, (src), (bl), (n))

bdev.c

#include "qspi.h"
#include "storage.h"

// External SPI flash uses standard SPI interface

STATIC const mp_soft_qspi_obj_t qspi_bus = {
    .cs  = MICROPY_HW_QSPIFLASH_CS,
    .clk = MICROPY_HW_QSPIFLASH_SCK,
    .io0 = MICROPY_HW_QSPIFLASH_IO0,
    .io1 = MICROPY_HW_QSPIFLASH_IO1,
    .io2 = MICROPY_HW_QSPIFLASH_IO2,
    .io3 = MICROPY_HW_QSPIFLASH_IO3,
};

STATIC mp_spiflash_cache_t spi_bdev_cache;

const mp_spiflash_config_t spiflash_config = {
    .bus_kind = MP_SPIFLASH_BUS_QSPI,
    .bus.u_qspi.data = (void*)&qspi_bus,
    .bus.u_qspi.proto = &qspi_proto,
    .cache = &spi_bdev_cache,
};

spi_bdev_t spi_bdev;

@dpgeorge

Copy link
Copy Markdown
Owner

Ok, thanks.

@dpgeorge

Copy link
Copy Markdown
Owner

This is now obsolete (it seems), VfsLfs1/2 are now part of master.

@dpgeorge dpgeorge closed this Dec 17, 2019
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

Successfully merging this pull request may close these issues.

3 participants