1
6
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
110
111
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
134
135
136
137
138
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
164
165
166
167
168
169
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
201
202
203
204
205
206
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
258
259
260
261
262
263
264
265
266
267
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
300
301
302
303
314
315
316
317
318
319
320
321
322
323
324
/* ... */
/* ... */
#include <stdio.h>
#include <stdbool.h>
#include <sys/time.h>
#include "esp_err.h"
#include "esp_log.h"
#include "esp_check.h"
#include "esp_partition.h"
#include "esp_vfs_fat.h"
#include "esp_spiffs.h"
#include "wear_levelling.h"
#include "esp_littlefs.h"
#include "sdkconfig.h"
#include "perf_benchmark_example_tests.h"
#include "perf_benchmark_example_sd_utils.h"14 includes
static const char *TAG = "example";
#ifdef CONFIG_EXAMPLE_TEST_SPIFLASH
static const char *flash_partition_label = "storage";
#endif
wl_handle_t s_wl_handle = WL_INVALID_HANDLE;
void test_spiflash_raw(void);
void test_spiflash_fatfs(void);
void test_spiflash_spiffs(void);
void test_spiflash_littlefs(void);
void test_sd_raw(void);
void test_sd_fatfs(void);
void test_sd_littlefs(void);
void app_main(void)
{
ESP_LOGI(TAG, "Starting benchmark test with target size %d bytes", CONFIG_EXAMPLE_TARGET_RW_SIZE);
#ifdef CONFIG_EXAMPLE_TEST_SPIFLASH
ESP_LOGI(TAG, "Internal flash test");
#ifdef CONFIG_EXAMPLE_TEST_SPIFLASH_RAW
test_spiflash_raw();
#endif
#ifdef CONFIG_EXAMPLE_TEST_SPIFLASH_FATFS
test_spiflash_fatfs();
#endif
#ifdef CONFIG_EXAMPLE_TEST_SPIFLASH_SPIFFS
test_spiflash_spiffs();
#endif
#ifdef CONFIG_EXAMPLE_TEST_SPIFLASH_LITTLEFS
test_spiflash_littlefs();
#endif
/* ... */
#endif
#ifdef CONFIG_EXAMPLE_TEST_SD_CARD
ESP_LOGI(TAG, "SD card test");
ESP_LOGI(TAG, "Initializing SD card");
init_sd_config(&host_g, &slot_config_g, EXAMPLE_SD_FREQ);
#ifdef CONFIG_EXAMPLE_TEST_SD_CARD_RAW
test_sd_raw();
#endif
#ifdef CONFIG_EXAMPLE_TEST_SD_CARD_FATFS
test_sd_fatfs();
#endif
#ifdef CONFIG_EXAMPLE_TEST_SD_CARD_LITTLEFS
test_sd_littlefs();
#endif
/* ... */
#endif
}{ ... }
#if CONFIG_EXAMPLE_TEST_SPIFLASH
#ifdef CONFIG_EXAMPLE_TEST_SPIFLASH_RAW
void test_spiflash_raw(void)
{
esp_err_t ret = ESP_OK;
ESP_LOGI(TAG, "Mountig WL layer...");
const esp_partition_t *data_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA,
ESP_PARTITION_SUBTYPE_DATA_UNDEFINED, flash_partition_label);
if (data_partition == NULL) {
ESP_LOGE(TAG, "Could not find partition \"%s\"", flash_partition_label);
ESP_ERROR_CHECK(ESP_ERR_NOT_FOUND);
}{...}
ret = wl_mount(data_partition, &s_wl_handle);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to mount wear levelling layer, ret = %i", ret);
ESP_ERROR_CHECK(ret);
}{...}
ESP_LOGI(TAG, "WL layer mounted");
spiflash_speed_test_raw_run(CONFIG_EXAMPLE_TEST_TRIES);
ret = wl_unmount(s_wl_handle);
ESP_ERROR_CHECK(ret);
ESP_LOGI(TAG, "WL layer unmounted");
}{ ... }
/* ... */#endif
#ifdef CONFIG_EXAMPLE_TEST_SPIFLASH_FATFS
void test_spiflash_fatfs(void)
{
esp_err_t ret = ESP_OK;
esp_vfs_fat_sdmmc_mount_config_t mount_config_spiflash = {
.format_if_mount_failed = true,
.max_files = 5,
.allocation_unit_size = CONFIG_EXAMPLE_FATFS_SPIFLASH_CLUSTER_SIZE,
}{...};
ESP_LOGI(TAG, "Mounting FATFS partition, with cluster size %d bytes", mount_config_spiflash.allocation_unit_size);
ret = esp_vfs_fat_spiflash_mount_rw_wl(FLASH_BASE_PATH, flash_partition_label, &mount_config_spiflash, &s_wl_handle);
if (ret == ESP_OK) {
ESP_LOGI(TAG, "FATFS mounted to %s", FLASH_BASE_PATH);
}{...} else {
ESP_LOGE(TAG, "Failed to mount FATFS (%s)", esp_err_to_name(ret));
ESP_ERROR_CHECK(ret);
}{...}
spiflash_speed_test_fatfs_run(CONFIG_EXAMPLE_TEST_TRIES);
ret = esp_vfs_fat_spiflash_unmount_rw_wl(FLASH_BASE_PATH, s_wl_handle);
ESP_ERROR_CHECK(ret);
ESP_LOGI(TAG, "FATFS partition unmounted");
}{ ... }
/* ... */#endif
#ifdef CONFIG_EXAMPLE_TEST_SPIFLASH_SPIFFS
void test_spiflash_spiffs(void)
{
esp_err_t ret = ESP_OK;
ESP_LOGI(TAG, "Mounting SPIFFS partition...");
esp_vfs_spiffs_conf_t conf = {
.base_path = FLASH_BASE_PATH,
.partition_label = flash_partition_label,
.max_files = 5,
.format_if_mount_failed = true}{...};
ret = esp_vfs_spiffs_register(&conf);
if (ret == ESP_OK) {
ESP_LOGI(TAG, "SPIFFS mounted to %s", FLASH_BASE_PATH);
}{...} else {
if (ret == ESP_FAIL) {
ESP_LOGE(TAG, "Failed to mount or format filesystem");
}{...} else if (ret == ESP_ERR_NOT_FOUND) {
ESP_LOGE(TAG, "Failed to find SPIFFS partition");
}{...} else {
ESP_LOGE(TAG, "Failed to initialize SPIFFS (%s)", esp_err_to_name(ret));
}{...}
ESP_ERROR_CHECK(ret);
}{...}
spiflash_speed_test_spiffs_run(1);
ret = esp_vfs_spiffs_unregister(conf.partition_label);
ESP_ERROR_CHECK(ret);
ESP_LOGI(TAG, "SPIFFS partition unmounted");
}{ ... }
/* ... */#endif
#ifdef CONFIG_EXAMPLE_TEST_SPIFLASH_LITTLEFS
void test_spiflash_littlefs(void)
{
esp_err_t ret = ESP_OK;
ESP_LOGI(TAG, "Mounting LittleFS partition...");
esp_vfs_littlefs_conf_t conf = {
.base_path = FLASH_BASE_PATH,
.partition_label = flash_partition_label,
.format_if_mount_failed = true,
}{...};
ret = esp_vfs_littlefs_register(&conf);
if (ret == ESP_OK) {
ESP_LOGI(TAG, "LittleFS mounted to %s", FLASH_BASE_PATH);
}{...} else {
if (ret == ESP_FAIL) {
ESP_LOGE(TAG, "Failed to mount or format filesystem");
}{...} else if (ret == ESP_ERR_NOT_FOUND) {
ESP_LOGE(TAG, "Failed to find LittleFS partition");
}{...} else {
ESP_LOGE(TAG, "Failed to initialize LittleFS (%s)", esp_err_to_name(ret));
}{...}
}{...}
spiflash_speed_test_littlefs_run(CONFIG_EXAMPLE_TEST_TRIES);
ret = esp_vfs_littlefs_unregister(conf.partition_label);
ESP_ERROR_CHECK(ret);
ESP_LOGI(TAG, "LittleFS partition unmounted");
}{ ... }
/* ... */#endif /* ... */
#endif
#ifdef CONFIG_EXAMPLE_TEST_SD_CARD
#ifdef CONFIG_EXAMPLE_TEST_SD_CARD_RAW
void test_sd_raw(void)
{
esp_err_t ret = ESP_OK;
sdmmc_card_t *card;
ESP_LOGI(TAG, "Mounting SD card - raw access");
ret = init_sd_card(&card);
ESP_ERROR_CHECK(ret);
sdcard_speed_test_raw_run(card, CONFIG_EXAMPLE_TEST_TRIES);
deinit_sd_card(&card);
ESP_LOGI(TAG, "SD card unmounted - raw access");
}{ ... }
/* ... */#endif
#ifdef CONFIG_EXAMPLE_TEST_SD_CARD_FATFS
void test_sd_fatfs(void)
{
esp_err_t ret = ESP_OK;
sdmmc_card_t *card;
esp_vfs_fat_sdmmc_mount_config_t mount_config_sdcard = {
.format_if_mount_failed = true,
.max_files = 5,
.allocation_unit_size = CONFIG_EXAMPLE_FATFS_SD_CARD_CLUSTER_SIZE,
}{...};
ESP_LOGI(TAG, "Mounting SD card - FATFS, with cluster size %d bytes", mount_config_sdcard.allocation_unit_size);
#ifdef CONFIG_EXAMPLE_USE_SDMMC
ret = esp_vfs_fat_sdmmc_mount(SD_BASE_PATH, &host_g, &slot_config_g, &mount_config_sdcard, &card);
#else
ret = esp_vfs_fat_sdspi_mount(SD_BASE_PATH, &host_g, &slot_config_g, &mount_config_sdcard, &card);
#endif
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to initialize the card (%s). "
"Make sure SD card lines have pull-up resistors in place.",
esp_err_to_name(ret));
ESP_ERROR_CHECK(ret);
}{...}
sdmmc_card_print_info(stdout, card);
ESP_LOGI(TAG, "SD card mounted - FATFS");
sdcard_speed_test_fatfs_run(CONFIG_EXAMPLE_TEST_TRIES);
esp_vfs_fat_sdcard_unmount(SD_BASE_PATH, card);
ESP_LOGI(TAG, "SD card unmounted - FATFS");
}{ ... }
/* ... */#endif
#ifdef CONFIG_EXAMPLE_TEST_SD_CARD_LITTLEFS
void test_sd_littlefs(void)
{
esp_err_t ret = ESP_OK;
sdmmc_card_t *card;
ESP_LOGI(TAG, "Mounting SD card - LittleFS");
ret = init_sd_card(&card);
ESP_ERROR_CHECK(ret);
esp_vfs_littlefs_conf_t conf = {
.base_path = SD_BASE_PATH,
.sdcard = card,
.format_if_mount_failed = true,
}{...};
ret = esp_vfs_littlefs_register(&conf);
if (ret == ESP_OK) {
ESP_LOGI(TAG, "LittleFS mounted to %s", SD_BASE_PATH);
}{...} else {
if (ret == ESP_FAIL) {
ESP_LOGE(TAG, "Failed to mount or format filesystem");
}{...} else if (ret == ESP_ERR_NOT_FOUND) {
ESP_LOGE(TAG, "Failed to find LittleFS partition");
}{...} else {
ESP_LOGE(TAG, "Failed to initialize LittleFS (%s)", esp_err_to_name(ret));
}{...}
}{...}
ESP_LOGI(TAG, "SD card mounted - LittleFS");
sdcard_speed_test_littlefs_run(CONFIG_EXAMPLE_TEST_TRIES);
esp_vfs_littlefs_unregister_sdmmc(card);
deinit_sd_card(&card);
ESP_LOGI(TAG, "SD card unmounted - LittleFS");
}{ ... }
/* ... */#endif /* ... */
#endif