Skip to content

Commit dcec6d3

Browse files
committed
Add repro example
1 parent f29377a commit dcec6d3

11 files changed

+156
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 2022 Lukasz Majewski, DENX Software Engineering GmbH
3+
* Copyright (c) 2024 STMicroelectronics
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
/delete-node/ &storage_partition;
8+
9+
&sdmmc1 {
10+
status = "okay";
11+
pinctrl-0 = <&sdmmc1_d0_pc8
12+
&sdmmc1_ck_pc12
13+
&sdmmc1_cmd_pd2>;
14+
15+
pinctrl-names = "default";
16+
17+
clocks = <&rcc STM32_CLOCK_BUS_AHB3 0x00010000>,
18+
<&rcc STM32_SRC_HSI48 SDMMC_SEL(0)>;
19+
};
20+
21+
/ {
22+
fstab {
23+
compatible = "zephyr,fstab";
24+
lfs1: lfs1 {
25+
compatible = "zephyr,fstab,littlefs";
26+
read-size = <32>;
27+
prog-size = <32>;
28+
cache-size = <256>;
29+
lookahead-size = <64>;
30+
block-cycles = <512>;
31+
partition = <&storage_partition>;
32+
mount-point = "/lfs1";
33+
};
34+
};
35+
};
36+
37+
&quadspi {
38+
pinctrl-0 = <&quadspi_clk_pf10 &quadspi_bk2_ncs_pc11
39+
&quadspi_bk2_io0_pe7 &quadspi_bk2_io1_pe8
40+
&quadspi_bk2_io2_pe9 &quadspi_bk2_io3_pe10>;
41+
pinctrl-names = "default";
42+
43+
flash-id = <2>;
44+
status = "okay";
45+
46+
mx25l25645g: qspi-nor-flash@90000000 {
47+
compatible = "st,stm32-qspi-nor";
48+
reg = <0x90000000 DT_SIZE_M(32)>; /* 256 Mbits */
49+
qspi-max-frequency = <50000000>;
50+
reset-gpios = <&gpiod 3 GPIO_ACTIVE_LOW>;
51+
reset-gpios-duration = <1>;
52+
spi-bus-width = <4>;
53+
status = "okay";
54+
55+
partitions {
56+
compatible = "fixed-partitions";
57+
#address-cells = <1>;
58+
#size-cells = <1>;
59+
60+
storage_partition: partition@0 {
61+
label = "storage";
62+
reg = <0 DT_SIZE_M(8)>;
63+
};
64+
};
65+
};
66+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# Copyright (c) 2022 Lukasz Majewski, DENX Software Engineering GmbH
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
CONFIG_MAIN_STACK_SIZE=2048
7+
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=8192
8+
9+
CONFIG_FS_LITTLEFS_FC_HEAP_SIZE=8192
10+
CONFIG_SDMMC_STM32_HWFC=y
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Copyright (c) 2021 Lukasz Majewski, DENX Software Engineering GmbH
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=8192
8+
9+
# Littlefs configuration to utilize QSPI operation
10+
CONFIG_FS_LITTLEFS_FC_HEAP_SIZE=8192
11+
12+
CONFIG_NOCACHE_MEMORY=y
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CONFIG_MAIN_STACK_SIZE=2048
2+
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=8192
3+
4+
CONFIG_FS_LITTLEFS_FC_HEAP_SIZE=8192
5+
CONFIG_SDMMC_STM32_HWFC=y
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
&sdmmc1 {
2+
status = "okay";
3+
pinctrl-0 = <
4+
&sdmmc1_d0_pc8
5+
&sdmmc1_ck_pc12
6+
&sdmmc1_cmd_pd2>;
7+
pinctrl-names = "default";
8+
};

samples/subsys/fs/fs_sample/prj.conf

+5
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ CONFIG_FILE_SYSTEM=y
44
CONFIG_FAT_FILESYSTEM_ELM=y
55
CONFIG_PRINTK=y
66
CONFIG_MAIN_STACK_SIZE=2048
7+
8+
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=8192
9+
CONFIG_SDMMC_STM32_HWFC=y
10+
CONFIG_DISK_DRIVER_SDMMC=y
11+
CONFIG_LOG_MODE_IMMEDIATE=y

samples/subsys/fs/fs_sample/src/main.c

+27-11
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ LOG_MODULE_REGISTER(main);
6363

6464
static int lsdir(const char *path);
6565
#ifdef CONFIG_FS_SAMPLE_CREATE_SOME_ENTRIES
66+
#define BUF_TO_WRITE_SIZE 512
67+
static const char buf_to_write[BUF_TO_WRITE_SIZE];
6668
static bool create_some_entries(const char *base_path)
6769
{
6870
char path[MAX_PATH];
@@ -83,21 +85,33 @@ static bool create_some_entries(const char *base_path)
8385
path[base] = 0;
8486
strcat(&path[base], SOME_FILE_NAME);
8587

86-
if (fs_open(&file, path, FS_O_CREATE) != 0) {
88+
if (fs_open(&file, path, FS_O_CREATE | FS_O_TRUNC | FS_O_WRITE) != 0) {
8789
LOG_ERR("Failed to create file %s", path);
8890
return false;
8991
}
92+
93+
for (int x = 0; x < 1024; x++) {
94+
int ret = fs_write(&file, buf_to_write, BUF_TO_WRITE_SIZE);
95+
if (ret < 0) {
96+
LOG_ERR("Failed to write: %d", ret);
97+
return false;
98+
} else if (ret < BUF_TO_WRITE_SIZE) {
99+
LOG_ERR("Incomplete write: %d/%d", ret, BUF_TO_WRITE_SIZE);
100+
return false;
101+
}
102+
}
103+
90104
fs_close(&file);
91105

92-
path[base] = 0;
93-
strcat(&path[base], SOME_DIR_NAME);
106+
// path[base] = 0;
107+
// strcat(&path[base], SOME_DIR_NAME);
94108

95-
if (fs_mkdir(path) != 0) {
96-
LOG_ERR("Failed to create dir %s", path);
97-
/* If code gets here, it has at least successes to create the
98-
* file so allow function to return true.
99-
*/
100-
}
109+
// if (fs_mkdir(path) != 0) {
110+
// LOG_ERR("Failed to create dir %s", path);
111+
// /* If code gets here, it has at least successes to create the
112+
// * file so allow function to return true.
113+
// */
114+
// }
101115
return true;
102116
}
103117
#endif
@@ -161,19 +175,21 @@ int main(void)
161175
return res;
162176
}
163177

164-
if (lsdir(disk_mount_pt) == 0) {
178+
// if (lsdir(disk_mount_pt) == 0) {
165179
#ifdef CONFIG_FS_SAMPLE_CREATE_SOME_ENTRIES
166180
if (create_some_entries(disk_mount_pt)) {
167181
lsdir(disk_mount_pt);
168182
}
169183
#endif
170-
}
184+
// }
171185
} else {
172186
printk("Error mounting disk.\n");
173187
}
174188

175189
fs_unmount(&mp);
176190

191+
printk("Finished.");
192+
177193
while (1) {
178194
k_sleep(K_MSEC(1000));
179195
}

samples/subsys/fs/littlefs/boards/nucleo_h743zi.overlay

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
&sdmmc1_cmd_pd2>;
1414

1515
pinctrl-names = "default";
16+
17+
clocks = <&rcc STM32_CLOCK_BUS_AHB3 0x00010000>,
18+
<&rcc STM32_SRC_HSI48 SDMMC_SEL(0)>;
1619
};
1720

1821
/ {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CONFIG_MAIN_STACK_SIZE=2048
2+
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=8192
3+
4+
CONFIG_FS_LITTLEFS_FC_HEAP_SIZE=8192
5+
CONFIG_SDMMC_STM32_HWFC=y
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
&sdmmc1 {
2+
status = "okay";
3+
pinctrl-0 = <
4+
&sdmmc1_d0_pc8
5+
&sdmmc1_ck_pc12
6+
&sdmmc1_cmd_pd2>;
7+
pinctrl-names = "default";
8+
};

samples/subsys/fs/littlefs/prj_blk.conf

+7
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,10 @@ CONFIG_FS_LITTLEFS_FMP_DEV=n
2020
CONFIG_APP_LITTLEFS_STORAGE_BLK_SDMMC=y
2121

2222
CONFIG_NOCACHE_MEMORY=y
23+
24+
25+
CONFIG_MAIN_STACK_SIZE=2048
26+
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=8192
27+
28+
CONFIG_FS_LITTLEFS_FC_HEAP_SIZE=8192
29+
CONFIG_SDMMC_STM32_HWFC=y

0 commit comments

Comments
 (0)