Using FatFS and MinINI with the NXP LPC55S16 EVK

For a research project we selected the NXP LPC55S16 but because it has due the silicon shortage it is not available probably for the next 52 weeks (yikes!) we can use the EVK Board.

The FatFS file system from Elm Chan is the de-facto file system for many embedded systems. As such it comes integrated with silicon vendor SDKs like the NXP MCUXpresso SDK. The problem is that the SDK only has examples for things on the board, and because that board does not have a SD card socket, no example for using FatFS with an SDK card is provided :-(. So I had to create one, and you can get it from GitHub.

Outline

This article shows how you can ad an SD card or breakout board to a NXP LPC55S16 microcontroller system using FatFS file system. Additionally it uses the MinINI middleware to store key-value pair in sections inside configuration files.

The project on GitHub uses the NXP LPC55S16 EVK Board. The LPC55S16 on the board is an ARM Cortex-M33 with 256 KByte Flash and 96 KByte RAM running at 150 MHz. It uses a LPC4433 based debug circuit and can be programmed as CMSIS-DAP (LinkServer) or Segger J-Link, or with any other external debug probe like the PEMicro Multilink.

LPC55S16 EVK

SD Card Breakout Board

In principle any SD or micro-SD card breakout board could be used as long as the logic levels are 3.3V. I’m using one from Pololu.

micro SD card breakout board (Source: Pololu.com)

The NXP LPC55S19-EVK board has all the needed connections on a connector:

SD Card Connection

In the above image, AN is connected to ‘Card Detect’. For VDD on the Pololu breakout I provided 3.3V instead of the 5V (otherwise the logic levels would be 5V which would be bad!).

Project

The project is using the Eclipse based NXP MCUXpresso IDE with the NXP MCUXpresso SDK and Configuration Tools.

The McuLib hosts FatFS, FreeRTOS and MinINI:

FatFS, FreeRTOS and MinINI

Card Detect

On the ‘Card Detect’ pin on the breakout board is high active and connected to PIO0_16. The pin is configured as below in IncludeMcuLibConfig.h:

#define McuFatFS_CONFIG_HAS_CARD_DETECT_PIN           (1)
#define McuFatFS_CONFIG_CARD_DETECT_GPIO              GPIO
#define McuFatFS_CONFIG_CARD_DETECT_PORT              0
#define McuFatFS_CONFIG_CARD_DETECT_PIN               16U
#define McuFatFS_CONFIG_CARD_DETECT_PULL              McuGPIO_PULL_DISABLE
#define McuFatFS_CONFIG_CARD_DETECT_IS_HIGH_ACTIVE    (1)

Everything else is handled by the GPIO driver used in McuFatFS_CardPins.c:

SD Card Pin Handling

FLEXCOMM SPI

The connection to the SD card breakout board is using FLEXCOMM/SPI with the pins muxed in the Pins Tool:

SPI Pin Muxing

The SPI driver is configured as below:

#define SDSPI_SPI_MASTER          SPI8
#define SDSPI_SPI_MASTER_IRQ      FLEXCOMM8_IRQn
#define SDSPI_SPI_MASTER_CLK_SRC  kCLOCK_Flexcomm8
#define SDSPI_SPI_MASTER_CLK_FREQ CLOCK_GetFlexCommClkFreq(8U)
#define SDSPI_SPI_SSEL            1
#define SDSPI_SPI_SPOL            kSPI_SpolActiveAllLow

FreeRTOS

The application runs with FreeRTOS. One task is dedicated to deal with card insert, file system mount and unmount and uses ‘Direct Task Notification‘.

FreeRTOS Tasks in the system

The DiskTask is dealing with card pins and automatically mounting/unmounting disks while the Shell task provides a command line interface.

MinINI

MinINI is a very versatile tool to read/write configuration data from a file system. It is configured to use the FatFS file system:

#define McuMinINI_CONFIG_FS                           McuMinINI_CONFIG_FS_TYPE_FAT_FS
MinINI Files

Shell and UART

The project uses both Segger RTT and the onboard UART and implements a command line interface.

On the board the Jumper JP9 needs to be removed and JP12 (the one left from JP3) needs to be installed. The UART Rx/Tx signals are available on JP3 (1: Rx to LPC, 2: Tx from LPC, 3: GND) and on the USB CDC connection.

Connect with a terminal or RTT to the board. The UART pins are muxed with the Pins Tool:

UART Pin Muxing

The ‘help’ command provides a list of commands to read and write data:

Help Command

Below the supported status information:

Status Command

With this one can use the application do work with the SD card or over the command line interface.

Summary

Unfortunately there are no SD Card examples in the SDK for the LPC55S16. Using the McuLib and the other drivers from the SDK I was able to get support for any SD card breakout or micro-SD breakout board: with the project above it only requires a few #defines to set up. That way I have FatFS including MinINI including command line interface running on the LPC55S16 board. I hope you find this useful and can use this potentially for your own project. All the files are open source and available on GitHub (see links below).

Happy FatFSing 🙂

6 thoughts on “Using FatFS and MinINI with the NXP LPC55S16 EVK

  1. Hey Erich,

    I did a FatFS project a few years ago and it’s a nice code base to work with and it’s easy to get things working for “most” SD Cards – I think you’re being wishful when you say “I was able to get support for any SD card”.

    I’m stating this because when I did this, eight years ago, there was a plethora of SD cards available with different operating parameters. Now there are even more as there is microSD (FAT16 and max size of 2GB), then SDHC (FAT32 and max size of 32GB), then SDXC (exFAT32 and max size of 2TB) and now we’re into SDUC (SDEXpress interface and up to 128TB). Along SDEXpress, there’s the SPI, One Wire and Four Wire interfaces for cards as well as different minimum data rate and block size requirements.

    I’m saying this because what I thought would be a simple job turned into an almost full time nightmare – it’s easy to get an SDHC card application running and assume you just need an SPI interface, but people use whatever is at hand and it’s amazing what they come up with – making things worse is the big vendors (Kingston in particular) just dump whatever cheap silicon they can find into the (mini, micro, standard) SD card package without any regard to compatibility with their existing product even though they ship the product out in the same retail packaging with the same SKU number.

    Honestly, if you pick something like SDHC (a mature technology) you’ll be lucky to have 80% of the cards out there work without different tweaks.

    Sorry, you can see I’m scarred.

    myke

    Liked by 1 person

    • Hi Mike,
      what I wanted to say is for any breakout board, not card. I’m well aware that there can be issues with consumer SD cards. That’s why I’m using industrial SD cards where reliability is key and where it really has to work. I have had bad experience with cheap or no-name consumer cards, even with branded consumer cards, including Kingston.
      Where I have used SD cards is not in a consumer but in a embedded environment where the SD card is provided or ‘controlled’. If something else is used there is as you say no guarantee that it will work.
      The same btw applies to USB MSD stacks and USB memory sticks: there can be too many failures, so I avoid that because even more problems.
      Erich

      Liked by 1 person

      • Heya,

        I suspect you use something like Swissbit? Just a guess ;^)

        Looking back at the article copy, the quotation I used in my post ends at the end of the line and that was what I keyed off of.

        Hopefully somebody won’t try your code with an SD Card they found in an old MP3 player and then complain that your application doesn’t work.

        Thanx for the article.

        Liked by 1 person

  2. Pingback: Key-Value pairs in FLASH Memory: file-system-less minINI | MCU on Eclipse

  3. Pingback: LittleFS File System with MCU Internal Flash Memory « Adafruit Industries – Makers, hackers, artists, designers and engineers!

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.