Marc's Public Blog - Arduino Hacking


All | Aquariums | Arduino | Btrfs | Cars | Cats | Clubbing | Computers | Diving | Dreamstate | Edc | Electronics | Exercising | Festivals | Flying | Halloween | Hbot | Hiking | Linux | Linuxha | Monuments | Museums | Oshkosh | Outings | Public | Rc | Sciencemuseums | Solar | Tfsf | Trips



>>> Back to post index <<<

2019/03/30 Using FatFS FFat on ESP32 Flash With Arduino
π 2019-03-30 01:01 in Arduino
FatFS on ESP32 wasn't well documented, or usable, so I learned about it, and made some changes to the esp32-arduino core:
  • https://github.com/espressif/arduino-esp32/pull/2623/files
  • https://github.com/marcmerlin/arduino-esp32
  • https://github.com/espressif/arduino-esp32/blob/170d204566bbee414f4059db99168974c69d166e/tools/partitions/noota_3gffat.csv
  • ffat,     data, fat,     0x111000,0x2EF000,

    If you pull https://github.com/espressif/arduino-esp32/ master and select esp32-dev, you will see easy to select partition splits for code vs FFat.

    More details here: https://github.com/marcmerlin/esp32_fatfsimage/blob/master/README.md , and at the top level, there is a pre-generated fatfsimage that lets you build a fatfs image:

    # replace 3004 with the size of your partition. In the 1/3MB split, the fatfs partition is 
    # 0x2EF000 = 3076096 .  3076096/1024 = 3004
    fatfsimage -l5 img.ffat 3004 datadir

    Once the image is built

    esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 write_flash  0x111000 img.ffat

    Example

    I put together some code you can run to verify the partition list and get a file listing: https://github.com/marcmerlin/esp32_fatfsimage/blob/master/arduino/ffat/ffat.ino .

    Here is the output:

    partition addr: 0x010000; size: 0x100000; label: app0
    partition addr: 0x009000; size: 0x005000; label: nvs
    partition addr: 0x00e000; size: 0x002000; label: otadata
    partition addr: 0x110000; size: 0x001000; label: eeprom
    partition addr: 0x111000; size: 0x2ef000; label: ffat
    

    Trying to mount ffat partition if present File system mounted Total space: 3018752 Free space: 1429504 Listing directory: /gifs64 FILE: /gifs64/ani-bman-BW.gif SIZE: 4061 FILE: /gifs64/087_net.gif SIZE: 46200 (...)

    More details and code here: https://github.com/marcmerlin/esp32_fatfsimage

    Memory Use

    The FFAT module uses 8KB plus 4KB per concurrent file that can be opened. By default, it allows 10 files to be opened, which means it uses 48KB. IF you want to reduce its memory use, you can tell it to only support one file, and you will save 36KB, leaving you with only 12KB used.
    if (!FFat.begin(0, "", 1)) die("Fat FS mount failed. Not enough RAM?");

    Newer Solution, Consider this Instead

    After I wrote all this, a better solution came up: https://github.com/lorol/arduino-esp32fs-plugin I recommend you install this instead and then grab a mkfatfs binary (it's a bit of a pain to build) from:

  • https://github.com/labplus-cn/mkfatfs/releases/tag/v2.0.1
  • https://github.com/labplus-cn/mkfatfs/releases/tag/v1.0
  • grab esp32fs.jar from https://github.com/lorol/arduino-esp32fs-plugin/releases
  • This will integrate with the arduino GUI and likely do what you want. That said, if you'd like to create your FatFS image from a makefile and upload it via esptool, then my repo explained above, does this fine.

    AnimatedGIFs

    I've then improved AnimatedGIFs to add support for FatFS/FFat which nicely fixes the short hangs I was getting with SPIFFS, which was ruining the animations:
  • https://github.com/marcmerlin/AnimatedGIFs
  • https://github.com/marcmerlin/AnimatedGIFs/commit/4356c81a5da76677d34c60d6dde74c5693870552

  • More pages: November 2024 June 2024 August 2023 June 2023 May 2023 April 2023 March 2022 January 2022 January 2021 December 2020 March 2020 January 2020 May 2019 April 2019 March 2019 January 2019 July 2018 May 2018 April 2018 January 2018 June 2017 April 2017 January 2017 February 2016 January 2015 September 2013 January 2012 December 2011 May 2011 January 2011

    >>> Back to post index <<<

    Contact Email