Skip to main content

Hardware

The development board includes a µSD Card Connector. It is connected to the RP2040 through SPI1.

sdCard Connection

Software

For a quick start in developing on our development board, please refer to our sample code for SD Card. It will provide you with a convenient and efficient way to begin your development process.

Base Libraries

This code is implemented with reference to two repositories. Thanks to the authors and the open-source community for their contributions. The repositories used as a reference are:

Configuration

spi_t Configuration

The configuration values do not require changes in this context; however, it's essential to note that an SPI instance is established and configured by specifying the pinouts and baud rate using the spi_t object. This information is provided for general knowledge.

static spi_t spis[] = {  // One for each SPI.
{
.hw_inst = spi1, // SPI component
.miso_gpio = 12, // GPIO number (not pin number)
.mosi_gpio = 11,
.sck_gpio = 14,
.baud_rate = 1000 * 1000,
//.baud_rate = 25 * 1000 * 1000, // Actual frequency: 20833333.
}
};
info

Note that GPIO numbers used rather than pin numbers.

sd_card_t Configuration

// Hardware Configuration of the SD Card "objects"

static sd_card_t sd_cards[] = { // One for each SD card
{
.pcName = "0:", // Name used to mount device
.spi = &spis[0], // Pointer to the SPI driving this card
.ss_gpio = 13, // The SPI slave select GPIO for this SD card
.use_card_detect = false,
.card_detect_gpio = 15, // Card detect
.card_detected_true = -1 // What the GPIO read returns when a card is
// present. Use -1 if there is no card detect.
}};

This code snippet represents the hardware configuration of an SD card. Let's break down the different elements of the sd_card_t structure and their meanings:

pcName: This field represents the name used to mount the SD card device. In this case, the SD card will be mounted as "0:". In some operating systems or filesystems, devices like SD cards are represented as files, and this name serves as a unique identifier for the SD card.

spi: This field is a pointer to the SPI (Serial Peripheral Interface) driver that drives this specific SD card. SPI is a common communication protocol used to interface with SD cards.

ss_gpio: SPI Slave Select (SS) GPIO pin number. The Slave Select pin is used to select the target device (in this case, the SD card) on the SPI bus. By toggling this GPIO, the microcontroller signals to the SD card that it wants to communicate with it.

use_card_detect: A boolean flag indicating whether or not card detection functionality is used. If set to true, it means the system will monitor the presence of the SD card through the card_detect_gpio.

card_detect_gpio: The GPIO pin number used for card detection. If use_card_detect is true, the system will monitor the state of this GPIO to determine if an SD card is present or not.

card_detected_true: This field defines the value that the card_detect_gpio is expected to read when an SD card is detected. If the GPIO reads this value, it means a card is present. If card_detected_true is set to -1, it indicates that the card detection feature is not used, and the GPIO will not be checked for card presence.

Sample Code

In our sample code, we demonstrate the process of creating a text file and proficiently writing multiple sample lines into it. This approach exemplifies a common practice for working with file operations and data storage in various programming scenarios.

sdCard.webp