Skip to content

Commit faf528b

Browse files
authored
[bsp][nxp] support qspi flash and filesystem for imxrt1180-evk board
1 parent b2e1f13 commit faf528b

13 files changed

Lines changed: 1036 additions & 5 deletions

File tree

bsp/nxp/imx/imxrt/imxrt1180-nxp-evk/README_zh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ CM33对CM7的kick off将在后续版本中支持。
2727
| **板载外设** | **支持情况** | **备注** |
2828
| :----------------- | :----------: | :------------------------------------|
2929
| USB 转串口 | 暂不支持 | |
30-
| SPI Flash | 暂不支持 | |
30+
| SPI Flash | 支持 | |
3131
| 以太网 | 暂不支持 | |
3232
| **片上外设** | **支持情况** | **备注** |
3333
| GPIO | 暂不支持 | |
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
scons.args: &scons
2+
scons_arg:
3+
- '--strict'
4+
5+
# ------ component CI ------
6+
7+
# ------ Peripheral CI ------
8+
Peripheral.flash_fs:
9+
<<: *scons
10+
kconfig:
11+
- CONFIG_BSP_USING_QSPI_FLASH_FS=y
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright (c) 2019-2024, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2026-06-02 CoreBoxer add LittleFS on QSPI NOR Flash (IMXRT1180-EVK)
9+
*/
10+
11+
#include <rtthread.h>
12+
13+
/* ====================================================================
14+
* QSPI NOR Flash LittleFS (controlled by BSP_USING_QSPI_FLASH_FS)
15+
*
16+
* Dependencies:
17+
* - drv_flash.c (Flash read/write/erase driver via ROM API)
18+
* - FAL framework (partition management)
19+
* - LittleFS component (RT-Thread package)
20+
*
21+
* FAL partition configuration (fal_cfg.h):
22+
* "filesystem" partition → filesystem area of norflash0
23+
*
24+
* Mount procedure:
25+
* 1. Find FAL partition to confirm correct configuration
26+
* 2. Create MTD NOR block device
27+
* 3. Try direct mount (for already formatted filesystem)
28+
* 4. If failed, perform mkfs then remount (first use or format scenario)
29+
* ==================================================================== */
30+
#ifdef BSP_USING_QSPI_FLASH_FS
31+
#include <dfs_fs.h>
32+
#include <fal.h>
33+
34+
#define FS_PARTITION_NAME "filesystem"
35+
#define FS_TYPE_NAME "lfs"
36+
#define FS_MOUNT_POINT "/"
37+
38+
static int _qspi_flash_fs_mount(void)
39+
{
40+
struct fal_mtd_nor_device *mtd_dev;
41+
int ret;
42+
43+
/* Find FAL partition to confirm configuration is correct */
44+
if (fal_partition_find(FS_PARTITION_NAME) == RT_NULL)
45+
{
46+
rt_kprintf("[qspi_fs] partition '%s' not found, check fal_cfg.h\n",
47+
FS_PARTITION_NAME);
48+
return -RT_ERROR;
49+
}
50+
51+
/* Create MTD NOR block device for filesystem partition */
52+
mtd_dev = (struct fal_mtd_nor_device *)fal_mtd_nor_device_create(FS_PARTITION_NAME);
53+
if (mtd_dev == RT_NULL)
54+
{
55+
rt_kprintf("[qspi_fs] failed to create MTD NOR device for '%s'\n",
56+
FS_PARTITION_NAME);
57+
return -RT_ERROR;
58+
}
59+
60+
/* Try direct mount (for already formatted flash) */
61+
ret = dfs_mount(FS_PARTITION_NAME, FS_MOUNT_POINT, FS_TYPE_NAME, 0, 0);
62+
if (ret == 0)
63+
{
64+
rt_kprintf("[qspi_fs] '%s' mounted at '%s'\n",
65+
FS_PARTITION_NAME, FS_MOUNT_POINT);
66+
return RT_EOK;
67+
}
68+
69+
/* Mount failed, indicating flash is not formatted (first use scenario), perform mkfs */
70+
rt_kprintf("[qspi_fs] mount failed (ret=%d), formatting '%s'...\n",
71+
ret, FS_PARTITION_NAME);
72+
73+
ret = dfs_mkfs(FS_TYPE_NAME, FS_PARTITION_NAME);
74+
if (ret != 0)
75+
{
76+
rt_kprintf("[qspi_fs] mkfs failed (ret=%d)\n", ret);
77+
return -RT_ERROR;
78+
}
79+
80+
/* Remount after successful mkfs */
81+
ret = dfs_mount(FS_PARTITION_NAME, FS_MOUNT_POINT, FS_TYPE_NAME, 0, 0);
82+
if (ret != 0)
83+
{
84+
rt_kprintf("[qspi_fs] mount failed after mkfs (ret=%d)\n", ret);
85+
return -RT_ERROR;
86+
}
87+
88+
rt_kprintf("[qspi_fs] '%s' formatted and mounted at '%s'\n",
89+
FS_PARTITION_NAME, FS_MOUNT_POINT);
90+
return RT_EOK;
91+
}
92+
INIT_APP_EXPORT(_qspi_flash_fs_mount);
93+
/*
94+
* FAL initialization registered as INIT_COMPONENT_EXPORT:
95+
* after Flash driver (INIT_DEVICE_EXPORT)
96+
* before filesystem mount (INIT_APP_EXPORT)
97+
*/
98+
INIT_COMPONENT_EXPORT(fal_init);
99+
100+
#endif /* BSP_USING_QSPI_FLASH_FS */

bsp/nxp/imx/imxrt/imxrt1180-nxp-evk/cm33/board/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,16 @@ menu "Onboard Peripheral Drivers"
229229
select BSP_USING_SDIO
230230
select RT_USING_DFS_ELMFAT
231231
default n
232+
233+
config BSP_USING_QSPI_FLASH_FS
234+
bool "Enable QSPI Flash (LittleFS)"
235+
select BSP_USING_FLEXSPI
236+
select BSP_USING_FLEXSPI1
237+
select RT_USING_FAL
238+
select FAL_PART_HAS_TABLE_CFG
239+
select RT_USING_MTD_NOR
240+
select PKG_USING_LITTLEFS
241+
default n
232242
endif
233243

234244
endmenu

bsp/nxp/imx/imxrt/imxrt1180-nxp-evk/cm33/board/SConscript

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ MCUX_Config/clock_config.c
1212
MCUX_Config/pin_mux.c
1313
""")
1414

15+
if GetDepend(['BSP_USING_QSPI_FLASH_FS']):
16+
src += ['ports/drv_flexspi_nor_flash.c', 'ports/fal_flash_port.c']
17+
1518
CPPPATH = [cwd,cwd + '/MCUX_Config',cwd + '/ports']
1619
CPPDEFINES = ['CPU_MIMXRT1189CVM8C_cm33', 'MCUXPRESSO_SDK', 'MCUX_META_BUILD', 'MIMXRT1189_cm33_SERIES', 'XIP_BOOT_HEADER_ENABLE=1', 'XIP_BOOT_HEADER_DCD_ENABLE=1', 'XIP_EXTERNAL_FLASH=1', 'ARM_MATH_CM33']
1720

bsp/nxp/imx/imxrt/imxrt1180-nxp-evk/cm33/board/linker_scripts/link.scf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ LR_m_text m_text_start m_text_size
173173

174174
ER_m_QuickAccessCode m_qacode_start m_qacode_size
175175
{
176+
fsl_flexspi.o (+RO-CODE)
176177
.ANY (CodeQuickAccess)
177178
}
178179

0 commit comments

Comments
 (0)