Code Monkey home page Code Monkey logo

spiffs-stm32's Introduction

SPIFFS Example (Base On STM32L4 DISCO)


Advantage:

  • Small (embedded) targets, sparse RAM without heap
  • Only big areas of data (blocks) can be erased
  • An erase will reset all bits in block to ones
  • Writing pulls one to zeroes
  • Zeroes can only be pulled to ones by erase
  • Wear leveling
  • Cache
  • Garbage Collecting

Disadvantages:

  • Non-Support For PC
  • Execution time uncertainty
  • Maximum partition only support up to 128MByte

[How to Build]

  • Keil UV5.24.2.0 or later
  • STM32L476 DISCO
  • Jlink-OB for RTT Debugger (It is free.)

My configuration

  • Debug method:Segger RTT
  • Cache For Read
  • Cache For Write[Unexpected power-lost has an impact on this.]
  • Cache Statistics
  • Garbage Collecting
  • Flash Magic signature[Easy to detect new Flash]
  • Mutex[You can migrate the operating system Mutex API.It is so easy.]
  • Single partition
  • Flash Size:16MB
  • Flash Sector:64K
  • Flash SubSector:4KB
  • Flash Page:256Bytes
  • SPIFFS Cache:(256 + 32) * 4 Bytes

Main Code

void SPIFFS_Main(void)
{
    SEGGER_RTT_Init();

    BSP_QSPI_Init();

    cfg.hal_erase_f = _spiffs_erase;
    cfg.hal_read_f = _spiffs_read;
    cfg.hal_write_f = _spiffs_write;

    if ((res = SPIFFS_mount(&fs,
                            &cfg,
                            FS_Work_Buf,
                            FS_FDS, sizeof(FS_FDS),
                            FS_Cache_Buf, sizeof(FS_Cache_Buf),
                            NULL)) != SPIFFS_OK &&
            SPIFFS_errno(&fs) == SPIFFS_ERR_NOT_A_FS)
    {
        SEGGER_RTT_printf("formatting spiffs...\n");
        if (SPIFFS_format(&fs) != SPIFFS_OK)
        {
            SEGGER_RTT_printf("SPIFFS format failed: %d\n", SPIFFS_errno(&fs));
        }
        SEGGER_RTT_printf("ok\n");
        SEGGER_RTT_printf("mounting\n");
        res = SPIFFS_mount(&fs,
                           &cfg,
                           FS_Work_Buf,
                           FS_FDS, sizeof(FS_FDS),
                           FS_Cache_Buf, sizeof(FS_Cache_Buf),
                           NULL);
    }
    if (res != SPIFFS_OK)
    {
        SEGGER_RTT_printf("SPIFFS mount failed: %d\n", SPIFFS_errno(&fs));
    }
    else
    {
        SEGGER_RTT_printf("SPIFFS mounted\n");
    }
    SEGGER_RTT_printf("errno %d\n", SPIFFS_errno(&fs));



    for(;;)
    {
        spiffs_file fd = SPIFFS_open(&fs, "my_file", SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0);
        SEGGER_RTT_printf("errno %d\n", SPIFFS_errno(&fs));
        if (SPIFFS_write(&fs, fd, WriteBuf, sizeof(WriteBuf)) < 0)
            SEGGER_RTT_printf("errno %d\n", SPIFFS_errno(&fs));
        SPIFFS_close(&fs, fd);

        fd = SPIFFS_open(&fs, "my_file", SPIFFS_RDWR, 0);
        if (SPIFFS_read(&fs, fd, ReadBuf, sizeof(WriteBuf)) < 0)
            SEGGER_RTT_printf("errno %d\n", SPIFFS_errno(&fs));
        SPIFFS_close(&fs, fd);
        LL_mDelay(1000);
        SPIFFS_info(&fs, &total, &used_space);
        SEGGER_RTT_printf("mybuf = %s\n", ReadBuf);
    }
}

spiffs-stm32's People

Contributors

nickfox-taterli avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.