Modern microcontroller come with plenty of internal FLASH memory. On the other side, many high performance MCUs as the NXP i.MX RT are ‘flashless’, because the silicon process for high performance cores is not matching the FLASH memory technology, so they are using external serial SPI or Quad-SPI (QSPI) memory instead.
Why not using an external SPI FLASH for a ‘normal’ microcontroller too?
The typical usage of external SPI flash memory is using it to load or store data. With the addition of a small external device on the SPI bus I can easily add several MBytes of memory to the microcontroller. Such SPI memory devices are very inexpensive: I ordered a few breakout modules with Winbond W25Q128 (16 MByte) from AliExpress for $1.50 each. The device uses the following pins:
- VCC: 3.3V
- DO: SPI MISO
- DI: SPI MOSI
- CS: SPI Chip Select
A red LED on the breakout module indicates if the board is powered.
Usually I use micro-SD cards for logging data. They are easily available, provide nearly ‘unlimited’ storage and with the FatFS file system I can easily exchange data with the host. But it needs space on the PCB, the SD card socket needs to be accessible, the socket is a mechanical component and has its costs plus is not very reliable in an environment with vibrations and subject of corrosion. Using a FLASH chip might be the better solution.
I have created a driver with a command line interface: that way I can read/write data of the SPI FLASH memory device. An Eclipse example project is available on GitHub (check the links at the end of this article).
The example is running on an ARM Cortex-M4 from NXP (Kinetis K20DX128), but easily can be ported for any other microcontroller.
The project includes a command line shell:
With the shell I can read/write the serial flash:
The ‘status’ command gives information about the device found:
I have now a working driver for using the Winbond W25Q128 16 MByte serial/SPI flash chip. The driver is still in an early stage, and I might update it to support other Flash devices too. With the command line interface I can read/write the memory. In a next step I plan to use the memory with a file system, more about this in a future article. The project is available on GitHub (see links below).
Happy Winbonding 🙂
- Example project on GitHub: https://github.com/ErichStyger/mcuoneclipse/tree/master/Examples/KDS/tinyK20/tinyK20_LittleFS_W25Q128
- Winbond W25Q128 Datasheet: http://www.winbond.com/resource-files/w25q128jv%20spi%20revc%2011162016.pdf
- Serial Flash driver by Paul Stoffregen: https://github.com/PaulStoffregen/SerialFlash/blob/master/SerialFlashChip.cpp
- Winbond driver for STM32: https://github.com/RRPRIME/STM32/blob/master/libraries/winbondflash/winbondflash.cpp
- W25Q128 breakout module: https://www.aliexpress.com/item/1pc-W25Q128-NorFlash-Storage-Module-128Mbit-Flash-SPI-Interface-Control-Module/32852244173.html