feat(storage/fatfs): restructure basic example

This commit is contained in:
Tomáš Rohlínek
2024-08-05 14:09:09 +02:00
committed by Tomas Rohlinek
parent f633839ece
commit 85b5869053
10 changed files with 28 additions and 26 deletions

View File

@@ -42,14 +42,6 @@ examples/storage/fatfs_advanced:
- if: IDF_TARGET != "esp32"
reason: only one target needed
examples/storage/fatfs_basic:
depends_components:
- fatfs
- vfs
disable_test:
- if: IDF_TARGET != "esp32"
reason: only one target needed
examples/storage/nvs_rw_blob:
depends_components:
- nvs_flash

View File

@@ -0,0 +1,9 @@
# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps
examples/storage/fatfs:
depends_components:
- fatfs
- vfs
disable_test:
- if: IDF_TARGET != "esp32"
reason: only one target needed

View File

@@ -1,5 +1,5 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | -------- | -------- | -------- |
# FATFS minimal example
@@ -29,15 +29,16 @@ Here is the example's console output:
```
...
I (339) example: Mounting FAT filesystem
I (339) example: Filesystem mounted
I (339) example: Opening file
I (729) example: File written
I (729) example: Reading file
I (739) example: Read from file: 'This is written by the device'
I (739) example: Unmounting FAT filesystem
I (849) example: Done
I (321) example: Mounting FAT filesystem
I (331) example: Filesystem mounted
I (331) example: Opening file
I (731) example: File written
I (731) example: Reading file
I (741) example: Read from file: 'Hello World!'
I (741) example: Unmounting FAT filesystem
I (851) example: Done
...
```
The logic of the example is contained in a [single source file](./main/fat_example_main.c),
The logic of the example is contained in a [single source file](./main/fatfs_getting_started_main.c),
and it should be relatively simple to match points in its execution with the log outputs above.

View File

@@ -0,0 +1,2 @@
idf_component_register(SRCS "fatfs_getting_started_main.c"
INCLUDE_DIRS ".")

View File

@@ -31,8 +31,8 @@ void app_main(void)
.use_one_fat = false, // Use only one FAT table (reduce memory usage), but decrease reliability of file system in case of power failure.
};
// Mount FATFS filesystem located on "storage" partition in read-write mode
esp_err_t err = esp_vfs_fat_spiflash_mount_rw_wl(base_path, "storage", &mount_config, &s_wl_handle);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to mount FATFS (%s)", esp_err_to_name(err));
return;
@@ -46,12 +46,12 @@ void app_main(void)
FILE *f = fopen(filename, "wb");
if (f == NULL) {
perror("fopen");
perror("fopen"); // Print reason why fopen failed
ESP_LOGE(TAG, "Failed to open file for writing");
return;
}
fprintf(f, "This is written by the device");
fprintf(f, "Hello World!\n");
fclose(f);
ESP_LOGI(TAG, "File written");

View File

@@ -6,12 +6,12 @@ from pytest_embedded import Dut
@pytest.mark.esp32
@pytest.mark.generic
def test_examples_fatfs_basic(dut: Dut) -> None:
def test_examples_fatfs_getting_started(dut: Dut) -> None:
dut.expect('example: Mounting FAT filesystem', timeout=90)
dut.expect('example: Filesystem mounted', timeout=90)
dut.expect('example: Opening file', timeout=90)
dut.expect('example: File written', timeout=90)
dut.expect('example: Reading file', timeout=90)
dut.expect('example: Read from file: \'This is written by the device\'', timeout=90)
dut.expect('example: Read from file: \'Hello World!\'', timeout=90)
dut.expect('example: Unmounting FAT filesystem', timeout=90)
dut.expect('example: Done', timeout=90)

View File

@@ -1,2 +0,0 @@
idf_component_register(SRCS "fat_example_main.c"
INCLUDE_DIRS ".")