SDIO

[中文]

1. Overview

SDIO hosts TF cards (FATFS) or acts as a slave Wi-Fi interface. As a host, the SDK integrates FATFS for file management; this document covers the CLI commands.

2. Code Path

  • CLI demo: components/bk_cli/cli_fatfs.c and components/fatfs/test_fatfs.c

  • Drivers: middleware/driver/sd_card/sd_card_driver.c and middleware/driver/sdio_host/sdio_host_driver.c

3. Configuration

Extensive macro list (FATFS, SD card clock, SDIO host/slave options, DMA, pin groups, etc.). Host use typically enables FATFS/SDCARD and disables SDIO DMA auto power-down; slave use enables SDIO channels, bidirectional mode, GDMA, GPIO interrupt, and optional debug/test features.

Example host configuration (excerpt):

CONFIG_FATFS=y
CONFIG_FATFS_SDCARD=y
CONFIG_SDCARD=y
CONFIG_SDCARD_DEFAULT_CLOCK_FREQ=14 # ≈20 MHz
CONFIG_SDIO_V2P0=y
CONFIG_SDIO_HOST=y
...

Example slave configuration (excerpt):

CONFIG_SDIO_SLAVE=y
CONFIG_SDIO_CHANNEL_EN=y
CONFIG_SDIO_BIDIRECT_CHANNEL_EN=y
CONFIG_SDIO_GDMA_EN=y
CONFIG_SDIO_V2P1=y
...

Pins (two selectable groups):

Function

Group 0

Group 1

CLK CMD DATA0 DATA1 DATA2 DATA3

GPIO2 GPIO3 GPIO4 GPIO5 GPIO10 GPIO11

GPIO14 GPIO15 GPIO16 GPIO17 GPIO18 GPIO19

Host mode reminders: - Add external 10 kΩ pull-ups. - Disable CONFIG_SDIO_GDMA_EN and auto power-down for timing.

4. CLI Commands (FATFS)

FATFS docs: http://elm-chan.org/fsw/ff/00index_e.html

Commands fatfstest for mount/unmount, scan, format, read/write/append, dump memory, and automated test.

DISK_NUMBER enum:

DISK_NUMBER_RAM = 0,
DISK_NUMBER_SDIO_SD = 1,
DISK_NUMBER_UDISK = 2,
DISK_NUMBER_FLASH = 3

5. Demo Steps

  1. Insert SD card; single-line wiring (GPIO2 CLK, GPIO3 CMD, GPIO4 D0, GPIO5 D1, GPIO10 D2, GPIO11 D3).

  2. Execute CLI commands (prefix with cpu1 for AP): - fatfstest M 1 – mount - fatfstest S 1 – scan files - fatfstest W 1 test.txt ... – write data - fatfstest R 1 test.txt 32 – read data - fatfstest A 1 autotest.txt 2222 1 0 – auto test - fatfstest D 1 dump.txt ... – dump memory to file - fatfstest F 1 – format

CLI logs show mount status, file listings, and read/write results.