From 3fa5419ea0b1ee079b4b0a17191f32f7ca30379e Mon Sep 17 00:00:00 2001 From: Jon Nordby Date: Wed, 13 Aug 2025 19:13:40 +0200 Subject: [PATCH 01/10] CI: Try setup RISCV build for ESP32-C6 --- .github/workflows/build.yaml | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 71fde7d..f98f77f 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -133,6 +133,49 @@ jobs: path: dist + build-riscv: + runs-on: ubuntu-24.04 + env: + MPY_DIR: ./micropython + MICROPYTHON_BIN: ./micropython/ports/unix/build-nomodules/micropython + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - name: Install OS dependencies + run: sudo add-apt-repository universe + - uses: actions/setup-python@v5 + with: + python-version: '3.10' + - uses: actions/checkout@v4 + with: + repository: jonnor/micropython + path: micropython + ref: v1.25.0-armv6m-abs-relocations + - name: Install Python dependencies + run: pip install -r requirements.txt + + - name: Setup MicroPython ESP32 + working-directory: micropython + run: | + source tools/ci.sh && ci_esp32_idf_setup && ci_gcc_riscv_setup + make -C mpy-cross + - name: Setup submodules esp32 + working-directory: micropython/ports/esp32 + run: source ../../esp-idf/export.sh && make submodules + - name: Build custom firmware with extmod, ESP32 + run: | + source micropython/esp-idf/export.sh && pip install -r requirements.txt + make extmod PORT=esp32 BOARD=ESP32_GENERIC_C6 + - name: Build nadmod xtensawin + run: source micropython/esp-idf/export.sh && pip install -r requirements.txt && make dist ARCH=rv32imc V=1 + - name: Archive dist artifacts + uses: actions/upload-artifact@v4 + with: + name: emlearn-micropython-build-riscv + path: dist + + build-macos: runs-on: macos-latest env: From bd8491671a534f90d06ceeb33a436f86945d88aa Mon Sep 17 00:00:00 2001 From: Jon Nordby Date: Wed, 13 Aug 2025 19:22:51 +0200 Subject: [PATCH 02/10] CI: Disable C6 extmod build Says it uses too much FLASH --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index f98f77f..6db45bb 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -166,7 +166,7 @@ jobs: - name: Build custom firmware with extmod, ESP32 run: | source micropython/esp-idf/export.sh && pip install -r requirements.txt - make extmod PORT=esp32 BOARD=ESP32_GENERIC_C6 + echo make extmod PORT=esp32 BOARD=ESP32_GENERIC_C6 - name: Build nadmod xtensawin run: source micropython/esp-idf/export.sh && pip install -r requirements.txt && make dist ARCH=rv32imc V=1 - name: Archive dist artifacts From 7cb8858d3b4981ed72cb5bf9a96478cdbfb37387 Mon Sep 17 00:00:00 2001 From: Jon Nordby Date: Wed, 13 Aug 2025 19:27:17 +0200 Subject: [PATCH 03/10] README: Improve build instructions for developers --- README.md | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0237bd2..e809343 100644 --- a/README.md +++ b/README.md @@ -80,16 +80,34 @@ git clone https://github.com/emlearn/emlearn-micropython ``` #### Prerequisites -These come in addition to the prequisites described above. -Make sure you have the dependencies needed to build for your platform. -See [MicroPython: Building native modules](https://docs.micropython.org/en/latest/develop/natmod.html). +You will need to have **Python 3.10+ or later** already installed. -We assume that micropython is installed in the same place as this repository. +We assume that **micropython** git repository available. +It is assumed to be at the same level as this repository in the file system. If using another location, adjust `MPY_DIR` accordingly. - You should be using MicroPython 1.25 (or newer). +Make sure you have the **build toolchain** needed for your platform. +See [MicroPython: Building native modules](https://docs.micropython.org/en/latest/develop/natmod.html), +and the documentation for the MicroPython port/architecture of interest. + +#### Download dependencies + +Fetch git submodules + +``` +git submodule update --init +``` + +Recommend using a Python virtual environment. + +Install Python packages +``` +pip install -r requirements.txt +``` + + #### Build Build the .mpy native module From a9b8309c77b0cc37580e3ec732fcfcdfcaf249e6 Mon Sep 17 00:00:00 2001 From: Jon Nordby Date: Wed, 13 Aug 2025 19:31:48 +0200 Subject: [PATCH 04/10] emlearn_iir_q15: Remove custom memset --- src/emlearn_iir_q15/iir_filter.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/emlearn_iir_q15/iir_filter.c b/src/emlearn_iir_q15/iir_filter.c index a918029..41c6b0a 100644 --- a/src/emlearn_iir_q15/iir_filter.c +++ b/src/emlearn_iir_q15/iir_filter.c @@ -5,16 +5,6 @@ #include -// memset is used by some standard C constructs -#if !defined(__linux__) -void *memcpy(void *dst, const void *src, size_t n) { - return mp_fun_table.memmove_(dst, src, n); -} -void *memset(void *s, int c, size_t n) { - return mp_fun_table.memset_(s, c, n); -} -#endif - // MicroPython type for EmlIIR typedef struct _mp_obj_iir_filter_t { From 0b49d1ea112b662042ce4d68f5620e1029e0f1c9 Mon Sep 17 00:00:00 2001 From: Jon Nordby Date: Wed, 13 Aug 2025 20:00:54 +0200 Subject: [PATCH 05/10] Revert "emlearn_iir_q15: Remove custom memset" This reverts commit a9b8309c77b0cc37580e3ec732fcfcdfcaf249e6. --- src/emlearn_iir_q15/iir_filter.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/emlearn_iir_q15/iir_filter.c b/src/emlearn_iir_q15/iir_filter.c index 41c6b0a..a918029 100644 --- a/src/emlearn_iir_q15/iir_filter.c +++ b/src/emlearn_iir_q15/iir_filter.c @@ -5,6 +5,16 @@ #include +// memset is used by some standard C constructs +#if !defined(__linux__) +void *memcpy(void *dst, const void *src, size_t n) { + return mp_fun_table.memmove_(dst, src, n); +} +void *memset(void *s, int c, size_t n) { + return mp_fun_table.memset_(s, c, n); +} +#endif + // MicroPython type for EmlIIR typedef struct _mp_obj_iir_filter_t { From 34a9c6b9ff3f6ca1945d6647fc000520fb517c85 Mon Sep 17 00:00:00 2001 From: Jon Nordby Date: Wed, 13 Aug 2025 20:01:21 +0200 Subject: [PATCH 06/10] emlearn_iir_q15: Use weak linkage for memset and memcpy --- src/emlearn_iir_q15/iir_filter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/emlearn_iir_q15/iir_filter.c b/src/emlearn_iir_q15/iir_filter.c index a918029..d31a8f1 100644 --- a/src/emlearn_iir_q15/iir_filter.c +++ b/src/emlearn_iir_q15/iir_filter.c @@ -7,10 +7,10 @@ // memset is used by some standard C constructs #if !defined(__linux__) -void *memcpy(void *dst, const void *src, size_t n) { +__attribute__((weak)) void *memcpy(void *dst, const void *src, size_t n) { return mp_fun_table.memmove_(dst, src, n); } -void *memset(void *s, int c, size_t n) { +__attribute__((weak)) void *memset(void *s, int c, size_t n) { return mp_fun_table.memset_(s, c, n); } #endif From f57bba4b52b2099b5535d9c000405e49a6d7405b Mon Sep 17 00:00:00 2001 From: Jon Nordby Date: Wed, 13 Aug 2025 20:11:51 +0200 Subject: [PATCH 07/10] emlearn_iir_q15: Try avoid duplicate symbol on RISC-V --- src/emlearn_iir_q15/iir_filter.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/emlearn_iir_q15/iir_filter.c b/src/emlearn_iir_q15/iir_filter.c index d31a8f1..4a3f23b 100644 --- a/src/emlearn_iir_q15/iir_filter.c +++ b/src/emlearn_iir_q15/iir_filter.c @@ -5,12 +5,13 @@ #include -// memset is used by some standard C constructs -#if !defined(__linux__) -__attribute__((weak)) void *memcpy(void *dst, const void *src, size_t n) { +// memset is used by some standard C constructs. Missing on some platforms, but not all... +// Unfortunately cannot use weak symbols with mpy_ld +#if !(defined(__linux__) || defined(__riscv__)) +void *memcpy(void *dst, const void *src, size_t n) { return mp_fun_table.memmove_(dst, src, n); } -__attribute__((weak)) void *memset(void *s, int c, size_t n) { +void *memset(void *s, int c, size_t n) { return mp_fun_table.memset_(s, c, n); } #endif From a5b67da7181bb8c3eee1d3eeb8828926a20aec0d Mon Sep 17 00:00:00 2001 From: Jon Nordby Date: Wed, 13 Aug 2025 20:34:38 +0200 Subject: [PATCH 08/10] requirements: Add setuptools Otherwise will get missing "distutils" on Python 3.12+ --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 3a89384..9c11383 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ emlearn>=0.21.2 scikit-learn>=1.0.0 ar>=1.0.0 pyelftools>=0.31 +setuptools>=71.0.0 From 52ed3cf251ec8bdf336a57b51cd6bc1ba420c121 Mon Sep 17 00:00:00 2001 From: Jon Nordby Date: Wed, 13 Aug 2025 20:36:30 +0200 Subject: [PATCH 09/10] CI: Add RISC-V as dependency for deploy step --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 6db45bb..d325329 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -221,7 +221,7 @@ jobs: deploy-pages: permissions: contents: write - needs: [build-linux, build-arm, build-esp32, build-macos] + needs: [build-linux, build-arm, build-esp32, build-macos, build-riscv] runs-on: ubuntu-latest steps: From def779b886ece0eb7982eab5cd6be09bdd547e0a Mon Sep 17 00:00:00 2001 From: Jon Nordby Date: Wed, 13 Aug 2025 20:57:33 +0200 Subject: [PATCH 10/10] emlearn_iir_q15: Try other way to avoid memset on RISC-V --- src/emlearn_iir_q15/iir_filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/emlearn_iir_q15/iir_filter.c b/src/emlearn_iir_q15/iir_filter.c index 4a3f23b..382fa2d 100644 --- a/src/emlearn_iir_q15/iir_filter.c +++ b/src/emlearn_iir_q15/iir_filter.c @@ -7,7 +7,7 @@ // memset is used by some standard C constructs. Missing on some platforms, but not all... // Unfortunately cannot use weak symbols with mpy_ld -#if !(defined(__linux__) || defined(__riscv__)) +#if !(defined(__linux__) || defined(__riscv__) || defined(__riscv)) void *memcpy(void *dst, const void *src, size_t n) { return mp_fun_table.memmove_(dst, src, n); }