Marc's Public Blog - Arduino Hacking

All | Aquariums | Arduino | Btrfs | Cars | Cats | Clubbing | Computers | Dining | Diving | Electronics | Exercising | Festivals | Flying | Halloween | Hbot | Hiking | Linux | Linuxha | Mexico | Monuments | Museums | 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:
  • ffat,     data, fat,     0x111000,0x2EF000,

    If you pull master and select esp32-dev, you will see easy to select partition splits for code vs FFat.

    More details here: , 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 --chip esp32 --port /dev/ttyUSB0 --baud 921600 write_flash  0x111000 img.ffat


    I put together some code you can run to verify the partition list and get a file listing: .

    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:

    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: I recommend you install this instead and then grab a mkfatfs binary (it's a bit of a pain to build) from:

  • grab esp32fs.jar from
  • 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.


    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:

  • More pages: August 2023 June 2023 May 2023 March 2022 January 2022 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