Skip to content

Commit

Permalink
ESP32: add support for mounting/umounting storage
Browse files Browse the repository at this point in the history
Allow to mount and umount external storage such as SD/MMC or internal
flash using `esp:mount/4` and `esp:umount/1`.
Right now only `fat` filesystem is supported.

Their semantic and parameters resembles unix mount and umount syscalls.

Signed-off-by: Davide Bettio <[email protected]>
  • Loading branch information
bettio committed Oct 2, 2024
1 parent 695495d commit 2990608
Show file tree
Hide file tree
Showing 9 changed files with 479 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ also non string parameters (e.g. `Enum.join([1, 2], ",")`
- Support for `binary:copy/1,2`
- Support for directory listing using POSIX APIs: (`atomvm:posix_opendir/1`,
`atomvm:posix_readdir/1`, `atomvm:posix_closedir/1`).
- Support for mounting/unmounting storage on ESP32 (such as SD or internal flash) using
`esp:mount/4` and `esp:umount/1`

### Changed

Expand Down
30 changes: 30 additions & 0 deletions libs/eavmlib/src/esp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
sleep_enable_ulp_wakeup/0,
deep_sleep/0,
deep_sleep/1,
mount/4,
umount/1,
nvs_fetch_binary/2,
nvs_get_binary/1, nvs_get_binary/2, nvs_get_binary/3,
nvs_set_binary/2, nvs_set_binary/3,
Expand Down Expand Up @@ -279,6 +281,34 @@ deep_sleep() ->
deep_sleep(_SleepMS) ->
erlang:nif_error(undefined).

%%-----------------------------------------------------------------------------
%% @param Source the device that will be mounted
%% @param Target the path where the filesystem will be mounted
%% @param FS the filesystem, only fat is supported now
%% @param Opts
%% @returns ok in case of success, otherwise an error
%% @doc Mount a filesystem
%% @end
%%-----------------------------------------------------------------------------
-spec mount(
Source :: unicode:chardata(),
Target :: unicode:chardata(),
FS :: fat,
Opts :: proplists:proplist() | #{atom() => term()}
) -> ok.
mount(_Source, _Target, _FS, _Opts) ->
erlang:nif_error(undefined).

%%-----------------------------------------------------------------------------
%% @param Target the path of the mounted filesystem that should be unmounted
%% @returns ok
%% @doc Unmounts filesystem located at given path
%% @end
%%-----------------------------------------------------------------------------
-spec umount(Target :: unicode:chardata()) -> ok.
umount(_Target) ->
erlang:nif_error(undefined).

%%-----------------------------------------------------------------------------
%% @param Namespace NVS namespace
%% @param Key NVS key
Expand Down
3 changes: 2 additions & 1 deletion src/platforms/esp32/components/avm_builtins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ set(AVM_BUILTIN_COMPONENT_SRCS
"rtc_slow_nif.c"
"socket_driver.c"
"spi_driver.c"
"storage_nif.c"
"uart_driver.c"
"otp_crypto_platform.c"
"otp_net_platform.c"
Expand Down Expand Up @@ -55,7 +56,7 @@ endif()
idf_component_register(
SRCS ${AVM_BUILTIN_COMPONENT_SRCS}
INCLUDE_DIRS "include"
PRIV_REQUIRES "libatomvm" "avm_sys" "nvs_flash" "driver" "esp_event" "esp_wifi" ${ADDITIONAL_PRIV_REQUIRES}
PRIV_REQUIRES "libatomvm" "avm_sys" "nvs_flash" "driver" "esp_event" "esp_wifi" "fatfs" ${ADDITIONAL_PRIV_REQUIRES}
${OPTIONAL_WHOLE_ARCHIVE}
)

Expand Down
4 changes: 4 additions & 0 deletions src/platforms/esp32/components/avm_builtins/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ config AVM_RTC_SLOW_MAX_SIZE
# 4KB is a reasonable default
default 4096

config AVM_ENABLE_STORAGE_NIFS
bool "Enable Storage NIFs"
default y

config AVM_ENABLE_GPIO_PORT_DRIVER
bool "Enable GPIO port driver"
default y
Expand Down
Loading

0 comments on commit 2990608

Please sign in to comment.