From 10494376837018ff26b7297d29e3b6913eced2b5 Mon Sep 17 00:00:00 2001 From: "@lin12345678" Date: Mon, 12 Jul 2021 14:28:10 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=8F=90=E4=BA=A4sdcard=20mount?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../applications/filesystem.c | 92 +++++++++++++++++++ bsp/imx6ull-artpi-smart/applications/mnt.c | 10 +- bsp/imx6ull-artpi-smart/applications/romfs.c | 11 +++ bsp/imx6ull-artpi-smart/drivers/drv_sdio.c | 5 + 4 files changed, 111 insertions(+), 7 deletions(-) create mode 100644 bsp/imx6ull-artpi-smart/applications/filesystem.c create mode 100644 bsp/imx6ull-artpi-smart/applications/romfs.c diff --git a/bsp/imx6ull-artpi-smart/applications/filesystem.c b/bsp/imx6ull-artpi-smart/applications/filesystem.c new file mode 100644 index 0000000000..21643263f6 --- /dev/null +++ b/bsp/imx6ull-artpi-smart/applications/filesystem.c @@ -0,0 +1,92 @@ +#include + +#include + +#define DBG_TAG "app.filesystem" +#define DBG_LVL DBG_INFO +#include + +static void _sdcard_mount(void) +{ + rt_device_t device; + + device = rt_device_find("sd0"); + if (device == NULL) + { + mmcsd_wait_cd_changed(0); + host_change(); + mmcsd_wait_cd_changed(RT_WAITING_FOREVER); + rt_thread_mdelay(10); + device = rt_device_find("sd0"); + } + if (device != RT_NULL) + { + if (dfs_mount("sd0", "/mnt", "elm", 0, 0) == RT_EOK) + { + LOG_I("sd card mount to '/mnt'"); + } + else + { + LOG_W("sd card mount to '/mnt' failed!"); + } + } +} + +static void _sdcard_unmount(void) +{ + rt_thread_mdelay(200); + dfs_unmount("/mnt"); + LOG_I("Unmount \"/mnt\""); + + mmcsd_wait_cd_changed(0); + host_change(); + mmcsd_wait_cd_changed(RT_WAITING_FOREVER); +} + +static void sd_mount(void *parameter) +{ + volatile unsigned int *IN_STATUS; + IN_STATUS = (volatile unsigned int *)rt_ioremap((void *)0x2190030, 4); + rt_thread_mdelay(20); + if (dfs_mount("sd0", "/mnt", "elm", 0, 0) == RT_EOK) + { + LOG_I("sd card mount to '/mnt'"); + } + else + { + LOG_W("sd card mount to '/mnt' failed!"); + } + while (1) + { + rt_thread_mdelay(200); + if (((*IN_STATUS >>6) & 0x1) == 1) + { + *IN_STATUS = 0x40; + _sdcard_mount(); + } + + if (((*IN_STATUS >>7) & 0x1) == 1) + { + *IN_STATUS = (0x80); + _sdcard_unmount(); + } + } +} + +int sd_task(void) +{ + + rt_thread_t tid; + tid = rt_thread_create("sd_mount", sd_mount, RT_NULL, + 2048, RT_THREAD_PRIORITY_MAX - 2, 20); + if (tid != RT_NULL) + { + rt_thread_startup(tid); + } + else + { + LOG_E("create sd_mount thread err!"); + } + return RT_EOK; +} + diff --git a/bsp/imx6ull-artpi-smart/applications/mnt.c b/bsp/imx6ull-artpi-smart/applications/mnt.c index b85f5b032e..3519ed71b4 100644 --- a/bsp/imx6ull-artpi-smart/applications/mnt.c +++ b/bsp/imx6ull-artpi-smart/applications/mnt.c @@ -17,17 +17,13 @@ int mnt_init(void) { rt_thread_mdelay(500); - if (dfs_mount("sd0", "/", "elm", 0, NULL) != 0) + if (dfs_mount(NULL, "/", "rom", 0, &romfs_root) != 0) { rt_kprintf("Dir / mount failed!\n"); return -1; } - else - { - mkdir("/romfs", 777); - mkdir("/flash", 777); - mkdir("/download", 777); - } + + sd_task(); rt_kprintf("file system initialization done!\n"); return 0; } diff --git a/bsp/imx6ull-artpi-smart/applications/romfs.c b/bsp/imx6ull-artpi-smart/applications/romfs.c new file mode 100644 index 0000000000..f098a76572 --- /dev/null +++ b/bsp/imx6ull-artpi-smart/applications/romfs.c @@ -0,0 +1,11 @@ +#include + +static const struct romfs_dirent _romfs_root[] = { + {ROMFS_DIRENT_DIR, "etc", RT_NULL, 0}, + {ROMFS_DIRENT_DIR, "mnt", RT_NULL, 0}, + {ROMFS_DIRENT_DIR, "bin", RT_NULL, 0} +}; + +const struct romfs_dirent romfs_root = { + ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_romfs_root, sizeof(_romfs_root) / sizeof(_romfs_root[0])}; + diff --git a/bsp/imx6ull-artpi-smart/drivers/drv_sdio.c b/bsp/imx6ull-artpi-smart/drivers/drv_sdio.c index ed0ebe0549..24f5c38b8d 100644 --- a/bsp/imx6ull-artpi-smart/drivers/drv_sdio.c +++ b/bsp/imx6ull-artpi-smart/drivers/drv_sdio.c @@ -695,4 +695,9 @@ err: } INIT_DEVICE_EXPORT(imxrt_mci_init); +void host_change(void) +{ + mmcsd_change(host1); +} + -- Gitee From 4b4552616df169ef644a8745d6d79c003fcc2259 Mon Sep 17 00:00:00 2001 From: "@lin12345678" Date: Mon, 12 Jul 2021 14:34:35 +0800 Subject: [PATCH 2/3] =?UTF-8?q?format=20=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../applications/filesystem.c | 22 +++++++++---------- bsp/imx6ull-artpi-smart/applications/mnt.c | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bsp/imx6ull-artpi-smart/applications/filesystem.c b/bsp/imx6ull-artpi-smart/applications/filesystem.c index 21643263f6..7fc7d47739 100644 --- a/bsp/imx6ull-artpi-smart/applications/filesystem.c +++ b/bsp/imx6ull-artpi-smart/applications/filesystem.c @@ -46,28 +46,28 @@ static void _sdcard_unmount(void) static void sd_mount(void *parameter) { volatile unsigned int *IN_STATUS; - IN_STATUS = (volatile unsigned int *)rt_ioremap((void *)0x2190030, 4); + IN_STATUS = (volatile unsigned int *)rt_ioremap((void *)0x2190030, 4); rt_thread_mdelay(20); - if (dfs_mount("sd0", "/mnt", "elm", 0, 0) == RT_EOK) - { - LOG_I("sd card mount to '/mnt'"); - } - else - { - LOG_W("sd card mount to '/mnt' failed!"); - } + if (dfs_mount("sd0", "/mnt", "elm", 0, 0) == RT_EOK) + { + LOG_I("sd card mount to '/mnt'"); + } + else + { + LOG_W("sd card mount to '/mnt' failed!"); + } while (1) { rt_thread_mdelay(200); if (((*IN_STATUS >>6) & 0x1) == 1) { - *IN_STATUS = 0x40; + *IN_STATUS = 0x40; _sdcard_mount(); } if (((*IN_STATUS >>7) & 0x1) == 1) { - *IN_STATUS = (0x80); + *IN_STATUS = (0x80); _sdcard_unmount(); } } diff --git a/bsp/imx6ull-artpi-smart/applications/mnt.c b/bsp/imx6ull-artpi-smart/applications/mnt.c index 3519ed71b4..278ecadfd8 100644 --- a/bsp/imx6ull-artpi-smart/applications/mnt.c +++ b/bsp/imx6ull-artpi-smart/applications/mnt.c @@ -23,7 +23,7 @@ int mnt_init(void) return -1; } - sd_task(); + sd_task(); rt_kprintf("file system initialization done!\n"); return 0; } -- Gitee From 5e2c7224eafea64c8c5c168f084c159434fcf6cf Mon Sep 17 00:00:00 2001 From: "@lin12345678" Date: Tue, 13 Jul 2021 11:43:55 +0800 Subject: [PATCH 3/3] =?UTF-8?q?format=20=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/imx6ull-artpi-smart/drivers/drv_sdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsp/imx6ull-artpi-smart/drivers/drv_sdio.c b/bsp/imx6ull-artpi-smart/drivers/drv_sdio.c index 24f5c38b8d..10fe3ed3f7 100644 --- a/bsp/imx6ull-artpi-smart/drivers/drv_sdio.c +++ b/bsp/imx6ull-artpi-smart/drivers/drv_sdio.c @@ -697,7 +697,7 @@ err: INIT_DEVICE_EXPORT(imxrt_mci_init); void host_change(void) { - mmcsd_change(host1); + mmcsd_change(host1); } -- Gitee