This project aims to implement a hardware driver interacting with an SD Card using the microSD Click board. SD Cards support SDIO or SPI interfaces to communicate; this driver communicates via the SPI interface as SPI is widely available in embedded devices/micro-controllers.
This project integrates FatFS which is one of the most popular file system libraries. File system related abstraction is handled by FatFS, and lower-level functions like the media IO layer are provided by this project's source code. For more information about FatFS, see the following source.
The microSD Click communicates with the target microcontroller over SPI interface that corresponds to the pinout on the mikroBUS™ socket as shown below.
-
Or SiWx917 Wi-Fi 6 and Bluetooth LE 8 MB Flash SoC Pro Kit (BRD4002 + BRD4338A)
-
A microSD card, e.g. microSD card 32 GB with adapter
Note: A pull-up resistor (e.g., 100k) should be placed on the MISO.
-
If the BGM220P Explorer Kit is used:
The microSD Click board can be easily clicked into its place. During the assembly, be sure that the 45-degree corner of the board fits the 45-degree white line of the Explorer Kit.
-
If the SiWx917 Wi-Fi 6 and Bluetooth LE 8 MB Flash SoC Pro Kit is used:
Description BRD4338A GPIO BRD4002 Breakout Pad microSD Click Board Card Detection GPIO_46 P24 CD RTE_GSPI_MASTER_CLK_PIN GPIO_25 P25 SCK RTE_GSPI_MASTER_MISO_PIN GPIO_26 P27 SDO RTE_GSPI_MASTER_MOSI_PIN GPIO_27 P29 SDI RTE_GSPI_MASTER_CS0_PIN GPIO_28 P31 CS
You can either create a project based on an example project or start with an empty example project.
-
From the Launcher Home, add your device to My Products, click on it, and click on the EXAMPLE PROJECTS & DEMOS tab. Find the example project filtering by microsd.
-
Click Create button on the Third Party Hardware Drivers - microSD Click (Mikroe) example. Example project creation dialog pops up -> click Create and Finish and Project should be generated.
-
Build and flash this example to the board.
-
Create an "Empty C Project" for the your board using Simplicity Studio v5. Use the default project settings.
-
Copy the file
app/example/mikroe_microsd/app.c
into the project root folder (overwriting the existing file). -
Install the software components:
-
Open the .slcp file in the project.
-
Select the SOFTWARE COMPONENTS tab.
-
Install the following components:
If the BGM220P Explorer Kit is used:
- [Third Party Hardware Drivers] → [Storage] → [microSD - microSD Click (Mikroe)]
- [Third Party Hardware Drivers] → [Storage] → [FatFS - Generic FAT Filesystem]
- [Services] → [IO Stream] → [IO Stream: USART] → with the default instance name: vcom
- [Application] → [Utility] → [Log]
- [Application] → [Utility] → [Assert]
If the SiWx917 Wi-Fi 6 and Bluetooth LE 8 MB Flash SoC Pro Kit is used:
-
-
Build and flash the project to your device.
Note:
-
Make sure that the Third Party Hardware Drivers extension is installed. If not, follow this documentation.
-
SDK Extension must be enabled for the project to install "microSD - microSD Click (Mikroe)" component.
The driver is divided into a FatFs, a Media access interface, and an SPI platform. The FatFs layer is the Filesystem Layer independent of platforms and storage media, it is completely separated from the physical device, such as memory card, hard disk, or any type of storage device. The media access interface is not part of the FatFs module and it needs to be provided by the implementer. FatFs module controls the storage devices via a media access interface. The SPI platform layer provides integration to the host microcontroller hardware-dependent code.
The dependency diagram is shown below.
FatFS: provides various filesystem functions for the applications.
- File Access
- Directory Access
- File and Directory Management
- Volume Management and System Configuration
For more information about the APIs of the FatFS module, see the following source.
Storage Device Controls Generic Media: implements the generic media access interface by consuming device-specific storage device control implementations. Storage Device Controls SD Card: implements the storage device control interfaces specific to SD Card.
Storage Device Controls SD Card Platform: implements basic interfaces required by the upper Storage Device Control layer. It implements SPI byte, multibyte, exchange, and other required functions by consuming platform SPI interfaces. The SPI instance is configurable via a public interface. SPI instance should be provided by passing as a parameter of the sd_card_spi_init() function.
Silicon Labs Platform: implements the peripheral driver core.
This example demonstrates the basic features of the driver as shown below:
Use a terminal program, such as the Console that is integrated into Simplicity Studio or a third-party tool terminal like Tera Term to receive the logs from the virtual COM port. Make sure that A pull-up resistor (e.g., 100k) is placed on the MISO. You should expect a similar output to the one below.
Unmount the SD Card. Use a micro Card Reader to read files from the SD Card on your computer. You should expect a similar output to the one below.
To report bugs in the Application Examples projects, please create a new "Issue" in the "Issues" section of third_party_hw_drivers_extension repo. Please reference the board, project, and source files associated with the bug, and reference line numbers. If you are proposing a fix, also include information on the proposed fix. Since these examples are provided as-is, there is no guarantee that these examples will be updated to fix these issues.
Questions and comments related to these examples should be made by creating a new "Issue" in the "Issues" section of third_party_hw_drivers_extension repo.