-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: fs: enable fstab devicetree integration for fatfs
Added tests in order to verify the functionality of the newly added fatfs fstab integration. Signed-off-by: Carlo Kirchmeier <[email protected]>
- Loading branch information
Showing
6 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright (c) 2025 Endress+Hauser AG | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(fatfs_fstab_sample) | ||
|
||
FILE(GLOB app_sources src/*.c) | ||
target_sources(app PRIVATE ${app_sources}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
.. zephyr:code-sample:: fatfs-fstab | ||
:name: Fatfs filesystem fstab | ||
:relevant-api: file_system_api | ||
|
||
Define fatfs filesystems in the devicetree. | ||
|
||
Overview | ||
*********** | ||
|
||
This sample shows how to define a fatfs fstab entry in the devicetree. | ||
This scenario uses a fatfs on a RAM disk. The sample is run on the | ||
:zephyr:board:`native_sim` board. | ||
|
||
Building and running | ||
******************** | ||
|
||
To run this sample, build it for the :zephyr:board:`native_sim` board | ||
and afterwards run the generated executable file within the build folder. | ||
|
||
The RAM disk sample for the :zephyr:board:`native_sim` board can be built as follows: | ||
|
||
.. zephyr-app-commands:: | ||
:zephyr-app: samples/subsys/fs/fatfs-fstab | ||
:host-os: unix | ||
:board: native_sim | ||
:gen-args: -DDTC_OVERLAY_FILE=fatfs_fstab.overlay | ||
:goals: build | ||
:compact: | ||
|
||
Sample Output | ||
============= | ||
|
||
When the sample runs successfully you should see following message on the screen: | ||
.. code-block:: console | ||
I: Filesystem access successful |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (c) 2025 Endress+Hauser AG | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/ { | ||
fstab { | ||
compatible = "zephyr,fstab"; | ||
ffs1: ffs1 { | ||
compatible = "zephyr,fstab,fatfs"; | ||
automount; | ||
disk-access; | ||
mount-point = "/RAM"; | ||
}; | ||
}; | ||
|
||
ramdisk0 { | ||
compatible = "zephyr,ram-disk"; | ||
disk-name = "RAM"; | ||
sector-size = <512>; | ||
sector-count = <128>; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CONFIG_DISK_ACCESS=y | ||
CONFIG_DISK_DRIVERS=y | ||
|
||
CONFIG_LOG=y | ||
CONFIG_LOG_MODE_MINIMAL=y | ||
|
||
CONFIG_FILE_SYSTEM=y | ||
CONFIG_FILE_SYSTEM_MKFS=y | ||
CONFIG_FAT_FILESYSTEM_ELM=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
sample: | ||
name: fatfs fstab sample | ||
tests: | ||
sample.filesystem.fat_fs.fstab: | ||
platform_allow: | ||
- native_sim | ||
extra_args: | ||
- EXTRA_DTC_OVERLAY_FILE="fatfs_fstab.overlay" | ||
tags: filesystem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (c) 2025 Endress+Hauser AG | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <ff.h> | ||
#include <zephyr/device.h> | ||
#include <zephyr/fs/fs.h> | ||
#include <zephyr/kernel.h> | ||
#include <zephyr/logging/log.h> | ||
#include <zephyr/storage/disk_access.h> | ||
|
||
LOG_MODULE_REGISTER(main, LOG_LEVEL_INF); | ||
|
||
int main(void) | ||
{ | ||
struct fs_file_t file; | ||
int rc; | ||
static const char data[] = "Hello"; | ||
|
||
fs_file_t_init(&file); | ||
rc = fs_open(&file, "/RAM:/hello.txt", FS_O_CREATE | FS_O_WRITE); | ||
if (rc != 0) { | ||
LOG_ERR("Accessing filesystem failed"); | ||
return rc; | ||
} | ||
rc = fs_write(&file, data, strlen(data)); | ||
if (rc != strlen(data)) { | ||
LOG_ERR("Writing filesystem failed"); | ||
return rc; | ||
} | ||
rc = fs_close(&file); | ||
if (rc != 0) { | ||
LOG_ERR("Closing file failed"); | ||
return rc; | ||
} | ||
|
||
LOG_INF("Filesystem access successful"); | ||
return 0; | ||
} |