Skip to content

Commit 72eefc4

Browse files
committed
bsp: artpi2: add sd card filesystem support.
Signed-off-by: stranding <[email protected]>
1 parent 1172726 commit 72eefc4

File tree

4 files changed

+51
-84
lines changed

4 files changed

+51
-84
lines changed

bsp/stm32/libraries/HAL_Drivers/drivers/SConscript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ if GetDepend(['BSP_USING_WDT']):
110110
src += ['drv_wdt.c']
111111

112112
if GetDepend(['BSP_USING_SDIO']):
113-
if GetDepend('SOC_SERIES_STM32H7') or GetDepend('SOC_SERIES_STM32F7') or GetDepend('SOC_SERIES_STM32L4') or GetDepend('SOC_SERIES_STM32L5'):
113+
if GetDepend('SOC_SERIES_STM32H7RS') or GetDepend('SOC_SERIES_STM32H7') or GetDepend('SOC_SERIES_STM32F7') or GetDepend('SOC_SERIES_STM32L4') or GetDepend('SOC_SERIES_STM32L5'):
114114
src += ['drv_sdmmc.c']
115115
else:
116116
src += ['drv_sdio.c']

bsp/stm32/libraries/HAL_Drivers/drivers/drv_sdmmc.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,11 @@ static void rthw_sdio_send_command(struct rthw_sdio *sdio, struct sdio_pkg *pkg)
269269
hsd->DTIMER = HW_SDIO_DATATIMEOUT;
270270
hsd->DLEN = data->blks * data->blksize;
271271
hsd->DCTRL = (get_order(data->blksize) << 4) | (data->flags & DATA_DIR_READ ? SDMMC_DCTRL_DTDIR : 0);
272-
hsd->IDMABASE0 = (rt_uint32_t)cache_buf;
272+
#ifndef SOC_SERIES_STM32H7RS
273+
hsd->IDMABASE0 = (rt_uint32_t)cache_buf;
274+
#else
275+
hsd->IDMABASER = (rt_uint32_t)cache_buf;
276+
#endif
273277
hsd->IDMACTRL = SDMMC_IDMA_IDMAEN;
274278
}
275279
/* config cmd reg */
@@ -648,7 +652,11 @@ struct rt_mmcsd_host *sdio_host_create(struct stm32_sdio_des *sdio_des)
648652
*/
649653
static rt_uint32_t stm32_sdio_clock_get(void)
650654
{
651-
return HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SDMMC);
655+
#ifndef SOC_SERIES_STM32H7RS
656+
return HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SDMMC);
657+
#else
658+
return HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SDMMC12);
659+
#endif
652660
}
653661

654662
void SDMMC1_IRQHandler(void)

bsp/stm32/stm32h7r7-artpi2/board/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ endmenu
3232

3333
menu "On-chip Peripheral Drivers"
3434

35+
config BSP_USING_SDIO
36+
bool "Enable SDIO"
37+
default n
38+
select RT_USING_SDIO
39+
if BSP_USING_SDIO
40+
config BSP_USING_SDIO1
41+
bool "Enable SDIO1"
42+
default n
43+
config BSP_USING_SDIO2
44+
bool "Enable SDIO2"
45+
default n
46+
endif
47+
3548
config BSP_USING_GPIO
3649
bool "Enable GPIO"
3750
select RT_USING_PIN

bsp/stm32/stm32h7r7-artpi2/board/port/filesystem.c

Lines changed: 27 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
*
@@ -13,71 +13,51 @@
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

6446
static 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

10282
static 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

130107
int 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
}
218164
INIT_APP_EXPORT(mount_init);

0 commit comments

Comments
 (0)