Today during my weekly NuttX Channel Live about porting NuttX to STM32F401RC-RS485 board we explained how to add support to SDCard and I commented that we could use the mkfatfs command to format the SDCard. However during our tests it failed:
nsh> mkfatfs /dev/mmcsd0
nsh: mkfatfs: mkfatfs failed: 23
nsh>
Looking the file nuttx/include/errno.h I saw that error -23 means ENFILE (“File table overflow”).
Then we look at mkfatfs help:
nsh> help mkfatfs
mkfatfs usage: mkfatfs [-F <fatsize>] [-r <rootdirentries>] <block-driver>
Initially I thought that fatsize was the size of FAT sector (i.e. 512 byter per sector) and my colleague Rodrigo thought it was the size of SDCard itself. So we tried 512 and bigger values, but it didn’t work.
Then Rodrigo looked at NuttX documentation and found the answer: it was the type of FAT: FAT16, FAT32, etc.
So we tried using “-F 32” and it worked:
nsh> mkfatfs -F 32 /dev/mmcsd0