diff --git a/.github/workflows/build-and-test-macos.yaml b/.github/workflows/build-and-test-macos.yaml index 781b272ec..38993a3b4 100644 --- a/.github/workflows/build-and-test-macos.yaml +++ b/.github/workflows/build-and-test-macos.yaml @@ -11,7 +11,7 @@ on: paths-ignore: - 'src/platforms/emscripten/**' - 'src/platforms/esp32/**' - - 'src/platforms/rp2040/**' + - 'src/platforms/rp2/**' - 'src/platforms/stm32/**' - 'doc/**' - 'LICENSES/**' @@ -21,7 +21,7 @@ on: paths-ignore: - 'src/platforms/emscripten/**' - 'src/platforms/esp32/**' - - 'src/platforms/rp2040/**' + - 'src/platforms/rp2/**' - 'src/platforms/stm32/**' - 'doc/**' - 'LICENSES/**' @@ -37,8 +37,8 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: ["macos-13", "macos-14"] - otp: ["24", "25", "26"] + os: ["macos-12", "macos-13", "macos-14", "macos-15"] + otp: ["24", "25", "26", "27"] steps: # Setup @@ -48,7 +48,21 @@ jobs: submodules: 'recursive' - name: "Install deps" - run: HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install gperf doxygen erlang@${{ matrix.otp }} ninja mbedtls + if: matrix.otp != '24' + run: HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install gperf doxygen erlang@${{ matrix.otp }} ninja mbedtls rebar3 + + - name: "Install deps" + if: matrix.otp == '24' + run: | + HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install gperf doxygen erlang@${{ matrix.otp }} ninja mbedtls + wget https://github.com/erlang/rebar3/releases/download/3.23.0/rebar3 + chmod +x rebar3 + if [ -e /usr/local/opt/erlang@24/bin/ ] ; then + sudo cp rebar3 /usr/local/opt/erlang@24/bin/ + fi + if [ -e /opt/homebrew/opt/erlang@24/bin/ ] ; then + sudo cp rebar3 /opt/homebrew/opt/erlang@24/bin/ + fi # Builder info - name: "System info" diff --git a/.github/workflows/build-and-test-on-freebsd.yaml b/.github/workflows/build-and-test-on-freebsd.yaml index bf2b2aa04..aae8067df 100644 --- a/.github/workflows/build-and-test-on-freebsd.yaml +++ b/.github/workflows/build-and-test-on-freebsd.yaml @@ -11,7 +11,7 @@ on: paths-ignore: - 'src/platforms/emscripten/**' - 'src/platforms/esp32/**' - - 'src/platforms/rp2040/**' + - 'src/platforms/rp2/**' - 'src/platforms/stm32/**' - 'doc/**' - 'LICENSES/**' @@ -21,7 +21,7 @@ on: paths-ignore: - 'src/platforms/emscripten/**' - 'src/platforms/esp32/**' - - 'src/platforms/rp2040/**' + - 'src/platforms/rp2/**' - 'src/platforms/stm32/**' - 'doc/**' - 'LICENSES/**' diff --git a/.github/workflows/build-and-test-other.yaml b/.github/workflows/build-and-test-other.yaml index 2c818fa68..537e3612d 100644 --- a/.github/workflows/build-and-test-other.yaml +++ b/.github/workflows/build-and-test-other.yaml @@ -11,7 +11,7 @@ on: paths-ignore: - 'src/platforms/emscripten/**' - 'src/platforms/esp32/**' - - 'src/platforms/rp2040/**' + - 'src/platforms/rp2/**' - 'src/platforms/stm32/**' - 'doc/**' - 'LICENSES/**' @@ -21,7 +21,7 @@ on: paths-ignore: - 'src/platforms/emscripten/**' - 'src/platforms/esp32/**' - - 'src/platforms/rp2040/**' + - 'src/platforms/rp2/**' - 'src/platforms/stm32/**' - 'doc/**' - 'LICENSES/**' diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml index e1fc24753..edf6ea56f 100644 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/build-and-test.yaml @@ -11,7 +11,7 @@ on: paths-ignore: - 'src/platforms/emscripten/**' - 'src/platforms/esp32/**' - - 'src/platforms/rp2040/**' + - 'src/platforms/rp2/**' - 'src/platforms/stm32/**' - 'doc/**' - 'LICENSES/**' @@ -21,7 +21,7 @@ on: paths-ignore: - 'src/platforms/emscripten/**' - 'src/platforms/esp32/**' - - 'src/platforms/rp2040/**' + - 'src/platforms/rp2/**' - 'src/platforms/stm32/**' - 'doc/**' - 'LICENSES/**' @@ -58,11 +58,15 @@ jobs: compiler_pkgs: "gcc-7 g++-7" os: "ubuntu-20.04" otp: "27" + elixir_version: "1.17" + rebar3_version: "3.24.0" - cc: "gcc-8" cxx: "g++-8" compiler_pkgs: "gcc-8 g++-8" os: "ubuntu-20.04" otp: "27" + elixir_version: "1.17" + rebar3_version: "3.24.0" - cc: "gcc-9" cxx: "g++-9" compiler_pkgs: "gcc-9 g++-9" @@ -75,6 +79,8 @@ jobs: cmake_opts_other: "-DAVM_WARNINGS_ARE_ERRORS=ON" os: "ubuntu-22.04" otp: "27" + elixir_version: "1.17" + rebar3_version: "3.24.0" - cc: "gcc-11" cxx: "g++-11" compiler_pkgs: "gcc-11 g++-11" @@ -89,6 +95,8 @@ jobs: cmake_opts_other: "-DAVM_WARNINGS_ARE_ERRORS=ON" os: "ubuntu-24.04" otp: "27" + elixir_version: "1.17" + rebar3_version: "3.24.0" - cc: "gcc-13" cxx: "g++-13" compiler_pkgs: "gcc-13 g++-13" @@ -103,6 +111,8 @@ jobs: cmake_opts_other: "-DAVM_WARNINGS_ARE_ERRORS=ON" os: "ubuntu-24.04" otp: "27" + elixir_version: "1.17" + rebar3_version: "3.24.0" - cc: "clang-10" cxx: "clang++-10" @@ -116,18 +126,24 @@ jobs: cmake_opts_other: "-DAVM_WARNINGS_ARE_ERRORS=ON" os: "ubuntu-20.04" otp: "27" + elixir_version: "1.17" + rebar3_version: "3.24.0" - cc: "clang-12" cxx: "clang++-12" compiler_pkgs: "clang-12" cmake_opts_other: "-DAVM_WARNINGS_ARE_ERRORS=ON" os: "ubuntu-22.04" otp: "27" + elixir_version: "1.17" + rebar3_version: "3.24.0" - cc: "clang-13" cxx: "clang++-13" compiler_pkgs: "clang-13" cmake_opts_other: "-DAVM_WARNINGS_ARE_ERRORS=ON" os: "ubuntu-22.04" otp: "27" + elixir_version: "1.17" + rebar3_version: "3.24.0" - cc: "clang-14" cxx: "clang++-14" compiler_pkgs: "clang-14" @@ -140,18 +156,24 @@ jobs: cmake_opts_other: "-DAVM_WARNINGS_ARE_ERRORS=ON" os: "ubuntu-24.04" otp: "27" + elixir_version: "1.17" + rebar3_version: "3.24.0" - cc: "clang-16" cxx: "clang++-16" compiler_pkgs: "clang-16" cmake_opts_other: "-DAVM_WARNINGS_ARE_ERRORS=ON" os: "ubuntu-24.04" otp: "27" + elixir_version: "1.17" + rebar3_version: "3.24.0" - cc: "clang-17" cxx: "clang++-17" compiler_pkgs: "clang-17" cmake_opts_other: "-DAVM_WARNINGS_ARE_ERRORS=ON" os: "ubuntu-24.04" otp: "27" + elixir_version: "1.17" + rebar3_version: "3.24.0" - cc: "clang-18" cxx: "clang++-18" compiler_pkgs: "clang-18" @@ -161,41 +183,48 @@ jobs: - otp: "25" elixir_version: "1.14" + rebar3_version: "3.24.0" - otp: "26" elixir_version: "1.17" + rebar3_version: "3.24.0" - otp: "27" elixir_version: "1.17" + rebar3_version: "3.24.0" # Old versions of OTP/Elixir - os: "ubuntu-20.04" cc: "cc" cxx: "c++" - otp: "21" cflags: "" + otp: "21" elixir_version: "1.7" + rebar3_version: "3.15.2" - os: "ubuntu-20.04" cc: "cc" cxx: "c++" - otp: "22" cflags: "" + otp: "22" elixir_version: "1.8" + rebar3_version: "3.18.0" - os: "ubuntu-20.04" cc: "cc" cxx: "c++" - otp: "23" cflags: "" + otp: "23" elixir_version: "1.11" + rebar3_version: "3.20.0" - os: "ubuntu-22.04" cc: "cc" cxx: "c++" - otp: "24" cflags: "" + otp: "24" elixir_version: "1.14" + rebar3_version: "3.23.0" # TODO: enable master again # master will not work until we don't adapt to atom table changes @@ -205,37 +234,42 @@ jobs: # cxx: "c++" # otp: "master" # elixir_version: "main" +# rebar3_version: "3.24.0" # Additional default compiler builds - os: "ubuntu-20.04" cc: "cc" cxx: "c++" - otp: "27" cflags: "" + otp: "27" elixir_version: "1.17" + rebar3_version: "3.24.0" - os: "ubuntu-22.04" cc: "cc" cxx: "c++" - otp: "27" cflags: "" + otp: "27" elixir_version: "1.17" + rebar3_version: "3.24.0" # Additional latest & -Os compiler builds - os: "ubuntu-24.04" cc: "gcc-14" cxx: "g++-14" - otp: "27" cflags: "-Os" + otp: "27" elixir_version: "1.17" + rebar3_version: "3.24.0" compiler_pkgs: "gcc-14 g++-14" - os: "ubuntu-24.04" cc: "clang-18" cxx: "clang++-18" - otp: "27" cflags: "-Os" + otp: "27" elixir_version: "1.17" + rebar3_version: "3.24.0" compiler_pkgs: "clang-18" # Additional 32 bits build @@ -245,6 +279,7 @@ jobs: cflags: "-m32 -O3" otp: "23" elixir_version: "1.11" + rebar3_version: "3.20.0" # Use Werror so we get an error with 32 bit specific warnings cmake_opts_other: "-DAVM_CREATE_STACKTRACES=off -DAVM_WARNINGS_ARE_ERRORS=ON" arch: "i386" @@ -268,6 +303,7 @@ jobs: with: otp-version: ${{ matrix.otp }} elixir-version: ${{ matrix.elixir_version }} + rebar3-version: ${{ matrix.rebar3_version }} hexpm-mirrors: | https://builds.hex.pm https://repo.hex.pm diff --git a/.github/workflows/codeql-analysis.yaml b/.github/workflows/codeql-analysis.yaml index f8e9ae190..f115542be 100644 --- a/.github/workflows/codeql-analysis.yaml +++ b/.github/workflows/codeql-analysis.yaml @@ -11,7 +11,7 @@ on: paths-ignore: - 'src/platforms/emscripten/**' - 'src/platforms/esp32/**' - - 'src/platforms/rp2040/**' + - 'src/platforms/rp2/**' - 'src/platforms/stm32/**' - 'libs/**' - 'doc/**' @@ -22,7 +22,7 @@ on: paths-ignore: - 'src/platforms/emscripten/**' - 'src/platforms/esp32/**' - - 'src/platforms/rp2040/**' + - 'src/platforms/rp2/**' - 'src/platforms/stm32/**' - 'libs/**' - 'doc/**' @@ -55,7 +55,7 @@ jobs: run: sudo apt update -y - name: "Install deps" - run: sudo apt install -y cmake gperf zlib1g-dev ninja-build erlang + run: sudo apt install -y cmake gperf zlib1g-dev ninja-build erlang rebar3 - name: "Checkout repository" uses: actions/checkout@v4 diff --git a/.github/workflows/pico-build.yaml b/.github/workflows/pico-build.yaml index bbbca5132..879fe3568 100644 --- a/.github/workflows/pico-build.yaml +++ b/.github/workflows/pico-build.yaml @@ -12,7 +12,7 @@ on: - '.github/workflows/pico-build.yaml' - 'CMakeLists.txt' - 'libs/**' - - 'src/platforms/rp2040/**' + - 'src/platforms/rp2/**' - 'src/platforms/esp32/test/main/test_erl_sources/test_crypto.erl' - 'src/libAtomVM/**' pull_request: @@ -20,7 +20,7 @@ on: - '.github/workflows/pico-build.yaml' - 'CMakeLists.txt' - 'libs/**' - - 'src/platforms/rp2040/**' + - 'src/platforms/rp2/**' - 'src/platforms/esp32/test/main/test_erl_sources/test_crypto.erl' - 'src/libAtomVM/**' @@ -36,7 +36,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - board: ["pico", "pico_w"] + board: ["pico", "pico_w", "pico2"] steps: - name: Checkout repo @@ -50,11 +50,11 @@ jobs: sudo apt install -y \ cmake gperf ninja-build gcc-arm-none-eabi \ libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib \ - erlang-base erlang-dev erlang-dialyzer erlang-eunit + erlang-base erlang-dev erlang-dialyzer erlang-eunit rebar3 - name: Build shell: bash - working-directory: ./src/platforms/rp2040/ + working-directory: ./src/platforms/rp2/ run: | set -euo pipefail mkdir build @@ -63,6 +63,7 @@ jobs: ninja - name: Install nvm and nodejs 20 + if: matrix.board != 'pico2' run: | set -euo pipefail curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash @@ -70,59 +71,81 @@ jobs: nvm install 20 - name: Build tests (without SMP) + if: matrix.board != 'pico2' shell: bash - working-directory: ./src/platforms/rp2040/ + working-directory: ./src/platforms/rp2/ run: | set -euo pipefail mkdir build.nosmp cd build.nosmp # TODO: fix all warnings and enable -DAVM_WARNINGS_ARE_ERRORS=ON cmake .. -G Ninja -DPICO_BOARD=${{ matrix.board }} -DAVM_DISABLE_SMP=1 - cmake --build . --target=rp2040_tests + cmake --build . --target=rp2_tests - name: Run tests with rp2040js + if: matrix.board != 'pico2' shell: bash - working-directory: ./src/platforms/rp2040/tests + working-directory: ./src/platforms/rp2/tests run: | set -euo pipefail source $HOME/.nvm/nvm.sh nvm use node npm install - npx tsx run-tests.ts ../build.nosmp/tests/rp2040_tests.uf2 ../build.nosmp/tests/test_erl_sources/rp2040_test_modules.uf2 + npx tsx run-tests.ts ../build.nosmp/tests/rp2_tests.uf2 ../build.nosmp/tests/test_erl_sources/rp2_test_modules.uf2 - name: Build atomvmlib.uf2 - if: startsWith(github.ref, 'refs/tags/') + if: startsWith(github.ref, 'refs/tags/') && matrix.board != 'pico_w' shell: bash run: | set -euo pipefail mkdir build cd build cmake .. - make atomvmlib.uf2 + make atomvmlib-${{ matrix.board }}.uf2 - - name: Rename and write sha256sum + - name: Rename AtomVM and write sha256sum if: startsWith(github.ref, 'refs/tags/') shell: bash run: | - pushd src/platforms/rp2040/build + pushd src/platforms/rp2/build ATOMVM_UF2=AtomVM-${{ matrix.board }}-${{ github.ref_name }}.uf2 mv src/AtomVM.uf2 "src/${ATOMVM_UF2}" sha256sum "src/${ATOMVM_UF2}" > "src/${ATOMVM_UF2}.sha256" popd pushd build/libs - ATOMVMLIB_FILE=atomvmlib-${{ github.ref_name }}.uf2 + ATOMVMLIB_FILE=atomvmlib-${{ matrix.board }}-${{ github.ref_name }}.uf2 mv atomvmlib.uf2 "${ATOMVMLIB_FILE}" sha256sum "${ATOMVMLIB_FILE}" > "${ATOMVMLIB_FILE}.sha256" popd - - name: Release + - name: Rename atomvmlib and write sha256sum + if: startsWith(github.ref, 'refs/tags/') && matrix.board != 'pico_w' + shell: bash + run: | + pushd build/libs + ATOMVMLIB_FILE=atomvmlib-${{ matrix.board }}-${{ github.ref_name }}.uf2 + mv atomvmlib-${{ matrix.board }}.uf2 "${ATOMVMLIB_FILE}" + sha256sum "${ATOMVMLIB_FILE}" > "${ATOMVMLIB_FILE}.sha256" + popd + + - name: Release (Pico & Pico2) uses: softprops/action-gh-release@v1 - if: startsWith(github.ref, 'refs/tags/') + if: startsWith(github.ref, 'refs/tags/') && matrix.board != 'pico_w' + with: + draft: true + fail_on_unmatched_files: true + files: | + src/platforms/rp2/build/src/AtomVM-${{ matrix.board }}-${{ github.ref_name }}.uf2 + src/platforms/rp2/build/src/AtomVM-${{ matrix.board }}-${{ github.ref_name }}.uf2.sha256 + build/libs/atomvmlib-${{ matrix.board }}-${{ github.ref_name }}.uf2 + build/libs/atomvmlib-${{ matrix.board }}-${{ github.ref_name }}.uf2.sha256 + + - name: Release (PicoW) + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') && matrix.board == 'pico_w' with: draft: true fail_on_unmatched_files: true files: | - src/platforms/rp2040/build/src/AtomVM-${{ matrix.board }}-${{ github.ref_name }}.uf2 - src/platforms/rp2040/build/src/AtomVM-${{ matrix.board }}-${{ github.ref_name }}.uf2.sha256 - build/libs/atomvmlib-${{ github.ref_name }}.uf2 - build/libs/atomvmlib-${{ github.ref_name }}.uf2.sha256 + src/platforms/rp2/build/src/AtomVM-${{ matrix.board }}-${{ github.ref_name }}.uf2 + src/platforms/rp2/build/src/AtomVM-${{ matrix.board }}-${{ github.ref_name }}.uf2.sha256 diff --git a/.github/workflows/run-tests-with-beam.yaml b/.github/workflows/run-tests-with-beam.yaml index 398c1cb6d..4566a8830 100644 --- a/.github/workflows/run-tests-with-beam.yaml +++ b/.github/workflows/run-tests-with-beam.yaml @@ -11,7 +11,7 @@ on: paths-ignore: - 'src/platforms/emscripten/**' - 'src/platforms/esp32/**' - - 'src/platforms/rp2040/**' + - 'src/platforms/rp2/**' - 'src/platforms/stm32/**' - 'doc/**' - 'LICENSES/**' @@ -21,7 +21,7 @@ on: paths-ignore: - 'src/platforms/emscripten/**' - 'src/platforms/esp32/**' - - 'src/platforms/rp2040/**' + - 'src/platforms/rp2/**' - 'src/platforms/stm32/**' - 'doc/**' - 'LICENSES/**' @@ -72,15 +72,15 @@ jobs: # This is ARM64 - os: "macos-14" - otp: "24" + otp: "25" path_prefix: "/opt/homebrew/opt/erlang@24/bin:" - os: "macos-14" - otp: "25" + otp: "26" path_prefix: "/opt/homebrew/opt/erlang@25/bin:" - os: "macos-14" - otp: "26" + otp: "27" path_prefix: "/opt/homebrew/opt/erlang@26/bin:" steps: # Setup @@ -97,7 +97,7 @@ jobs: - name: "Install deps (macOS)" if: runner.os == 'macOS' - run: brew install gperf erlang@${{ matrix.otp }} ninja mbedtls + run: brew install gperf erlang@${{ matrix.otp }} ninja mbedtls rebar3 # Build - name: "Build: create build dir" diff --git a/CMakeModules/BuildErlang.cmake b/CMakeModules/BuildErlang.cmake index 47f3df943..5b6e92a15 100644 --- a/CMakeModules/BuildErlang.cmake +++ b/CMakeModules/BuildErlang.cmake @@ -87,12 +87,20 @@ macro(pack_lib avm_name) endif() add_custom_target( - ${avm_name}.uf2 ALL - COMMAND ${CMAKE_BINARY_DIR}/tools/uf2tool/uf2tool create -o ${avm_name}.uf2 -s 0x10100000 ${avm_name}.avm + ${avm_name}-pico.uf2 ALL + COMMAND ${CMAKE_BINARY_DIR}/tools/uf2tool/uf2tool create -o ${avm_name}-pico.uf2 -s 0x10100000 ${avm_name}.avm + COMMENT "Creating UF2 file ${avm_name}.uf2" + VERBATIM + ) + add_dependencies(${avm_name}-pico.uf2 ${avm_name}) + + add_custom_target( + ${avm_name}-pico2.uf2 ALL + COMMAND ${CMAKE_BINARY_DIR}/tools/uf2tool/uf2tool create -o ${avm_name}-pico2.uf2 -f data -s 0x10100000 ${avm_name}.avm COMMENT "Creating UF2 file ${avm_name}.uf2" VERBATIM ) - add_dependencies(${avm_name}.uf2 ${avm_name}) + add_dependencies(${avm_name}-pico2.uf2 ${avm_name}) endmacro() @@ -237,7 +245,7 @@ macro(pack_uf2 avm_name main) add_custom_target( ${avm_name}.uf2 ALL - COMMAND ${CMAKE_BINARY_DIR}/tools/uf2tool/uf2tool create -o ${avm_name}.uf2 -s 0x10180000 ${avm_name}.avm + COMMAND ${CMAKE_BINARY_DIR}/tools/uf2tool/uf2tool create -o ${avm_name}.uf2 -f universal -s 0x10180000 ${avm_name}.avm COMMENT "Creating UF2 file ${avm_name}.uf2" VERBATIM ) diff --git a/README.Md b/README.Md index b7a90f1ec..9d9a667d9 100644 --- a/README.Md +++ b/README.Md @@ -18,7 +18,7 @@ Supported Platforms * Linux, macOS, FreeBSD, DragonFly ([generic_unix](https://www.atomvm.net/doc/main/getting-started-guide.html#getting-started-on-the-generic-unix-platform)) * ESP32 SoC (with IDF/FreeRTOS, see [esp32](https://www.atomvm.net/doc/main/getting-started-guide.html#getting-started-on-the-esp32-platform)) * STM32 MCUs (with LibOpenCM3, see [stm32](https://www.atomvm.net/doc/main/getting-started-guide.html#getting-started-on-the-stm32-platform)) -* Raspberry Pi Pico (see [rp2040](https://www.atomvm.net/doc/main/getting-started-guide.html#getting-started-on-the-raspberry-pi-pico-platform)) +* Raspberry Pi Pico and Pico 2 (see [rp2](https://www.atomvm.net/doc/main/getting-started-guide.html#getting-started-on-the-raspberry-pi-pico-platform)) * Browsers and NodeJS with WebAssembly (see [emscripten](https://www.atomvm.net/doc/main/getting-started-guide.html#getting-started-with-atomvm-webassembly)) AtomVM aims to be easily portable to new platforms with a minimum effort, so additional platforms @@ -47,6 +47,7 @@ Required for building: * gperf ([GNU Perfect Hash Function Generator](https://www.gnu.org/software/gperf/manual/gperf.html)) * erlc ([erlang compiler](https://www.erlang.org/)) * elixirc ([elixir compiler](https://elixir-lang.org)) +* rebar3 ([rebar3 build tool](https://www.rebar3.org/)) * Mbed TLS ([portable TLS library, optionally required to support SSL](https://www.trustedfirmware.org/projects/mbed-tls/)) * zlib ([zlib compression and decompression library](https://zlib.net/)) @@ -81,8 +82,8 @@ available in the documentation for [Generic UNIX](https://www.atomvm.net/doc/main/build-instructions.html) (Linux, MacOS, FreeBSD, DragonFly), [ESP32](https://www.atomvm.net/doc/main/build-instructions.html#building-for-esp32), [STM32](https://www.atomvm.net/doc/main/build-instructions.html#building-for-stm32), -[Raspberry Pi Pico](https://www.atomvm.net/doc/main/build-instructions.html#building-for-raspberry-pi-pico) -(rp2040), and +[Raspberry Pi Pico and Pico 2](https://www.atomvm.net/doc/main/build-instructions.html#building-for-raspberry-pi-pico) +(rp2), and [WASM](https://www.atomvm.net/doc/main/build-instructions.html#building-for-nodejs-web) (NodeJS/Web). Project Status diff --git a/doc/src/atomvm-internals.md b/doc/src/atomvm-internals.md index af6f76f72..787ad6358 100644 --- a/doc/src/atomvm-internals.md +++ b/doc/src/atomvm-internals.md @@ -146,17 +146,17 @@ If there already is one thread in `sys_poll_events`, other scheduler threads pic ## Tasks and synchronization mechanisms -AtomVM SMP builds run on operating or runtime systems implementing tasks (FreeRTOS SMP on ESP32, Unix and WebAssembly) as well as on systems with no task implementation (Raspberry Pi Pico). +AtomVM SMP builds run on operating or runtime systems implementing tasks (FreeRTOS SMP on ESP32, Unix and WebAssembly) as well as on systems with no task implementation (Raspberry Pi RP2). -On runtime systems with tasks, each scheduler thread is implemented as a task. On Pico, a scheduler thread runs on Core 0 and another one runs on Core 1, and they are effectively pinned to each core. +On runtime systems with tasks, each scheduler thread is implemented as a task. On RP2, a scheduler thread runs on Core 0 and another one runs on Core 1, and they are effectively pinned to each core. For synchronization purposes, AtomVM uses mutexes, condition variables, RW locks, spinlocks and Atomics. Availability of RW Locks and atomics are verified at compile time using detection of symbols for RW Locks and `ATOMIC_*_LOCK_FREE` C11 macros for atomics. -Mutexes and condition variables are provided by the SDK or the runtime system. If RW Locks are not available, AtomVM uses mutexes. Atomics are not available on Pico and are replaced by critical sections. Spinlocks are implemented by AtomVM on top of Atomics, or using mutexes on Pico. +Mutexes and condition variables are provided by the SDK or the runtime system. If RW Locks are not available, AtomVM uses mutexes. Atomics are not available on RP2 and are replaced by critical sections. Spinlocks are implemented by AtomVM on top of Atomics, or using mutexes on RP2. -Importantly, locking synchronization mechanisms (mutexes, RW locks, spinlocks) are not interrupt-safe. Interrupt service routines must not try to lock as they could fail forever if interrupted code owns the lock. Atomics, including emulation on Pico, are interrupt-safe. +Importantly, locking synchronization mechanisms (mutexes, RW locks, spinlocks) are not interrupt-safe. Interrupt service routines must not try to lock as they could fail forever if interrupted code owns the lock. Atomics, including emulation on RP2040, are interrupt-safe. Drivers can send messages from event callbacks typically called from FreeRTOS tasks using `globalcontext_send_message_from_task` or `port_send_message_from_task` functions instead of `globalcontext_send_message` or `port_send_message`. These functions try to acquire required locks and if they fail, enqueue sent message in a queue, so it is later processed when the scheduler performs context switching. The functions are undefined if option `AVM_DISABLE_TASK_DRIVER` is passed. Some platforms do not include support for task drivers. Define `AVM_TASK_DRIVER_ENABLED` can be checked to determine if these functions are available. diff --git a/doc/src/atomvm-tooling.md b/doc/src/atomvm-tooling.md index 4038a995b..90051e87f 100644 --- a/doc/src/atomvm-tooling.md +++ b/doc/src/atomvm-tooling.md @@ -30,7 +30,7 @@ To use the [`atomvm_rebar3_plugin`](https://atomvm.github.io/atomvm_rebar3_plugi * For flashing to ESP32, the [`esptool`](https://github.com/espressif/esptool) program. * For flashing to STM32, `st-flash` via [stlink](https://github.com/stlink-org/stlink) * (optional) A serial console program such as [minicom](https://en.wikipedia.org/wiki/Minicom) or [screen](https://en.wikipedia.org/wiki/GNU_Screen), to view console output from a device. -* (recommended) For rp2040, [`picotool`](https://github.com/raspberrypi/picotool) for software resets on Raspberry Pi Pico. (optionally used if found in PATH to disconnect active `screen` sessions, which normally prevent flashing) +* (recommended) For rp2040 and rp2350, [`picotool`](https://github.com/raspberrypi/picotool) for software resets on Raspberry Pi Pico. (optionally used if found in PATH to disconnect active `screen` sessions, which normally prevent flashing) ### Erlang Example Program @@ -210,9 +210,9 @@ You can now use a serial console program such as [minicom](https://en.wikipedia. INFO [74] AtomVM: Exited with return: ok INFO [78] AtomVM: AtomVM application terminated. Going to sleep forever ... -#### Raspberry Pico +#### Raspberry Pi RP2 -To generate a Raspberry Pico uf2 file from an AtomVM AVM file and flash it to an rp2040 device, use the `pico_flash` target in the `atomvm` namespace. +To generate a Raspberry Pi RP2 uf2 file from an AtomVM AVM file and flash it to an RP2 device, use the `pico_flash` target in the `atomvm` namespace. For example: @@ -226,7 +226,7 @@ $ rebar3 atomvm pico_flash /run/media/${USER}/RPI-RP2... ``` -See the [`atomvm_rebar3_plugin`](https://atomvm.github.io/atomvm_rebar3_plugin) page for more detailed instructions about how to use the `pico_flash` target. +See the [`atomvm_rebar3_plugin`](https://atomvm.github.io/atomvm_rebar3_plugin) page for more detailed instructions about how to use the `pico_flash` target. By default it will generate a universal UF2 that works on both RP2040 and RP2350 but you can optionally target only one of socs. You can now use a serial console program such as [minicom](https://en.wikipedia.org/wiki/Minicom) or [screen](https://en.wikipedia.org/wiki/GNU_Screen) to view console output from a device. The default build will wait 20 seconds for a serial connection to be established before starting the application. @@ -262,7 +262,7 @@ The device was asked to reboot into application mode. $ ``` -This will again give you 20 seconds to establish a serial monitor connection. For information about changing this timeout, or locking down the device so that software resets no longer work (requiring that the device be power cycled and the `BOOTSEL` button help when powering on to flash) consult the [rp2040 section](./build-instructions.md#building-for-raspberry-pi-pico) of the [Build Instructions](./build-instructions.md). +This will again give you 20 seconds to establish a serial monitor connection. For information about changing this timeout, or locking down the device so that software resets no longer work (requiring that the device be power cycled and the `BOOTSEL` button help when powering on to flash) consult the [rp2040 section](./build-instructions.md#building-for-raspberry-pi-rp2) of the [Build Instructions](./build-instructions.md). ## `ExAtomVM` diff --git a/doc/src/build-instructions.md b/doc/src/build-instructions.md index 13677604e..07bda857e 100644 --- a/doc/src/build-instructions.md +++ b/doc/src/build-instructions.md @@ -76,7 +76,7 @@ The `src` directory is broken up into the core platform-independent AtomVM libra * [Generic UNIX](#building-for-generic-unix) * [ESP32](#building-for-esp32) * [STM32](#building-for-stm32) -* [Raspberry Pi Pico](#building-for-raspberry-pi-pico) (rp2040) +* [RP2](#building-for-rp2) (including Pico boards) * [WASM](#building-for-emscripten) (NodeJS or web) ## Building for Generic UNIX @@ -732,19 +732,22 @@ If building for a different target USART may be configure as explained above in After your application has been tested (_and debugged_) and is ready to put into active use you may want to tune the build of AtomVM. For instance disabling logging with `-DAVM_LOG_DISABLE=on` as a `cmake` configuration option may result in slightly better performance. This will have no affect on the console output of your application, just disable low level log messages from the AtomVM system. You may also want to enabling automatic reboot in the case that your application ever exits with a return other than `ok`. This can be enabled with the `cmake` option `-DAVM_CONFIG_REBOOT_ON_NOT_OK=on`. -## Building for Raspberry Pi Pico +## Building for Raspberry Pi RP2 -### Pico Prerequisites +You can build with all boards supported by Raspberry Pi pico SDK, including Pico, Pico-W and Pico2. AtomVM also works with clones such as RP2040 Zero. + +### RP2 Prerequisites * `cmake` * `ninja` * `Erlang/OTP` * `Elixir` (optional) +* A toolchain for the target (ARM or Risc-V) -### AtomVM build steps (Pico) +### AtomVM build steps (Pico or most boards based on RP2040) ```shell -$ cd src/platforms/rp2040/ +$ cd src/platforms/rp2/ $ mkdir build $ cd build $ cmake .. -G Ninja @@ -752,13 +755,13 @@ $ ninja ``` ```{tip} -You may want to build with option `AVM_REBOOT_ON_NOT_OK` so Pico restarts on error. +You may want to build with option `AVM_REBOOT_ON_NOT_OK` so AtomVM restarts on error. ``` ### AtomVM build steps (Pico-W) ```shell -$ cd src/platforms/rp2040/ +$ cd src/platforms/rp2/ $ mkdir build $ cd build $ cmake .. -G Ninja -DPICO_BOARD=pico_w @@ -766,14 +769,39 @@ $ ninja ``` ```{tip} -You may want to build with option `AVM_REBOOT_ON_NOT_OK` so Pico restarts on error. +You may want to build with option `AVM_REBOOT_ON_NOT_OK` so AtomVM restarts on error. +``` + +### AtomVM build steps (Pico2 or boards based on RP2350) + +For ARM S platform (recommended) : +```shell +$ cd src/platforms/rp2/ +$ mkdir build +$ cd build +$ cmake .. -G Ninja -DPICO_BOARD=pico2 +$ ninja +``` + +For RISC-V platform (supported but slower) : + +```shell +$ cd src/platforms/rp2/ +$ mkdir build +$ cd build +$ cmake .. -G Ninja -DPICO_BOARD=pico2 -DPICO_PLATFORM=rp2350-riscv +$ ninja +``` + +```{tip} +You may want to build with option `AVM_REBOOT_ON_NOT_OK` so AtomVM restarts on error. ``` The default build configuration allows the device to be re-flashed with the `atomvm_rebar3_plugin` `atomvm pico_flash` task or restarting the application after exiting using [`picotool`](https://github.com/raspberrypi/picotool). This behaviour can be changed to hang the CPU when the application exits, so that power must be cycled to restart, and `BOOTSEL` must be held when power on to flash a new application. To disable software resets use `-DAVM_WAIT_BOOTSEL_ON_EXIT=off` when configuring `cmake`. The 20 second default timeout for a USB serial connection can be changed using option `AVM_USB_WAIT_SECONDS`. The device can also be configured to wait indefinitely for a serial connection using the option `AVM_WAIT_FOR_USB_CONNECT=on`. -### libAtomVM build steps for Pico +### libAtomVM build steps for RP2 Build of standard libraries is part of the generic unix build. @@ -786,16 +814,16 @@ $ cmake .. -G Ninja $ ninja ``` -### Running tests for Pico +### Running tests for RP2 -Tests for Pico/RP2040 are run on the desktop (or CI) using [rp2040js](https://github.com/wokwi/rp2040js). +Tests for RP2040 are run on the desktop (or CI) using [rp2040js](https://github.com/wokwi/rp2040js). Running tests currently require nodejs 20. -Change directory to the `src/platforms/rp2040/tests` directory under the AtomVM source tree root: +Change directory to the `src/platforms/rp2/tests` directory under the AtomVM source tree root: ```shell $ cd -$ cd src/platforms/rp2040/tests +$ cd src/platforms/rp2/tests $ ``` diff --git a/doc/src/getting-started-guide.md b/doc/src/getting-started-guide.md index df1d50325..4745755de 100644 --- a/doc/src/getting-started-guide.md +++ b/doc/src/getting-started-guide.md @@ -14,7 +14,7 @@ The getting started is broken up into the following sections: * [Getting Started on the ESP32 platform](#getting-started-on-the-esp32-platform) * [Getting Started on the STM32 platform](#getting-started-on-the-stm32-platform) -* [Getting Started on the Raspberry Pi Pico platform](#getting-started-on-the-raspberry-pi-pico-platform) +* [Getting Started on the Raspberry Pi RP2](#getting-started-on-the-raspberry-pi-rp2) * [Getting Started on the Generic UNIX platform](#getting-started-on-the-generic-unix-platform) * [Getting Started with AtomVM WebAssembly](#getting-started-with-atomvm-webassembly) @@ -259,25 +259,25 @@ AtomVM applications can be written in Erlang or Elixir, or a combination of both For information about how to flash your application to your STM32, see the [AtomVM Tooling](./atomvm-tooling.md) chapter. -## Getting Started on the Raspberry Pi Pico platform +## Getting Started on the Raspberry Pi RP2 -AtomVM supports deployment of the VM and applications onto the [Raspberry Pi Pico](https://www.raspberrypi.com/products/raspberry-pi-pico/) platform. For information about supported boards, please refer to the AtomVM [Release Notes](./release-notes.md). +AtomVM supports deployment of the VM and applications onto boards based on Raspberry Pi RP2 socs, including RP2040 and RP2350. This includes [Raspberry Pi Pico and Pico-W](https://www.raspberrypi.com/products/raspberry-pi-pico/), as well as [Raspberry Pi Pico 2](https://www.raspberrypi.com/products/raspberry-pi-pico-2/) boards. For information about supported boards, please refer to the AtomVM [Release Notes](./release-notes.md). The following instructions show you how to install the AtomVM onto one of the [Raspberry Pi Pico](https://www.raspberrypi.com/products/raspberry-pi-pico/) boards. -### Pico Requirements +### Pico and Pico 2 Requirements -Deployment of AtomVM on the Raspberry Pico platform requires the following components: +Deployment of AtomVM on the Raspberry Pi Pico and Pico 2 platform requires the following components: * A computer running MacOS or Linux (Windows support is not currently supported); -* A Raspberry Pico board with a USB/UART connector (typically part of a development board); -* A USB cable capable of connecting the Raspberry Pico module or board to your development machine (laptop or PC); +* A Raspberry Pi Pico or Pico 2 board; +* A USB cable capable of connecting the board to your development machine (laptop or PC); * A serial console program, such as `minicom` or `screen`, so that you can view console output from your AtomVM application. * (recommended) For Erlang programs, [`rebar3`](https://rebar3.org); * (recommended) For Elixir programs, [`mix`](https://elixir-lang.org/getting-started/mix-otp/introduction-to-mix.html), which ships with the Elixir runtime; * (recommended) [`picotool`](https://github.com/raspberrypi/picotool), useful for resetting the device into `BOOTSEL` or `application` mode, optionally used by the `atomvm_rebar3_plugin` (if available in env $PATH) for disconnecting active `screen` sessions when attempting to flash when still connected. -### Deploying the Pico AtomVM virtual machine +### Deploying the Pico or Pico 2 AtomVM virtual machine The following methods can be used to deploy the AtomVM virtual machine to a Raspberry Pico device: @@ -286,17 +286,21 @@ The following methods can be used to deploy the AtomVM virtual machine to a Rasp #### Flashing a binary image to Pico -Flashing the Raspberry Pico using a pre-built binary image is by far the easiest path to getting started with development on the Raspberry Pico. Binary images contain the virtual machine image and all of the necessary components to run your application. +Flashing the Raspberry Pi Pico or Pico 2 using a pre-built binary image is by far the easiest path to getting started with development on this platform. Binary images contain the virtual machine image and all of the necessary components to run your application. -Download the latest [release image](https://github.com/atomvm/AtomVM/releases) for Raspberry Pico. +Download the latest [release image](https://github.com/atomvm/AtomVM/releases) for Raspberry Pi Pico or Raspberry Pi Pico 2. This image will generally take the form: ->`Atomvm--.uf2` +>`Atomvm--.uf2` For example: ->`Atomvm-pico-v0.6.0.uf2` +>`Atomvm-pico-v0.7.0.uf2` + +or + +>`Atomvm-pico2-v0.7.0.uf2` You will also find the sha256 hash for this file, which you should verify using the `sha256sum` command on your local operating system. @@ -304,29 +308,29 @@ You will also need a copy of the AtomVM core libraries, which include all of the This library will generally take the form: ->`atomvmlib-.uf2` +>`atomvmlib--.uf2` For example: ->`atomvmlib-v0.6.0.uf2` +>`atomvmlib-pico-v0.7.0.uf2` You will also find the sha256 hash for this file, which you should verify using the `sha256sum` command on your local operating system. To flash your Raspberry Pico, you will need to undertake a few steps that interact with your operating file system. ```{important} -It is important that you downloads the `.uf2` versions of these files for the Raspberry Pico platform. +It is important that you downloads the `.uf2` versions of these files for the Raspberry Pi Pico or Pico 2 platform. It is also important to download the Pico or the Pico2 files depending on your board. ``` -For each of the above files, you will start your Raspberry Pico in bootloader mode by pressing the `BOOTSEL` button on the Raspberry Pico dev board, while powering on the device. Doing so will automatically boot the device and mount the Raspberry Pico on to your file system as a USB device. +For each of the above files, you will start your Raspberry Pi Pico or Pico 2 in bootloader mode by pressing the `BOOTSEL` button on the board, while powering on the device. Doing so will automatically boot the device and mount the Raspberry Pi Pico on to your file system as a USB device. You can then use normal operating system commands (such as `cp`, or even drag-and-drop) to copy the above files to the mounted USB volume. Note, however, that in general the USB device will auto-unmount after each file has been copied, so you will need to repeat the procedure for each of the above two files. -On most Linux systems, the Raspberry Pico will be mounted at `/run/media/${USER}/RPI-RP2`. +On most Linux systems, the Raspberry Pi Pico will be mounted at `/run/media/${USER}/RPI-RP2` and the Raspberry Pi Pico 2 will be mounted at `/run/media/${USER}/RP2350`. -On macOS system, the Raspberry Pico will be mounted at `/Volumes/RPI-RP2`. +On macOS system, the Raspberry Pi Pico will be mounted at `/Volumes/RPI-RP2` and the Raspberry Pi Pico 2 will be mounted at `/Volumes/RP2350`. For example: @@ -338,7 +342,7 @@ total 16 -rwxrwxrwx 1 joe staff 241 Sep 5 2008 INDEX.HTM* -rwxrwxrwx 1 joe staff 62 Sep 5 2008 INFO_UF2.TXT* -$ cp ~/Downloads/AtomVM-pico-v0.6.0.uf2 /Volumes/RPI-RP2/. +$ cp ~/Downloads/AtomVM-pico-v0.7.0.uf2 /Volumes/RPI-RP2/. ``` ... at this point, the device will auto-unmount. @@ -353,7 +357,7 @@ total 16 -rwxrwxrwx 1 joe staff 241 Sep 5 2008 INDEX.HTM* -rwxrwxrwx 1 joe staff 62 Sep 5 2008 INFO_UF2.TXT* -$ cp ~/Downloads/atomvmlib-v0.6.0.uf2 /Volumes/RPI-RP2/. +$ cp ~/Downloads/atomvmlib-pico-v0.7.0.uf2 /Volumes/RPI-RP2/. ``` ... and again, at this point, the device will auto-unmount. @@ -388,7 +392,7 @@ When the AtomVM virtual machine starts, it will search for the first module that AtomVM applications can be written in Erlang or Elixir, or a combination of both. The AtomVM community has provided tooling for both platforms, making deployment of AtomVM applications as seamless as possible. -For information about how to flash your application to your Raspberry Pico, see the [AtomVM Tooling](./atomvm-tooling.md#raspberry-pico) chapter. +For information about how to flash your application to your Raspberry Pi Pico, see the [AtomVM Tooling](./atomvm-tooling.md#raspberry-pico) chapter. ## Getting Started on the Generic UNIX platform diff --git a/doc/src/programmers-guide.md b/doc/src/programmers-guide.md index b7c1bed1c..44cb1b43b 100644 --- a/doc/src/programmers-guide.md +++ b/doc/src/programmers-guide.md @@ -109,11 +109,11 @@ In order to deploy AtomVM applications to and test on the ESP32 platform, develo * [`packbeam`](https://github.com/atomvm/atomvm_packbeam) the AtomVM for packing and stripping `*.beam` files into the AtomVM `*.avm` format. * (Optional, but recommended) A serial console program, such as `minicom` or `screen`, so that you can view console output from your AtomVM application. -#### Raspberry Pi Pico Deployment Requirements +#### Raspberry Pi RP2 Deployment Requirements * A computer running MacOS or Linux (Windows support is not currently supported); -* A Raspberry Pico board with a USB/UART connector (typically part of a development board); -* A USB cable capable of connecting the Raspberry Pico module or board to your development machine (laptop or PC); +* A board with a Raspberry Pi RP2 soc such as Raspberry Pi Pico or Pico W or Pico 2, with a USB connector (typically part of a development board); +* A USB cable capable of connecting the module or board to your development machine (laptop or PC); * (Optional, but recommended) A serial console program, such as `minicom` or `screen`, so that you can view console output from your AtomVM application. ### Development Workflow @@ -1453,7 +1453,7 @@ case gpio:digital_read(Pin) of end. ``` -The Pico has an additional initialization step [`gpio:init/1`](./apidocs/erlang/eavmlib/gpio.md#init1) before using a pin for gpio: +The RP2 has an additional initialization step [`gpio:init/1`](./apidocs/erlang/eavmlib/gpio.md#init1) before using a pin for gpio: ```erlang Pin = 2, @@ -1487,7 +1487,7 @@ gpio:set_pin_mode(Pin, output), gpio:digital_write(Pin, low). ``` -Pico needs the extra `gpio:init/1` before `gpio:read/1` too: +RP2 needs the extra `gpio:init/1` before `gpio:read/1` too: ```erlang Pin = 2, diff --git a/src/platforms/rp2040/.gitignore b/src/platforms/rp2/.gitignore similarity index 100% rename from src/platforms/rp2040/.gitignore rename to src/platforms/rp2/.gitignore diff --git a/src/platforms/rp2040/CMakeLists.txt b/src/platforms/rp2/CMakeLists.txt similarity index 100% rename from src/platforms/rp2040/CMakeLists.txt rename to src/platforms/rp2/CMakeLists.txt diff --git a/src/platforms/rp2040/pico_sdk_import.cmake b/src/platforms/rp2/pico_sdk_import.cmake similarity index 97% rename from src/platforms/rp2040/pico_sdk_import.cmake rename to src/platforms/rp2/pico_sdk_import.cmake index 780b4b093..043f4a2bc 100644 --- a/src/platforms/rp2040/pico_sdk_import.cmake +++ b/src/platforms/rp2/pico_sdk_import.cmake @@ -58,14 +58,14 @@ if (NOT PICO_SDK_PATH) FetchContent_Declare( pico_sdk GIT_REPOSITORY https://github.com/pguyot/pico-sdk # revert to raspberrypi once PR 1101 is merged - GIT_TAG v1.5.1+conditional-variables+cyw43-assoc-callback # revert to master once pico-sdk PR 1101 is merged + cyw43-driver PR 91 + GIT_TAG v2.0.0+conditional-variables+cyw43-assoc-callback # revert to master once pico-sdk PR 1101 is merged + cyw43-driver PR 91 GIT_SUBMODULES_RECURSE FALSE ) else () FetchContent_Declare( pico_sdk GIT_REPOSITORY https://github.com/pguyot/pico-sdk # revert to raspberrypi once PR 1101 is merged - GIT_TAG v1.5.1+conditional-variables+cyw43-assoc-callback # revert to master once pico-sdk PR 1101 is merged + cyw43-driver PR 91 + GIT_TAG v2.0.0+conditional-variables+cyw43-assoc-callback # revert to master once pico-sdk PR 1101 is merged + cyw43-driver PR 91 ) endif () diff --git a/src/platforms/rp2040/src/CMakeLists.txt b/src/platforms/rp2/src/CMakeLists.txt similarity index 97% rename from src/platforms/rp2040/src/CMakeLists.txt rename to src/platforms/rp2/src/CMakeLists.txt index ab2fdcbee..c79433551 100644 --- a/src/platforms/rp2040/src/CMakeLists.txt +++ b/src/platforms/rp2/src/CMakeLists.txt @@ -30,7 +30,10 @@ endif() # libAtomVM needs to find Pico's platform_smp.h and platform_atomic.h headers set(HAVE_PLATFORM_SMP_H ON) +# RP2040 needs platform atomic, RP2350 doesn't +if(PICO_RP2040) set(HAVE_PLATFORM_ATOMIC_H ON) +endif() add_subdirectory(../../../libAtomVM libAtomVM) target_link_libraries(AtomVM PUBLIC libAtomVM) # Also add lib where platform_smp.h and platform_atomic headers are diff --git a/src/platforms/rp2040/src/lib/CMakeLists.txt b/src/platforms/rp2/src/lib/CMakeLists.txt similarity index 96% rename from src/platforms/rp2040/src/lib/CMakeLists.txt rename to src/platforms/rp2/src/lib/CMakeLists.txt index 64a766f61..699326b9d 100644 --- a/src/platforms/rp2040/src/lib/CMakeLists.txt +++ b/src/platforms/rp2/src/lib/CMakeLists.txt @@ -24,7 +24,7 @@ set(HEADER_FILES gpiodriver.h platform_defaultatoms.h platform_smp.h - rp2040_sys.h + rp2_sys.h ../../../../libAtomVM/otp_crypto.h ../../../../libAtomVM/portnifloader.h ) @@ -57,7 +57,6 @@ target_link_libraries( libAtomVM${PLATFORM_LIB_SUFFIX} PUBLIC hardware_gpio - hardware_rtc hardware_sync pico_float pico_mbedtls @@ -67,6 +66,10 @@ target_link_libraries( pico_sync pico_time) +if (PICO_RP2040) + target_link_libraries(libAtomVM${PLATFORM_LIB_SUFFIX} PUBLIC hardware_rtc) +endif() + if (NOT AVM_USE_32BIT_FLOAT) target_link_libraries(libAtomVM${PLATFORM_LIB_SUFFIX} PUBLIC pico_double) endif() diff --git a/src/platforms/rp2040/src/lib/gpiodriver.c b/src/platforms/rp2/src/lib/gpiodriver.c similarity index 91% rename from src/platforms/rp2040/src/lib/gpiodriver.c rename to src/platforms/rp2/src/lib/gpiodriver.c index 19efdc787..7bedcb828 100644 --- a/src/platforms/rp2040/src/lib/gpiodriver.c +++ b/src/platforms/rp2/src/lib/gpiodriver.c @@ -30,7 +30,7 @@ #include "defaultatoms.h" #include "interop.h" -#include "rp2040_sys.h" +#include "rp2_sys.h" #include "trace.h" #define WL_ATOM globalcontext_make_atom(ctx->global, ATOM_STR("\x2", "wl")) @@ -45,30 +45,30 @@ static const AtomStringIntPair pin_mode_table[] = { enum { - AtomVMRP2040GPIOFloating = 0, - AtomVMRP2040GPIOPullUp = 1, - AtomVMRP2040GPIOPullDown = 2, + AtomVMRP2GPIOFloating = 0, + AtomVMRP2GPIOPullUp = 1, + AtomVMRP2GPIOPullDown = 2, }; static const AtomStringIntPair pull_mode_table[] = { - { ATOM_STR("\x2", "up"), AtomVMRP2040GPIOPullUp }, - { ATOM_STR("\x4", "down"), AtomVMRP2040GPIOPullDown }, - { ATOM_STR("\x7", "up_down"), AtomVMRP2040GPIOPullUp | AtomVMRP2040GPIOPullDown }, - { ATOM_STR("\x8", "floating"), AtomVMRP2040GPIOFloating }, + { ATOM_STR("\x2", "up"), AtomVMRP2GPIOPullUp }, + { ATOM_STR("\x4", "down"), AtomVMRP2GPIOPullDown }, + { ATOM_STR("\x7", "up_down"), AtomVMRP2GPIOPullUp | AtomVMRP2GPIOPullDown }, + { ATOM_STR("\x8", "floating"), AtomVMRP2GPIOFloating }, SELECT_INT_DEFAULT(-1) }; enum gpio_pin_level { - AtomVMRP2040GPIOInvalid = -1, - AtomVMRP2040GPIOLow = 0, - AtomVMRP2040GPIOHigh = 1 + AtomVMRP2GPIOInvalid = -1, + AtomVMRP2GPIOLow = 0, + AtomVMRP2GPIOHigh = 1 }; static const AtomStringIntPair pin_level_table[] = { - { ATOM_STR("\x3", "low"), AtomVMRP2040GPIOLow }, - { ATOM_STR("\x4", "high"), AtomVMRP2040GPIOHigh }, - SELECT_INT_DEFAULT(AtomVMRP2040GPIOInvalid) + { ATOM_STR("\x3", "low"), AtomVMRP2GPIOLow }, + { ATOM_STR("\x4", "high"), AtomVMRP2GPIOHigh }, + SELECT_INT_DEFAULT(AtomVMRP2GPIOInvalid) }; static term nif_gpio_init(Context *ctx, int argc, term argv[]) @@ -129,7 +129,7 @@ static term nif_gpio_set_pin_pull(Context *ctx, int argc, term argv[]) if (UNLIKELY(pull_mode < 0)) { RAISE_ERROR(BADARG_ATOM); } - gpio_set_pulls(gpio_num, pull_mode & AtomVMRP2040GPIOPullUp, pull_mode & AtomVMRP2040GPIOPullDown); + gpio_set_pulls(gpio_num, pull_mode & AtomVMRP2GPIOPullUp, pull_mode & AtomVMRP2GPIOPullDown); return OK_ATOM; } diff --git a/src/platforms/rp2040/src/lib/gpiodriver.h b/src/platforms/rp2/src/lib/gpiodriver.h similarity index 100% rename from src/platforms/rp2040/src/lib/gpiodriver.h rename to src/platforms/rp2/src/lib/gpiodriver.h diff --git a/src/platforms/rp2040/src/lib/lwipopts.h b/src/platforms/rp2/src/lib/lwipopts.h similarity index 100% rename from src/platforms/rp2040/src/lib/lwipopts.h rename to src/platforms/rp2/src/lib/lwipopts.h diff --git a/src/platforms/rp2040/src/lib/mbedtls_config.h b/src/platforms/rp2/src/lib/mbedtls_config.h similarity index 100% rename from src/platforms/rp2040/src/lib/mbedtls_config.h rename to src/platforms/rp2/src/lib/mbedtls_config.h diff --git a/src/platforms/rp2040/src/lib/networkdriver.c b/src/platforms/rp2/src/lib/networkdriver.c similarity index 99% rename from src/platforms/rp2040/src/lib/networkdriver.c rename to src/platforms/rp2/src/lib/networkdriver.c index f428d0b16..91bc6e520 100644 --- a/src/platforms/rp2040/src/lib/networkdriver.c +++ b/src/platforms/rp2/src/lib/networkdriver.c @@ -25,7 +25,7 @@ #include #include -#include "rp2040_sys.h" +#include "rp2_sys.h" #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" diff --git a/src/platforms/rp2040/src/lib/otp_crypto_platform.c b/src/platforms/rp2/src/lib/otp_crypto_platform.c similarity index 97% rename from src/platforms/rp2040/src/lib/otp_crypto_platform.c rename to src/platforms/rp2/src/lib/otp_crypto_platform.c index 80adcd308..dc6280a30 100644 --- a/src/platforms/rp2040/src/lib/otp_crypto_platform.c +++ b/src/platforms/rp2/src/lib/otp_crypto_platform.c @@ -20,6 +20,6 @@ #include #include -#include +#include REGISTER_NIF_COLLECTION(otp_crypto, NULL, NULL, otp_crypto_nif_get_nif) diff --git a/src/platforms/rp2040/src/lib/otp_net_lwip_raw.c b/src/platforms/rp2/src/lib/otp_net_lwip_raw.c similarity index 99% rename from src/platforms/rp2040/src/lib/otp_net_lwip_raw.c rename to src/platforms/rp2/src/lib/otp_net_lwip_raw.c index dd60c61d6..5255601ba 100644 --- a/src/platforms/rp2040/src/lib/otp_net_lwip_raw.c +++ b/src/platforms/rp2/src/lib/otp_net_lwip_raw.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include diff --git a/src/platforms/rp2040/src/lib/otp_net_lwip_raw.h b/src/platforms/rp2/src/lib/otp_net_lwip_raw.h similarity index 100% rename from src/platforms/rp2040/src/lib/otp_net_lwip_raw.h rename to src/platforms/rp2/src/lib/otp_net_lwip_raw.h diff --git a/src/platforms/rp2040/src/lib/otp_socket_platform.c b/src/platforms/rp2/src/lib/otp_socket_platform.c similarity index 98% rename from src/platforms/rp2040/src/lib/otp_socket_platform.c rename to src/platforms/rp2/src/lib/otp_socket_platform.c index f257a4031..2cf5796c8 100644 --- a/src/platforms/rp2040/src/lib/otp_socket_platform.c +++ b/src/platforms/rp2/src/lib/otp_socket_platform.c @@ -22,7 +22,7 @@ #include #include -#include +#include struct OTPSocketNIFGlobalData { diff --git a/src/platforms/rp2040/src/lib/otp_socket_platform.h b/src/platforms/rp2/src/lib/otp_socket_platform.h similarity index 100% rename from src/platforms/rp2040/src/lib/otp_socket_platform.h rename to src/platforms/rp2/src/lib/otp_socket_platform.h diff --git a/src/platforms/rp2040/src/lib/otp_ssl_platform.c b/src/platforms/rp2/src/lib/otp_ssl_platform.c similarity index 97% rename from src/platforms/rp2040/src/lib/otp_ssl_platform.c rename to src/platforms/rp2/src/lib/otp_ssl_platform.c index f17a0a5c5..159536f73 100644 --- a/src/platforms/rp2040/src/lib/otp_ssl_platform.c +++ b/src/platforms/rp2/src/lib/otp_ssl_platform.c @@ -20,6 +20,6 @@ #include #include -#include +#include REGISTER_NIF_COLLECTION(otp_ssl, otp_ssl_init, NULL, otp_ssl_nif_get_nif) diff --git a/src/platforms/rp2040/src/lib/platform_atomic.h b/src/platforms/rp2/src/lib/platform_atomic.h similarity index 100% rename from src/platforms/rp2040/src/lib/platform_atomic.h rename to src/platforms/rp2/src/lib/platform_atomic.h diff --git a/src/platforms/rp2040/src/lib/platform_defaultatoms.c b/src/platforms/rp2/src/lib/platform_defaultatoms.c similarity index 100% rename from src/platforms/rp2040/src/lib/platform_defaultatoms.c rename to src/platforms/rp2/src/lib/platform_defaultatoms.c diff --git a/src/platforms/rp2040/src/lib/platform_defaultatoms.h b/src/platforms/rp2/src/lib/platform_defaultatoms.h similarity index 100% rename from src/platforms/rp2040/src/lib/platform_defaultatoms.h rename to src/platforms/rp2/src/lib/platform_defaultatoms.h diff --git a/src/platforms/rp2040/src/lib/platform_nifs.c b/src/platforms/rp2/src/lib/platform_nifs.c similarity index 98% rename from src/platforms/rp2040/src/lib/platform_nifs.c rename to src/platforms/rp2/src/lib/platform_nifs.c index e0f5310fb..5f2ea026b 100644 --- a/src/platforms/rp2040/src/lib/platform_nifs.c +++ b/src/platforms/rp2/src/lib/platform_nifs.c @@ -22,13 +22,15 @@ #include "platform_defaultatoms.h" #include "platform_nifs.h" -#include "rp2040_sys.h" +#include "rp2_sys.h" // Pico SDK #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" +#if PICO_RP2040 #include +#endif #include #ifdef LIB_PICO_CYW43_ARCH @@ -58,6 +60,7 @@ static term nif_atomvm_platform(Context *ctx, int argc, term argv[]) return PICO_ATOM; } +#if PICO_RP2040 static term nif_pico_rtc_set_datetime(Context *ctx, int argc, term argv[]) { UNUSED(argc); @@ -137,6 +140,7 @@ static term nif_pico_rtc_set_datetime(Context *ctx, int argc, term argv[]) return OK_ATOM; } +#endif #ifdef LIB_PICO_CYW43_ARCH static term nif_pico_cyw43_arch_gpio_get(Context *ctx, int argc, term argv[]) @@ -163,10 +167,12 @@ static const struct Nif atomvm_platform_nif = { .base.type = NIFFunctionType, .nif_ptr = nif_atomvm_platform }; +#if PICO_RP2040 static const struct Nif pico_rtc_set_datetime_nif = { .base.type = NIFFunctionType, .nif_ptr = nif_pico_rtc_set_datetime }; +#endif #ifdef LIB_PICO_CYW43_ARCH static const struct Nif pico_cyw43_arch_gpio_get_nif = { .base.type = NIFFunctionType, @@ -184,10 +190,12 @@ const struct Nif *platform_nifs_get_nif(const char *nifname) TRACE("Resolved platform nif %s ...\n", nifname); return &atomvm_platform_nif; } +#if PICO_RP2040 if (strcmp("pico:rtc_set_datetime/1", nifname) == 0) { TRACE("Resolved platform nif %s ...\n", nifname); return &pico_rtc_set_datetime_nif; } +#endif #ifdef LIB_PICO_CYW43_ARCH if (strcmp("pico:cyw43_arch_gpio_get/1", nifname) == 0) { TRACE("Resolved platform nif %s ...\n", nifname); diff --git a/src/platforms/rp2040/src/lib/platform_smp.h b/src/platforms/rp2/src/lib/platform_smp.h similarity index 100% rename from src/platforms/rp2040/src/lib/platform_smp.h rename to src/platforms/rp2/src/lib/platform_smp.h diff --git a/src/platforms/rp2040/src/lib/rp2040_sys.h b/src/platforms/rp2/src/lib/rp2_sys.h similarity index 97% rename from src/platforms/rp2040/src/lib/rp2040_sys.h rename to src/platforms/rp2/src/lib/rp2_sys.h index abf7c751e..a7cd4413b 100644 --- a/src/platforms/rp2040/src/lib/rp2040_sys.h +++ b/src/platforms/rp2/src/lib/rp2_sys.h @@ -18,8 +18,8 @@ * SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later */ -#ifndef _RP2040_SYS_H_ -#define _RP2040_SYS_H_ +#ifndef _RP2_SYS_H_ +#define _RP2_SYS_H_ #include @@ -74,7 +74,7 @@ bool sys_try_post_listener_event_from_isr(GlobalContext *global, listener_event_ */ void sys_unregister_listener_from_event(GlobalContext *global, listener_event_t listener_queue); -struct RP2040PlatformData +struct RP2PlatformData { #ifndef AVM_NO_SMP mutex_t event_poll_mutex; diff --git a/src/platforms/rp2040/src/lib/smp.c b/src/platforms/rp2/src/lib/smp.c similarity index 100% rename from src/platforms/rp2040/src/lib/smp.c rename to src/platforms/rp2/src/lib/smp.c diff --git a/src/platforms/rp2040/src/lib/sys.c b/src/platforms/rp2/src/lib/sys.c similarity index 92% rename from src/platforms/rp2040/src/lib/sys.c rename to src/platforms/rp2/src/lib/sys.c index b4d4ac612..aeffd7287 100644 --- a/src/platforms/rp2040/src/lib/sys.c +++ b/src/platforms/rp2/src/lib/sys.c @@ -28,7 +28,6 @@ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" -#include #include #include #include @@ -55,8 +54,15 @@ #include #include +#ifdef HAVE_PLATFORM_ATOMIC_H #include "platform_atomic.h" -#include "rp2040_sys.h" +#else +#if defined(HAVE_ATOMIC) +#include +#endif +#endif + +#include "rp2_sys.h" // #define ENABLE_TRACE #include "trace.h" @@ -69,7 +75,7 @@ struct NifCollectionDefListItem *nif_collection_list; void sys_init_platform(GlobalContext *glb) { - struct RP2040PlatformData *platform = malloc(sizeof(struct RP2040PlatformData)); + struct RP2PlatformData *platform = malloc(sizeof(struct RP2PlatformData)); glb->platform_data = platform; #ifndef AVM_NO_SMP mutex_init(&platform->event_poll_mutex); @@ -77,7 +83,9 @@ void sys_init_platform(GlobalContext *glb) #endif queue_init(&platform->event_queue, sizeof(queue_t *), EVENT_QUEUE_LEN); +#ifdef HAVE_PLATFORM_ATOMIC_H atomic_init(); +#endif #ifdef LIB_PICO_CYW43_ARCH cyw43_arch_init(); @@ -105,7 +113,7 @@ void sys_free_platform(GlobalContext *glb) cyw43_arch_deinit(); #endif - struct RP2040PlatformData *platform = glb->platform_data; + struct RP2PlatformData *platform = glb->platform_data; queue_free(&platform->event_queue); if (platform->random_is_initialized) { @@ -123,12 +131,14 @@ void sys_free_platform(GlobalContext *glb) free(platform); +#ifdef HAVE_PLATFORM_ATOMIC_H atomic_free(); +#endif } bool sys_try_post_listener_event_from_isr(GlobalContext *glb, listener_event_t listener_queue, const void *event) { - struct RP2040PlatformData *platform = glb->platform_data; + struct RP2PlatformData *platform = glb->platform_data; if (UNLIKELY(!queue_try_add(listener_queue, event))) { fprintf(stderr, "Lost event from ISR as listener queue is full. System is overloaded or EVENT_QUEUE_LEN is too low\n"); return false; @@ -175,7 +185,7 @@ bool sys_try_post_listener_event_from_isr(GlobalContext *glb, listener_event_t l void sys_poll_events(GlobalContext *glb, int timeout_ms) { - struct RP2040PlatformData *platform = glb->platform_data; + struct RP2PlatformData *platform = glb->platform_data; #ifndef AVM_NO_SMP if (timeout_ms != 0) { mutex_enter_blocking(&platform->event_poll_mutex); @@ -204,7 +214,7 @@ void sys_poll_events(GlobalContext *glb, int timeout_ms) #ifndef AVM_NO_SMP void sys_signal(GlobalContext *glb) { - struct RP2040PlatformData *platform = glb->platform_data; + struct RP2PlatformData *platform = glb->platform_data; cond_signal(&platform->event_poll_cond); } #endif @@ -401,8 +411,8 @@ void sys_unregister_listener_from_event(GlobalContext *global, listener_event_t int sys_mbedtls_entropy_func(void *entropy, unsigned char *buf, size_t size) { #ifndef MBEDTLS_THREADING_C - struct RP2040PlatformData *platform - = CONTAINER_OF(entropy, struct RP2040PlatformData, entropy_ctx); + struct RP2PlatformData *platform + = CONTAINER_OF(entropy, struct RP2PlatformData, entropy_ctx); SMP_MUTEX_LOCK(platform->entropy_mutex); int result = mbedtls_entropy_func(entropy, buf, size); SMP_MUTEX_UNLOCK(platform->entropy_mutex); @@ -415,7 +425,7 @@ int sys_mbedtls_entropy_func(void *entropy, unsigned char *buf, size_t size) mbedtls_entropy_context *sys_mbedtls_get_entropy_context_lock(GlobalContext *global) { - struct RP2040PlatformData *platform = global->platform_data; + struct RP2PlatformData *platform = global->platform_data; SMP_MUTEX_LOCK(platform->entropy_mutex); @@ -429,13 +439,13 @@ mbedtls_entropy_context *sys_mbedtls_get_entropy_context_lock(GlobalContext *glo void sys_mbedtls_entropy_context_unlock(GlobalContext *global) { - struct RP2040PlatformData *platform = global->platform_data; + struct RP2PlatformData *platform = global->platform_data; SMP_MUTEX_UNLOCK(platform->entropy_mutex); } mbedtls_ctr_drbg_context *sys_mbedtls_get_ctr_drbg_context_lock(GlobalContext *global) { - struct RP2040PlatformData *platform = global->platform_data; + struct RP2PlatformData *platform = global->platform_data; SMP_MUTEX_LOCK(platform->random_mutex); @@ -446,7 +456,7 @@ mbedtls_ctr_drbg_context *sys_mbedtls_get_ctr_drbg_context_lock(GlobalContext *g // Safe to unlock it now, sys_mbedtls_entropy_func will lock it again later sys_mbedtls_entropy_context_unlock(global); - const char *seed = "AtomVM RP2040 Mbed-TLS initial seed."; + const char *seed = "AtomVM RP2 Mbed-TLS initial seed."; int seed_len = strlen(seed); int seed_err = mbedtls_ctr_drbg_seed(&platform->random_ctx, sys_mbedtls_entropy_func, entropy_ctx, (const unsigned char *) seed, seed_len); @@ -461,6 +471,6 @@ mbedtls_ctr_drbg_context *sys_mbedtls_get_ctr_drbg_context_lock(GlobalContext *g void sys_mbedtls_ctr_drbg_context_unlock(GlobalContext *global) { - struct RP2040PlatformData *platform = global->platform_data; + struct RP2PlatformData *platform = global->platform_data; SMP_MUTEX_UNLOCK(platform->random_mutex); } diff --git a/src/platforms/rp2040/src/main.c b/src/platforms/rp2/src/main.c similarity index 99% rename from src/platforms/rp2040/src/main.c rename to src/platforms/rp2/src/main.c index 3f531a10c..8ac8639c7 100644 --- a/src/platforms/rp2040/src/main.c +++ b/src/platforms/rp2/src/main.c @@ -40,7 +40,7 @@ #include #include -#include "rp2040_sys.h" +#include "rp2_sys.h" extern char __flash_binary_end; diff --git a/src/platforms/rp2040/tests/.gitignore b/src/platforms/rp2/tests/.gitignore similarity index 100% rename from src/platforms/rp2040/tests/.gitignore rename to src/platforms/rp2/tests/.gitignore diff --git a/src/platforms/rp2040/tests/CMakeLists.txt b/src/platforms/rp2/tests/CMakeLists.txt similarity index 66% rename from src/platforms/rp2040/tests/CMakeLists.txt rename to src/platforms/rp2/tests/CMakeLists.txt index 9f4791760..3bb2a50c9 100644 --- a/src/platforms/rp2040/tests/CMakeLists.txt +++ b/src/platforms/rp2/tests/CMakeLists.txt @@ -23,36 +23,36 @@ cmake_minimum_required (VERSION 3.14) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../../CMakeModules") include(FetchUnity) -add_executable(rp2040_tests test_main.c) +add_executable(rp2_tests test_main.c) -target_compile_features(rp2040_tests PUBLIC c_std_11) +target_compile_features(rp2_tests PUBLIC c_std_11) if(CMAKE_COMPILER_IS_GNUCC) - target_compile_options(rp2040_tests PUBLIC -ggdb) - target_compile_options(rp2040_tests PRIVATE -Wall -pedantic -Wextra) + target_compile_options(rp2_tests PUBLIC -ggdb) + target_compile_options(rp2_tests PRIVATE -Wall -pedantic -Wextra) endif() # libAtomVM needs to find Pico's platform_smp.h and platform_atomic.h headers set(HAVE_PLATFORM_SMP_H ON) set(HAVE_PLATFORM_ATOMIC_H ON) -target_link_libraries(rp2040_tests PUBLIC libAtomVM) +target_link_libraries(rp2_tests PUBLIC libAtomVM) # Also add lib where platform_smp.h and platform_atomic.h headers are -target_include_directories(rp2040_tests PUBLIC ../src/lib) +target_include_directories(rp2_tests PUBLIC ../src/lib) -target_link_libraries(rp2040_tests PUBLIC hardware_regs pico_stdlib pico_binary_info unity) +target_link_libraries(rp2_tests PUBLIC hardware_regs pico_stdlib pico_binary_info unity) set( PLATFORM_LIB_SUFFIX ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR} ) -target_link_libraries(rp2040_tests PRIVATE libAtomVM${PLATFORM_LIB_SUFFIX}) +target_link_libraries(rp2_tests PRIVATE libAtomVM${PLATFORM_LIB_SUFFIX}) # could not get rp2040js to work with stdio USB -pico_enable_stdio_usb(rp2040_tests 0) -pico_enable_stdio_uart(rp2040_tests 1) +pico_enable_stdio_usb(rp2_tests 0) +pico_enable_stdio_uart(rp2_tests 1) # create map/bin/hex/uf2 file in addition to ELF. -pico_add_extra_outputs(rp2040_tests) +pico_add_extra_outputs(rp2_tests) add_subdirectory(test_erl_sources) -add_dependencies(rp2040_tests rp2040_test_modules) +add_dependencies(rp2_tests rp2_test_modules) diff --git a/src/platforms/rp2040/tests/package-lock.json b/src/platforms/rp2/tests/package-lock.json similarity index 100% rename from src/platforms/rp2040/tests/package-lock.json rename to src/platforms/rp2/tests/package-lock.json diff --git a/src/platforms/rp2040/tests/package-lock.json.license b/src/platforms/rp2/tests/package-lock.json.license similarity index 100% rename from src/platforms/rp2040/tests/package-lock.json.license rename to src/platforms/rp2/tests/package-lock.json.license diff --git a/src/platforms/rp2040/tests/package.json b/src/platforms/rp2/tests/package.json similarity index 100% rename from src/platforms/rp2040/tests/package.json rename to src/platforms/rp2/tests/package.json diff --git a/src/platforms/rp2040/tests/package.json.license b/src/platforms/rp2/tests/package.json.license similarity index 100% rename from src/platforms/rp2040/tests/package.json.license rename to src/platforms/rp2/tests/package.json.license diff --git a/src/platforms/rp2040/tests/run-tests.ts b/src/platforms/rp2/tests/run-tests.ts similarity index 100% rename from src/platforms/rp2040/tests/run-tests.ts rename to src/platforms/rp2/tests/run-tests.ts diff --git a/src/platforms/rp2040/tests/test_erl_sources/CMakeLists.txt b/src/platforms/rp2/tests/test_erl_sources/CMakeLists.txt similarity index 83% rename from src/platforms/rp2040/tests/test_erl_sources/CMakeLists.txt rename to src/platforms/rp2/tests/test_erl_sources/CMakeLists.txt index 17a638473..6007ce23f 100644 --- a/src/platforms/rp2040/tests/test_erl_sources/CMakeLists.txt +++ b/src/platforms/rp2/tests/test_erl_sources/CMakeLists.txt @@ -21,7 +21,7 @@ ExternalProject_Add(HostAtomVM SOURCE_DIR ../../../../../../ INSTALL_COMMAND cmake -E echo "Skipping install step." - BUILD_COMMAND cmake --build . --target=atomvmlib --target=PackBEAM + BUILD_COMMAND cmake --build . --target=atomvmlib --target=PackBEAM --target=uf2tool ) function(compile_erlang module_name module_src_dir) @@ -41,8 +41,8 @@ compile_erlang(test_smp "") compile_erlang(test_crypto ../../../esp32/test/main/test_erl_sources/) add_custom_command( - OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/rp2040_test_modules.avm" - COMMAND HostAtomVM-prefix/src/HostAtomVM-build/tools/packbeam/PackBEAM -i rp2040_test_modules.avm + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/rp2_test_modules.avm" + COMMAND HostAtomVM-prefix/src/HostAtomVM-build/tools/packbeam/PackBEAM -i rp2_test_modules.avm HostAtomVM-prefix/src/HostAtomVM-build/libs/atomvmlib.avm test_clocks.beam test_smp.beam @@ -56,21 +56,21 @@ add_custom_command( VERBATIM ) -set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/rp2040_test_modules.avm") +set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/rp2_test_modules.avm") add_custom_command( - OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/rp2040_test_modules.uf2" + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/rp2_test_modules.uf2" COMMAND HostAtomVM-prefix/src/HostAtomVM-build/tools/uf2tool/uf2tool create - -o rp2040_test_modules.uf2 - -s 0x10100000 "${CMAKE_CURRENT_BINARY_DIR}/rp2040_test_modules.avm" + -o rp2_test_modules.uf2 + -s 0x10100000 "${CMAKE_CURRENT_BINARY_DIR}/rp2_test_modules.avm" DEPENDS HostAtomVM - "${CMAKE_CURRENT_BINARY_DIR}/rp2040_test_modules.avm" + "${CMAKE_CURRENT_BINARY_DIR}/rp2_test_modules.avm" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} VERBATIM ) -set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/rp2040_test_modules.uf2") +set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/rp2_test_modules.uf2") -add_custom_target(rp2040_test_modules DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/rp2040_test_modules.uf2") +add_custom_target(rp2_test_modules DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/rp2_test_modules.uf2") diff --git a/src/platforms/rp2040/tests/test_erl_sources/test_clocks.erl b/src/platforms/rp2/tests/test_erl_sources/test_clocks.erl similarity index 100% rename from src/platforms/rp2040/tests/test_erl_sources/test_clocks.erl rename to src/platforms/rp2/tests/test_erl_sources/test_clocks.erl diff --git a/src/platforms/rp2040/tests/test_erl_sources/test_smp.erl b/src/platforms/rp2/tests/test_erl_sources/test_smp.erl similarity index 100% rename from src/platforms/rp2040/tests/test_erl_sources/test_smp.erl rename to src/platforms/rp2/tests/test_erl_sources/test_smp.erl diff --git a/src/platforms/rp2040/tests/test_main.c b/src/platforms/rp2/tests/test_main.c similarity index 99% rename from src/platforms/rp2040/tests/test_main.c rename to src/platforms/rp2/tests/test_main.c index 62e3fa1a1..8aebf51d0 100644 --- a/src/platforms/rp2040/tests/test_main.c +++ b/src/platforms/rp2/tests/test_main.c @@ -42,7 +42,7 @@ #include #include "platform_defaultatoms.h" -#include "rp2040_sys.h" +#include "rp2_sys.h" #ifndef AVM_NO_SMP #include "smp.h" diff --git a/src/platforms/rp2040/tests/tsconfig.json b/src/platforms/rp2/tests/tsconfig.json similarity index 100% rename from src/platforms/rp2040/tests/tsconfig.json rename to src/platforms/rp2/tests/tsconfig.json diff --git a/src/platforms/rp2040/tests/tsconfig.json.license b/src/platforms/rp2/tests/tsconfig.json.license similarity index 100% rename from src/platforms/rp2040/tests/tsconfig.json.license rename to src/platforms/rp2/tests/tsconfig.json.license diff --git a/tools/uf2tool/CMakeLists.txt b/tools/uf2tool/CMakeLists.txt index 359358995..894732fa9 100644 --- a/tools/uf2tool/CMakeLists.txt +++ b/tools/uf2tool/CMakeLists.txt @@ -21,16 +21,12 @@ cmake_minimum_required (VERSION 3.13) project (UF2Tool) -include(${CMAKE_SOURCE_DIR}/CMakeModules/GetVersion.cmake) - -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/uf2tool.erl ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/uf2tool @ONLY) -file(COPY ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/uf2tool +file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/rebar.config DESTINATION ${CMAKE_CURRENT_BINARY_DIR} - FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) add_custom_target( uf2tool ALL - COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/uf2tool + COMMAND rebar3 escriptize && cp _build/default/bin/uf2tool . VERBATIM ) diff --git a/tools/uf2tool/rebar.config b/tools/uf2tool/rebar.config new file mode 100644 index 000000000..6145da3b4 --- /dev/null +++ b/tools/uf2tool/rebar.config @@ -0,0 +1,24 @@ +% +% This file is part of AtomVM. +% +% Copyright 2024 Paul Guyot +% +% Licensed under the Apache License, Version 2.0 (the "License"); +% you may not use this file except in compliance with the License. +% You may obtain a copy of the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, +% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +% See the License for the specific language governing permissions and +% limitations under the License. +% +% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later +% + +{deps, [ + uf2tool +]}. +{escript_main_app, uf2tool}. diff --git a/tools/uf2tool/uf2tool.erl b/tools/uf2tool/uf2tool.erl deleted file mode 100644 index c7291e860..000000000 --- a/tools/uf2tool/uf2tool.erl +++ /dev/null @@ -1,164 +0,0 @@ -#!/usr/bin/env escript -% -% This file is part of AtomVM. -% -% Copyright 2022 Paul Guyot -% -% Licensed under the Apache License, Version 2.0 (the "License"); -% you may not use this file except in compliance with the License. -% You may obtain a copy of the License at -% -% http://www.apache.org/licenses/LICENSE-2.0 -% -% Unless required by applicable law or agreed to in writing, software -% distributed under the License is distributed on an "AS IS" BASIS, -% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -% See the License for the specific language governing permissions and -% limitations under the License. -% -% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later -% - --module(uf2tool). - --export([main/1]). --mode(compile). - -main([]) -> - io:format("UF2 tool for AtomVM usage on Pico\n"); -main(["-h"]) -> - usage(); -main(["help"]) -> - usage(); -main(["join", "-o", Output | Sources]) when length(Sources) > 1 -> - uf2join(Output, Sources); -main(["create", "-o", Output, "-s", StartAddrStr, Image]) -> - StartAddr = parse_addr(StartAddrStr), - uf2create(Output, StartAddr, Image); -main(_) -> - io:format("Syntax error\n"), - usage(), - erlang:halt(2). - -usage() -> - io:format("UF2 Tool, AtomVM version @ATOMVM_VERSION@\n\n"), - io:format("Usage:\n"), - io:format(" uf2tool help | -h\n"), - io:format(" Display this message\n\n"), - io:format(" uf2tool join -o combined.uf2 first.uf2 second.uf2...\n"), - io:format(" Join two or more UF2 binaries\n\n"), - io:format(" uf2tool create -o new.uf2 -s start_addr image.avm\n"), - io:format(" Create a UF2 image from a binary file (image.avm), suitable for the Pico\n"), - ok. - -parse_addr("0x" ++ AddrHex) -> - list_to_integer(AddrHex, 16); -parse_addr("16#" ++ AddrHex) -> - list_to_integer(AddrHex, 16); -parse_addr(AddrDec) -> - list_to_integer(AddrDec). - -%%% UF2 defines --define(UF2_MAGIC_START0, 16#0A324655). --define(UF2_MAGIC_START1, 16#9E5D5157). --define(UF2_MAGIC_END, 16#0AB16F30). - --define(UF2_FLAG_FAMILY_ID_PRESENT, 16#00002000). - -%%% Pico defines --define(UF2_PICO_FLAGS, ?UF2_FLAG_FAMILY_ID_PRESENT). --define(UF2_PICO_PAGE_SIZE, 256). --define(UF2_PICO_FAMILY_ID, 16#E48BFF56). - -%%% - -uf2join(OutputPath, Sources) -> - SourceBins = [Bin || {ok, Bin} <- [file:read_file(Source) || Source <- Sources]], - BlocksCount = lists:sum([byte_size(SourceBin) || SourceBin <- SourceBins]) div 512, - {BlocksCount, OutputBinsLR} = lists:foldl( - fun(SourceBin, {StartBlock, Acc}) -> - {NewBlockStart, RewrittenBin} = rewrite_block_indices( - StartBlock, BlocksCount, SourceBin - ), - {NewBlockStart, [RewrittenBin | Acc]} - end, - {0, []}, - SourceBins - ), - ok = file:write_file(OutputPath, lists:reverse(OutputBinsLR)). - -rewrite_block_indices(BlockIndex, BlocksCount, Bin) -> - rewrite_block_indices0(BlockIndex, BlocksCount, Bin, []). - -rewrite_block_indices0(LastBlock, _BlocksCount, <<>>, Acc) -> - {LastBlock, lists:reverse(Acc)}; -rewrite_block_indices0(BlockIndex, BlocksCount, <>, Acc) -> - << - ?UF2_MAGIC_START0:32/little, - ?UF2_MAGIC_START1:32/little, - Flags:32/little, - TargetAddr:32/little, - PageSize:32/little, - _BlockNo:32/little, - _NumBlocks:32/little, - FamilyIdOrFileSize:32/little, - Data:476/binary, - ?UF2_MAGIC_END:32/little - >> = Page, - Rewritten = << - ?UF2_MAGIC_START0:32/little, - ?UF2_MAGIC_START1:32/little, - Flags:32/little, - TargetAddr:32/little, - PageSize:32/little, - BlockIndex:32/little, - BlocksCount:32/little, - FamilyIdOrFileSize:32/little, - Data:476/binary, - ?UF2_MAGIC_END:32/little - >>, - rewrite_block_indices0(BlockIndex + 1, BlocksCount, Tail, [Rewritten | Acc]). - -uf2create(OutputPath, StartAddr, ImagePath) -> - {ok, ImageBin} = file:read_file(ImagePath), - BlocksCount0 = byte_size(ImageBin) div ?UF2_PICO_PAGE_SIZE, - BlocksCount = - BlocksCount0 + - if - byte_size(ImageBin) rem ?UF2_PICO_PAGE_SIZE =:= 0 -> 0; - true -> 1 - end, - OutputBin = uf2create0(0, BlocksCount, StartAddr, ImageBin, []), - ok = file:write_file(OutputPath, OutputBin). - -uf2create0(_BlockIndex, _BlocksCount, _BaseAddr, <<>>, Acc) -> - lists:reverse(Acc); -uf2create0(BlockIndex, BlocksCount, BaseAddr, ImageBin, Acc) -> - {PageBin, Tail} = - if - byte_size(ImageBin) >= ?UF2_PICO_PAGE_SIZE -> - split_binary(ImageBin, ?UF2_PICO_PAGE_SIZE); - true -> - {ImageBin, <<>>} - end, - PaddedData = pad_binary(PageBin, 476), - Block = [ - << - ?UF2_MAGIC_START0:32/little, - ?UF2_MAGIC_START1:32/little, - ?UF2_PICO_FLAGS:32/little, - BaseAddr:32/little, - ?UF2_PICO_PAGE_SIZE:32/little, - BlockIndex:32/little, - BlocksCount:32/little, - ?UF2_PICO_FAMILY_ID:32/little - >>, - PaddedData, - <> - ], - uf2create0(BlockIndex + 1, BlocksCount, BaseAddr + ?UF2_PICO_PAGE_SIZE, Tail, [Block | Acc]). - -pad_binary(Bin, Len) -> - PadCount = Len - byte_size(Bin), - Pad = binary:copy(<<0>>, PadCount), - [Bin, Pad].