11/*
2- * Copyright (c) 2006-2022 , RT-Thread Development Team
2+ * Copyright (c) 2006-2018 , RT-Thread Development Team
33 *
44 * SPDX-License-Identifier: Apache-2.0
55 *
1313
1414#ifdef BSP_USING_FS
1515#if DFS_FILESYSTEMS_MAX < 4
16- #error "Please define DFS_FILESYSTEMS_MAX more than 4"
16+ #error "Please define DFS_FILESYSTEMS_MAX more than 4"
1717#endif
1818#if DFS_FILESYSTEM_TYPES_MAX < 4
19- #error "Please define DFS_FILESYSTEM_TYPES_MAX more than 4"
19+ #error "Please define DFS_FILESYSTEM_TYPES_MAX more than 4"
2020#endif
2121
22- #include <dfs_fs.h>
23-
24- #ifdef BSP_USING_SDCARD_FS
25- #include <board.h>
26- #include "drv_sdio.h"
27- #endif
2822#ifdef BSP_USING_SPI_FLASH_FS
29- #include "fal.h"
23+ #include "fal.h"
3024#endif
31- #define DBG_TAG "app.filesystem"
32- #define DBG_LVL DBG_INFO
33- #include <rtdbg.h>
34-
3525
26+ #include <dfs_fs.h>
3627#include "dfs_romfs.h"
28+ #include "drv_sdmmc.h"
3729
38- #ifdef RT_USING_DFS_ELMFAT
39- static const struct romfs_dirent _romfs_root [] =
40- {
41- {ROMFS_DIRENT_DIR , "flash" , RT_NULL , 0 },
42- {ROMFS_DIRENT_DIR , "sdcard" , RT_NULL , 0 },
43- {ROMFS_DIRENT_DIR , "filesystem" , RT_NULL , 0 }
44- };
45- #else
46- static const struct romfs_dirent _romfs_root [] =
47- {
48- {ROMFS_DIRENT_DIR , "flash" , RT_NULL , 0 },
49- {ROMFS_DIRENT_DIR , "sdcard" , RT_NULL , 0 }
50- };
51- #endif
30+ #define DBG_TAG "app.filesystem"
31+ #define DBG_LVL DBG_INFO
32+ #include <rtdbg.h>
5233
53- const struct romfs_dirent romfs_root =
54- {
55- ROMFS_DIRENT_DIR , "/" , (rt_uint8_t * )_romfs_root , sizeof (_romfs_root ) / sizeof (_romfs_root [0 ])
56- };
34+ static const struct romfs_dirent _romfs_root [] = {
35+ // {ROMFS_DIRENT_DIR, "flash", RT_NULL, 0},
36+ {ROMFS_DIRENT_DIR , "sdcard" , RT_NULL , 0 }};
5737
38+ const struct romfs_dirent romfs_root = {
39+ ROMFS_DIRENT_DIR , "/" , (rt_uint8_t * )_romfs_root , sizeof (_romfs_root ) / sizeof (_romfs_root [0 ])};
5840
5941#ifdef BSP_USING_SDCARD_FS
6042
6143/* SD Card hot plug detection pin */
62- #define SD_CHECK_PIN GET_PIN(D, 5 )
44+ #define SD_CHECK_PIN GET_PIN(N, 7 )
6345
6446static void _sdcard_mount (void )
6547{
6648 rt_device_t device ;
6749
68- device = rt_device_find ("sd" );
69-
50+ device = rt_device_find ("sd0" );
7051 if (device == NULL )
7152 {
7253 mmcsd_wait_cd_changed (0 );
73- sdcard_change ();
54+ stm32_mmcsd_change ();
7455 mmcsd_wait_cd_changed (RT_WAITING_FOREVER );
75- device = rt_device_find ("sd " );
56+ device = rt_device_find ("sd0 " );
7657 }
77-
7858 if (device != RT_NULL )
7959 {
80- if (dfs_mount ("sd " , "/sdcard" , "elm" , 0 , 0 ) == RT_EOK )
60+ if (dfs_mount ("sd0 " , "/sdcard" , "elm" , 0 , 0 ) == RT_EOK )
8161 {
8262 LOG_I ("sd card mount to '/sdcard'" );
8363 }
@@ -95,24 +75,21 @@ static void _sdcard_unmount(void)
9575 LOG_I ("Unmount \"/sdcard\"" );
9676
9777 mmcsd_wait_cd_changed (0 );
98- sdcard_change ();
78+ stm32_mmcsd_change ();
9979 mmcsd_wait_cd_changed (RT_WAITING_FOREVER );
10080}
10181
10282static void sd_mount (void * parameter )
10383{
10484 rt_uint8_t re_sd_check_pin = 1 ;
10585 rt_thread_mdelay (200 );
106-
10786 if (rt_pin_read (SD_CHECK_PIN ))
10887 {
10988 _sdcard_mount ();
11089 }
111-
11290 while (1 )
11391 {
11492 rt_thread_mdelay (200 );
115-
11693 if (!re_sd_check_pin && (re_sd_check_pin = rt_pin_read (SD_CHECK_PIN )) != 0 )
11794 {
11895 _sdcard_mount ();
@@ -129,54 +106,26 @@ static void sd_mount(void *parameter)
129106
130107int mount_init (void )
131108{
132- #ifdef RT_USING_DFS_ROMFS
133109 if (dfs_mount (RT_NULL , "/" , "rom" , 0 , & (romfs_root )) != 0 )
134110 {
135111 LOG_E ("rom mount to '/' failed!" );
136112 }
137- #endif
138-
139- #ifdef BSP_USING_SPI_FLASH_FS
113+ #ifdef BSP_USING_SPI_FLASH_FS
140114 struct rt_device * flash_dev = RT_NULL ;
141115
142- #ifndef RT_USING_WIFI
116+ #ifndef RT_USING_WIFI
143117 fal_init ();
144- #endif
118+ #endif
145119
146120 flash_dev = fal_mtd_nor_device_create ("filesystem" );
147121
148- #ifdef RT_USING_DFS_ELMFAT
149- flash_dev = fal_blk_device_create ("filesystem" );
150- if (flash_dev )
151- {
152- //mount filesystem
153- if (dfs_mount (flash_dev -> parent .name , "/filesystem" , "elm" , 0 , 0 ) != 0 )
154- {
155- LOG_W ("mount to '/filesystem' failed! try to mkfs %s" , flash_dev -> parent .name );
156- dfs_mkfs ("elm" , flash_dev -> parent .name );
157- if (dfs_mount (flash_dev -> parent .name , "/filesystem" , "elm" , 0 , 0 ) == 0 )
158- {
159- LOG_I ("mount to '/filesystem' success!" );
160- }
161- }
162- else
163- {
164- LOG_I ("mount to '/filesystem' success!" );
165- }
166- }
167- else
168- {
169- LOG_E ("Can't create block device filesystem or bt_image partition." );
170- }
171- #else
172122 if (flash_dev )
173123 {
174124 //mount filesystem
175125 if (dfs_mount (flash_dev -> parent .name , "/flash" , "lfs" , 0 , 0 ) != 0 )
176126 {
177127 LOG_W ("mount to '/flash' failed! try to mkfs %s" , flash_dev -> parent .name );
178128 dfs_mkfs ("lfs" , flash_dev -> parent .name );
179-
180129 if (dfs_mount (flash_dev -> parent .name , "/flash" , "lfs" , 0 , 0 ) == 0 )
181130 {
182131 LOG_I ("mount to '/flash' success!" );
@@ -189,20 +138,18 @@ int mount_init(void)
189138 }
190139 else
191140 {
192- LOG_E ("Can't create block device filesystem or bt_image partition." );
141+ LOG_E ("Can't create block device filesystem or bt_image partition." );
193142 }
194- #endif
195143
196- #endif
144+ #endif
197145
198- #ifdef BSP_USING_SDCARD_FS
146+ #ifdef BSP_USING_SDCARD_FS
199147 rt_thread_t tid ;
200148
201149 rt_pin_mode (SD_CHECK_PIN , PIN_MODE_INPUT_PULLUP );
202150
203151 tid = rt_thread_create ("sd_mount" , sd_mount , RT_NULL ,
204152 2048 , RT_THREAD_PRIORITY_MAX - 2 , 20 );
205-
206153 if (tid != RT_NULL )
207154 {
208155 rt_thread_startup (tid );
@@ -211,8 +158,7 @@ int mount_init(void)
211158 {
212159 LOG_E ("create sd_mount thread err!" );
213160 }
214-
215- #endif
161+ #endif
216162 return RT_EOK ;
217163}
218164INIT_APP_EXPORT (mount_init );
0 commit comments