Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SD/MMC/FAT partition mouting with esp:mount/4 and umount #1289

Merged
merged 3 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ also non string parameters (e.g. `Enum.join([1, 2], ",")`
- ESP32: add support for `esp_adc` ADC driver, with Erlang and Elixir examples
- Add handler for ESP32 network driver STA mode `beacon_timeout` (event: 21), see issue
[#1100](https://github.com/atomvm/AtomVM/issues/1100)
- Support for mounting/unmounting storage on ESP32 (such as SD or internal flash) using
`esp:mount/4` and `esp:umount/1`

### Changed

Expand Down
33 changes: 33 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 @@ -118,6 +120,8 @@
}.
-opaque task_wdt_user_handle() :: binary().

-opaque mounted_fs() :: binary().

-export_type(
[
esp_reset_reason/0,
Expand All @@ -128,6 +132,7 @@
esp_partition_address/0,
esp_partition_size/0,
esp_partition_props/0,
mounted_fs/0,
task_wdt_config/0,
task_wdt_user_handle/0
]
Expand Down Expand Up @@ -279,6 +284,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 either a tuple having `ok' and the mounted fs resource, or an error tuple
%% @doc Mount a filesystem, and return a resource that can be used later for unmounting it
%% @end
%%-----------------------------------------------------------------------------
-spec mount(
Source :: unicode:chardata(),
Target :: unicode:chardata(),
FS :: fat,
Opts :: proplists:proplist() | #{atom() => term()}
) -> {ok, mounted_fs()} | {error, term()}.
mount(_Source, _Target, _FS, _Opts) ->
erlang:nif_error(undefined).

%%-----------------------------------------------------------------------------
%% @param The mounted filesystem resource that should be unmounted
%% @returns either `ok' or an error tuple
%% @doc Unmounts filesystem located at given path
%% @end
%%-----------------------------------------------------------------------------
-spec umount(mounted_fs()) -> ok | {error, term()}.
umount(_Target) ->
erlang:nif_error(undefined).

%%-----------------------------------------------------------------------------
%% @param Namespace NVS namespace
%% @param Key NVS key
Expand Down
3 changes: 3 additions & 0 deletions libs/estdlib/src/proplists.erl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
to_map/1
]).

-export_type([property/0, proplist/0]).

-type property() :: atom() | {term(), term()}.
-type proplist() :: [property()].

% Taken from `otp/blob/master/lib/stdlib/src/proplists.erl`
%%-----------------------------------------------------------------------------
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 @@ -56,7 +57,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}
bettio marked this conversation as resolved.
Show resolved Hide resolved
${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 @@ -72,6 +72,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
Loading