DE10-Nano: Writing and reading the SD card with a standalone program
Introduction
As a personal learning exercise, I wanted to read and write a plain text file on an SD card with a standalone C program. I decided on using the open source FatFs module library for this exercise because of its simplicity. Reading the documentation all I needed was to write the necessary vendor port code for some FatFs functions to support the Cyclone V SoC FPGA.
Thanks to Intel's HWLIB which provides the low-level functions for the SD/MMC controller and card commands, I was able to write the supporting code with little effort, resulting in these files diskio_c5_sdmmc.h & diskio_c5_sdmmc.c.
The complete FatFs for C5 example can be downloaded from here: fatfs_c5.
Running a debug session in Eclipse under Windows
I assume your computer is already setup with the required tools, but if not, have a look at my bare-metal tutorial.
Prepare a SD card containing a FAT partition. If your computer does not have SD card slot I recommend getting one of those cheap USB to SD card dongle from Ebay or Amazon. The easiest way to create a FAT partition is with Windows Disk Management tool.
Start by attaching the USB cable to the UART USB socket on the DE10-Nano, then open a serial terminal program such as PuTTY and connect to it with the correct COM port and settings.
Attached another USB cable, in this case to the USB-Blaster II socket, then open the project in Eclipse IDE for Embedded C/C++ Developers, and select Run/Debug Configurations... from the menu. In the pop-up dialog select the fatfs_c5_debug launch profile and click the Debug button:
By default, the debug session will stop at a breakpoint in main(), now insert the SD card into the card slot on DE10-Nano, then click the resume button in Eclipse, i.e. the green play icon on the toolbar:
Finally, you should be able to see the results in the serial terminal:
Document date: Rev 1: 15 Oct 2024