参数配置
驱动配置
在 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
2
3
4
5
6
7
8
9
10
11
12
当使用 RT-Thread 内核的时候,SDMC 驱动需要依赖RT-Thread的 SDIO 设备驱动框架,也是在menuconfig界面中打开:
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
2
3
4
5
6
7
8
9
为了简化使用,Using SDMCx
会自动打开 RT-Thread 的 SDIO设备驱动框架。
SDMC 自定义参数
SDMC驱动在menuconfig中提供了一些扩展参数,方便客户根据板级硬件设计来进行调整。如下表:
SDMCx_DRV_PHASE 和 SDMCx_SMP_PHASE,分别用于调节发送、接收的信号相位,主要影响兼容性,Luban-Lite已经提供了调优后的配置,通常不需要修改。
D21x 默认配置
SDMC V1.0有三个接口:SDMC0、SDMC1、SDMC2,D21x 提供了3套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
2
3
4
5
6
7
8
9
10
11
12
文件系统配置
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
2
3
4
5
6
7
8
9
10
11
12
13
14
注意,上面的 Using mount table for file system
选项打开后,意味着可以系统启动后会根据一个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
2
3
4
5
6
7
8
9
10
Baremetal
Baremetal默认打开文件系统配置:
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
2
3
4
5
6
7
8
9
10
11
12
设备上电后会直接将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
2
3
4
热插拔配置
目前Luban-lite下只实现了SDMC1热插拔,用户可根据源码拓展至SDMC0/2中。路径:
RT-Thread: bsp/artinchip/drv/sdmc/drv_sdcard.c
Baremetal: bsp/artinchip/drv_bare/sdmc/sdcard.c
RT-Thread
Board options --->
[*] Using SDMC1
SDMC1 Parameter --->
[*] Using SDcard hotplug detection
2
3
4
Baremetal
Board options --->
[*] Using SDMC1
SDMC1 Parameter --->
[*] Using SDcard hotplug detection
2
3
4