SDMC 配置
5 Dec 2024
Read time: 6 minute(s)
驱动配置
-
在 Luban-Lite 根目录下执行 scons --menuconfig,进入 menuconfig 的功能配置界面,按如下选择:
Board options ---> [ ] Using SDMC0 [*] Using SDMC1 [ ] Using SDMC2 [*] Enable the interrupt of SDMC SDMC1 Parameter ---> Select SDMC1 BUSWIDTH (sdmc 4-bit mode) ---> [ ] Using SDcard hotplug detection [ ] SDMC1 connect to a SDIO device (3) SDMC1 driver phase (0) SDMC1 sample phase (100000000) SDMC1 CMU clock frequency
-
当使用 RT-Thread 内核时,SDMC 驱动需要依赖 RT-Thread 的 SDIO 设备驱动框架,也是在 menuconfig 界面中打开,否则可略过:提示:
为了简化使用,Using SDMCx 会自动打开 RT-Thread 的 SDIO 设备驱动框架。
Rt-Thread options ---> RT-Thread Components ---> Device Drivers ---> [*] Using SD/MMC device driver (512) The stack size for sdio irq thread (15) The priority level value of sdio irq thread (8192) The stack size for mmcsd thread (22) The priority level value of mmcsd thread (16) mmcsd max partition
SDMC 自定义参数
SDMC 驱动在 menuconfig 中提供了下列扩展参数,方便用户根据板级硬件设计进行调整:
参数名称 | 类型 | 取值范围 | 功能说明 |
---|---|---|---|
SDMCx_BUSWIDTH1 | Boolean | 1 - 是,0 - 否 | 控制器 x 是否为 1 线模式 |
SDMCx_BUSWIDTH4 | Boolean | 1 - 是,0 - 否 | 控制器 x 是否为 4 线模式 |
SDMC0_BUSWIDTH8 | Boolean | 1 - 是,0 - 否 | SDMC0 是否支持 8 线 |
SDMCx_IS_SDIO | Boolean | 1 - 是,0 - 否 | 控制器 x 是否用到 SDIO 外设 |
SDMCx_DRV_PHASE | Integer | 0 - 3 | 控制器 x 驱动相位 |
SDMCx_SMP_PHASE | Integer | 0 - 3 | 控制器 x 采样相位 |
SDMCx_CLK_FREQ | Integer | 31500000 - 200000000 | 控制器 x 输入时钟频率范围 |
提示:
SDMCx_DRV_PHASE 和 SDMCx_SMP_PHASE 分别用于调节发送、接收的信号相位,会影响兼容性,Luban-Lite 提供了调优后的配置,通常不需要修改。
D21x 默认配置
SDMC V1.0 包含三个接口,分别为 SDMC0、SDMC1 和 SDMC2,D21x 提供了三套 SDMC
控制器,默认配置如下:
Board options --->
[ ] Using SDMC0
[*] Using SDMC1
[ ] Using SDMC2
[*] Enable the interrupt of SDMC
SDMC1 Parameter --->
Select SDMC1 BUSWIDTH (sdmc 4-bit mode) --->
[ ] Using SDcard hotplug detection
[ ] SDMC1 connect to a SDIO device
(3) SDMC1 driver phase
(0) SDMC1 sample phase
(100000000) SDMC1 CMU clock frequency
文件系统配置
-
RT-Thread如果有文件访问的场景,就需要打开相应的文件系统。以 FatFS 文件系统为例,需要打开 RT-Thread 中的 elm(即 FatFS)配置:
Rt-Thread options ---> RT-Thread Components ---> [*] DFS: device virtual file system ---> [*] Using posix-like functions, open/read/write/close [*] Using working directory (4) The maximal number of mounted file system (4) The maximal number of file system type (16) The maximal number of opened files [*] Using mount table for file system [*] Enable elm-chan fatfs elm-chan's FatFs, Generic FAT Filesystem Module ---> [ ] Using devfs for device objects [*] Enable ReadOnly file system on flash [ ] Enable RAM file system
注意,上面的 Using mount table for filesystem 选项打开后,意味着可以系统启动后会根据一个 Table 配置来自动挂载文件系统。该 Table 定义在 board.c 中:#ifdef RT_USING_DFS_MNTTABLE #include <dfs_fs.h> const struct dfs_mount_tbl mount_table[] = { #ifdef AIC_USING_SDMC1 {"sd0", "/sdcard", "elm", 0, 0, 0}, #endif {0} }; #endif
-
BaremetalBaremetal 默认打开文件系统配置:
Local packages options ---> Third-party packages options ---> [*] DFS: device virtual file system for baremetal mode ---> [*] Using posix-like functions, open/read/write/close (4) The maximal number of mounted file system (4) The maximal number of file system type (16) The maximal number of opened files [ ] Using mount table for file system [*] Enable elm-chan fatfs elm-chan's FatFs, Generic FAT Filesystem Module ---> [ ] Enable ReadOnly file system on flash [ ] Enable RAM file system
设备上电后会直接将 Baremetal SDMC 设备自动挂载在根目录下。此部分定义在 main.c 中:#if defined(LPKG_USING_DFS_ELMFAT) && defined(AIC_SDMC_DRV) if (dfs_mount("sdmc", "/", "elm", 0, 0) < 0) pr_err("Failed to mount sdmc with FatFS\n"); #endif
热插拔配置
目前 Luban-Lite 下只实现了 SDMC1 热插拔,用户可根据源码拓展至 SDMC0/2 中:
- RT-Thread: bsp/artinchip/drv/sdmc/drv_sdcard.cRT-Thread
Board options ---> [*] Using SDMC1 SDMC1 Parameter ---> [*] Using SDcard hotplug detection
- Baremetal: bsp/artinchip/drv_bare/sdmc/sdcard.cBaremetal
Board options ---> [*] Using SDMC1 SDMC1 Parameter ---> [*] Using SDcard hotplug detection