Skip to content
Draft
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: 1 addition & 1 deletion .github/workflows/build-and-test-macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
matrix:
os: ["macos-14", "macos-15", "macos-15-intel", "macos-26"]
otp: ["26", "27", "28"]
mbedtls: ["mbedtls@3"]
mbedtls: ["mbedtls@3", "mbedtls@4"]
cmake_opts_other: [""]

include:
Expand Down
32 changes: 30 additions & 2 deletions .github/workflows/build-and-test-on-freebsd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ concurrency:
jobs:
build-and-test-on-freebsd:
runs-on: ubuntu-24.04
name: Build and test AtomVM on FreeBSD
name: Build and test AtomVM on FreeBSD ${{ matrix.os_release }} (${{ matrix.mbedtls }})
env:
ATOMVM_EXAMPLE: "atomvm-example"

Expand All @@ -44,6 +44,10 @@ jobs:

matrix:
os_release: ["13.5", "14.3", "15.0"]
mbedtls: ["mbedtls@3"]
include:
- os_release: "14.3"
mbedtls: "mbedtls@4"

steps:

Expand All @@ -60,10 +64,25 @@ jobs:
sync: rsync
copyback: false

- name: "Use latest pkg repo for MbedTLS 4"
if: matrix.mbedtls == 'mbedtls@4'
shell: freebsd {0}
run: |
mkdir -p /usr/local/etc/pkg/repos
echo 'FreeBSD: { url: "pkg+https://pkg.FreeBSD.org/${ABI}/latest" }' > /usr/local/etc/pkg/repos/FreeBSD.conf
pkg update -f

- name: "Install deps"
if: matrix.mbedtls == 'mbedtls@3'
shell: freebsd {0}
run: |
pkg install -y curl cmake gperf erlang elixir rebar3 ninja mbedtls3

- name: "Install deps (MbedTLS 4)"
if: matrix.mbedtls == 'mbedtls@4'
shell: freebsd {0}
run: |
pkg install -y curl cmake gperf erlang elixir rebar3 mbedtls3 ninja
pkg install -y curl cmake gperf erlang elixir rebar3 ninja mbedtls4

- name: "Add hostname to /etc/hosts for distribution tests"
shell: freebsd {0}
Expand Down Expand Up @@ -102,6 +121,15 @@ jobs:
mkdir build

- name: "Build: run cmake"
if: matrix.mbedtls == 'mbedtls@3'
shell: freebsd {0}
run: |
cd $GITHUB_WORKSPACE;
cd build
cmake .. -DAVM_WARNINGS_ARE_ERRORS=ON

- name: "Build: run cmake (MbedTLS 4)"
if: matrix.mbedtls == 'mbedtls@4'
shell: freebsd {0}
run: |
cd $GITHUB_WORKSPACE;
Expand Down
51 changes: 47 additions & 4 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
# We only test several OTP versions with default compilers for supported OSes (gcc 11, gcc 13, clang 14, clang 18)
cc: ["gcc-11", "gcc-13", "clang-14", "clang-18"]
otp: ["26", "27", "28"]
mbedtls: ["default"]

include:
### gcc
Expand Down Expand Up @@ -159,6 +160,12 @@ jobs:
otp: "master"
elixir_version: "main"

# Additional mbedtls@4 coverage with the default Linux toolchain
- cc: "cc"
cxx: "c++"
otp: "28"
mbedtls: "mbedtls@4"

# Additional latest & -Os compiler builds
- cc: "gcc-14"
cxx: "g++-14"
Expand Down Expand Up @@ -494,13 +501,26 @@ jobs:
run: sudo apt update -y

- name: "Install deps"
if: matrix.container != ''
run: sudo apt install -y ${{ matrix.compiler_pkgs}} cmake gperf zlib1g-dev doxygen valgrind libmbedtls-dev
if: matrix.container != '' && matrix.mbedtls != 'mbedtls@4'
run: |
sudo apt install -y ${{ matrix.compiler_pkgs}} cmake gperf zlib1g-dev doxygen valgrind libmbedtls-dev

- name: "Install deps (MbedTLS 4)"
if: matrix.container != '' && matrix.mbedtls == 'mbedtls@4'
run: |
sudo apt install -y ${{ matrix.compiler_pkgs}} cmake gperf zlib1g-dev doxygen valgrind

- name: "Install deps"
if: matrix.container == ''
if: matrix.container == '' && matrix.mbedtls != 'mbedtls@4'
run: |
sudo apt install -y ${{ matrix.compiler_pkgs}} cmake gperf zlib1g-dev doxygen libc6-dbg libmbedtls-dev
# Get a more recent valgrind
sudo snap install valgrind --classic

- name: "Install deps (MbedTLS 4)"
if: matrix.container == '' && matrix.mbedtls == 'mbedtls@4'
run: |
sudo apt install -y ${{ matrix.compiler_pkgs}} cmake gperf zlib1g-dev doxygen libmbedtls-dev libc6-dbg
sudo apt install -y ${{ matrix.compiler_pkgs}} cmake gperf zlib1g-dev doxygen libc6-dbg
# Get a more recent valgrind
sudo snap install valgrind --classic

Expand Down Expand Up @@ -536,6 +556,19 @@ jobs:
https://repo.hex.pm
https://cdn.jsdelivr.net/hex

- name: "Install specific MbedTLS version"
if: matrix.mbedtls == 'mbedtls@4'
run: |
git clone --depth 1 --branch mbedtls-4.0.0 --recurse-submodules https://github.com/Mbed-TLS/mbedtls
cd mbedtls
mkdir build
cd build
cmake -DENABLE_TESTING=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=On -DCMAKE_INSTALL_PREFIX=/usr/local ..
make -j$(nproc)
sudo make install
sudo ldconfig
echo "MBEDTLS_ROOT_DIR=/usr/local" >> $GITHUB_ENV

# Builder info
- name: "System info"
run: |
Expand Down Expand Up @@ -566,13 +599,23 @@ jobs:
key: ${{ matrix.otp || env.DEFAULT_OTP_VERSION }}-${{ hashFiles('**/build-and-test.yaml', 'tests/**/*.erl', 'tests/**/*.hrl', 'tests/**/*.ex') }}-${{ matrix.jit_target_arch || 'nojit' }}-${{ contains(matrix.cmake_opts_other, 'AVM_DISABLE_JIT_DWARF=OFF') && 'dwarf' || 'nodwarf' }}

- name: "Build: run cmake"
if: matrix.mbedtls != 'mbedtls@4'
working-directory: build
run: |
cmake ${{ matrix.cmake_opts_fp }} ${{ matrix.cmake_opts_smp }} ${{ matrix.cmake_opts_other || env.DEFAULT_CMAKE_OPTS_OTHER }} ..
# git clone will use more recent timestamps than cached beam files
# touch them so we can benefit from the cache and avoid costly beam file rebuild.
find . -name '*.beam' -exec touch {} \;

- name: "Build: run cmake (MbedTLS 4)"
if: matrix.mbedtls == 'mbedtls@4'
working-directory: build
run: |
cmake -DMBEDTLS_ROOT_DIR=/usr/local ${{ matrix.cmake_opts_fp }} ${{ matrix.cmake_opts_smp }} ${{ matrix.cmake_opts_other || env.DEFAULT_CMAKE_OPTS_OTHER }} ..
# git clone will use more recent timestamps than cached beam files
# touch them so we can benefit from the cache and avoid costly beam file rebuild.
find . -name '*.beam' -exec touch {} \;

- name: "Build: run make"
working-directory: build
run: make -j3
Expand Down
24 changes: 21 additions & 3 deletions .github/workflows/build-libraries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
runs-on: "ubuntu-22.04"
strategy:
fail-fast: false
matrix:
mbedtls: ["default", "mbedtls@4"]

steps:
- name: "Checkout repo"
Expand All @@ -36,10 +38,26 @@ jobs:

- name: "Install deps"
run: |
sudo apt install -y build-essential cmake gperf zlib1g-dev libmbedtls-dev
sudo apt install -y build-essential cmake gperf zlib1g-dev
if [[ "${{ matrix.mbedtls }}" == "default" ]]; then
sudo apt install -y libmbedtls-dev
fi
# Get a more recent valgrind
sudo snap install valgrind --classic

- name: "Install specific MbedTLS version"
if: matrix.mbedtls == 'mbedtls@4'
run: |
git clone --depth 1 --branch mbedtls-4.0.0 --recurse-submodules https://github.com/Mbed-TLS/mbedtls
cd mbedtls
mkdir build
cd build
cmake -DENABLE_TESTING=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=On -DCMAKE_INSTALL_PREFIX=/usr/local ..
make -j$(nproc)
sudo make install
sudo ldconfig
echo "MBEDTLS_ROOT_DIR=/usr/local" >> $GITHUB_ENV

# Builder info
- name: "System info"
run: |
Expand All @@ -64,7 +82,7 @@ jobs:
- name: "Build: run cmake"
working-directory: build
run: |
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ${MBEDTLS_ROOT_DIR:+-DMBEDTLS_ROOT_DIR=$MBEDTLS_ROOT_DIR} ..

- name: "Build: run make"
working-directory: build
Expand Down Expand Up @@ -124,7 +142,7 @@ jobs:

- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
if: startsWith(github.ref, 'refs/tags/') && matrix.mbedtls == 'default'
with:
draft: true
fail_on_unmatched_files: true
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/esp32-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
- 'v5.3.4'
- 'v5.4.3'
- 'v5.5.3'
- 'v6.0'

include:
- esp-idf-target: "esp32p4"
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/esp32-simtest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ jobs:
idf-version: "v5.5.3"
- esp-idf-target: "esp32c61"
idf-version: "v5.5.3"
- esp-idf-target: "esp32"
idf-version: "v6.0"
- esp-idf-target: "esp32s3"
idf-version: "v6.0"

steps:
- name: Checkout repo
Expand Down
18 changes: 16 additions & 2 deletions doc/src/programmers-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@ Use the [`esp:deep_sleep/1`](./apidocs/erlang/eavmlib/esp.md#deep_sleep1) functi
esp:deep_sleep(60*1000).
```

Use the [`esp:sleep_get_wakeup_cause/0`](./apidocs/erlang/eavmlib/esp.md#sleep_get_wakeup_cause0) function to inspect the reason for a wakeup. Possible return values include:
For ESP-IDF 5.5 compatibility, use [`esp:sleep_get_wakeup_cause/0`](./apidocs/erlang/eavmlib/esp.md#sleep_get_wakeup_cause0) to inspect a single wakeup reason. Possible values include:

* `sleep_wakeup_ext0`
* `sleep_wakeup_ext1`
Expand All @@ -1411,7 +1411,7 @@ Use the [`esp:sleep_get_wakeup_cause/0`](./apidocs/erlang/eavmlib/esp.md#sleep_g
* `sleep_wakeup_uart`
* `sleep_wakeup_wifi`
* `sleep_wakeup_cocpu`
* `sleep_wakeup_cocpu_trag_trig`
* `sleep_wakeup_cocpu_trap_trig`
* `sleep_wakeup_bt`
* `undefined` (no sleep wakeup)
* `error` (unknown other reason)
Expand All @@ -1431,6 +1431,20 @@ case esp:sleep_get_wakeup_cause() of
end.
```

For ESP-IDF 6+, use [`esp:sleep_get_wakeup_causes/0`](./apidocs/erlang/eavmlib/esp.md#sleep_get_wakeup_causes0) to inspect all wakeup reasons. This function returns a list, since a wakeup may have multiple causes.

The values match the semantics of [`esp_sleep_get_wakeup_causes`](https://docs.espressif.com/projects/esp-idf/en/release-v6.0/esp32/api-reference/system/sleep_modes.html).

```erlang
WakeupCauses = esp:sleep_get_wakeup_causes(),
case WakeupCauses of
[] ->
io:format("No wakeup cause available~n");
_ ->
io:format("Wakeup causes: ~p~n", [WakeupCauses])
end.
```

Use the [`esp:sleep_enable_ext0_wakeup/2`](./apidocs/erlang/eavmlib/esp.md#sleep_enable_ext0_wakeup2) and [`esp:sleep_enable_ext1_wakeup/2`](./apidocs/erlang/eavmlib/esp.md#sleep_enable_ext1_wakeup2) functions to configure ext0 and ext1 wakeup mechanisms. They follow the semantics of [`esp_sleep_enable_ext0_wakeup`](https://docs.espressif.com/projects/esp-idf/en/release-v5.5/esp32/api-reference/system/sleep_modes.html#_CPPv428esp_sleep_enable_ext0_wakeup10gpio_num_ti) and [`esp_sleep_enable_ext1_wakeup`](https://docs.espressif.com/projects/esp-idf/en/release-v5.5/esp32/api-reference/system/sleep_modes.html#_CPPv428esp_sleep_enable_ext1_wakeup8uint64_t28esp_sleep_ext1_wakeup_mode_t).

```erlang
Expand Down
10 changes: 10 additions & 0 deletions libs/avm_esp32/src/esp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
restart/0,
reset_reason/0,
sleep_get_wakeup_cause/0,
sleep_get_wakeup_causes/0,
sleep_enable_ext0_wakeup/2,
sleep_enable_ext1_wakeup/2,
sleep_enable_ext1_wakeup_io/2,
Expand Down Expand Up @@ -174,6 +175,15 @@ reset_reason() ->
sleep_get_wakeup_cause() ->
erlang:nif_error(undefined).

%%-----------------------------------------------------------------------------
%% @returns wakeup causes for the previous sleep operation
%% @doc Returns all causes for the wakeup
%% @end
%%-----------------------------------------------------------------------------
-spec sleep_get_wakeup_causes() -> [esp_wakeup_cause()].
sleep_get_wakeup_causes() ->
erlang:nif_error(undefined).

%%-----------------------------------------------------------------------------
%% @doc Configure gpio wakeup from deep sleep.
%% Implemented for SOCs that support it (ESP32, ESP32S2, ESP32S3)
Expand Down
Loading
Loading