Closed MaxRondelli closed 2 months ago
If you could successfully compile the firmware, then the binary file with the extension .bin
should be in the /micropython/ports/esp32 folder. https://docs.micropython.org/en/latest/esp32/tutorial/intro.html
Yes, I can compile and flash the .bin
file that I download from Micropython page (here), as shown in the doc you sent me.
But when I try to import ulab, after flashing, I get a Module Error since it does not find the module.
How can I solve this issue?
Can you post the compilation report here? You should see something like this: https://github.com/v923z/micropython-ulab/actions/runs/10547613010/job/29220529520#step:8:287. How do you make sure that ulab is indeed in the firmware?
I am following esp32-based-boards doc but, as mentioned here, I fail the installation.
This is just how I flash the firmware with the .bin
from the link above.
max@Max:~$ python -m esptool --chip esp32 --port /dev/ttyUSB0 erase_flash
esptool.py v4.7.0
Serial port /dev/ttyUSB0
Connecting....
Chip is ESP32-D0WDQ6 (revision v1.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 30:ae:a4:f5:a0:6c
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 15.3s
Hard resetting via RTS pin...
max@Max:~$ python -m esptool --chip esp32 --port /dev/ttyUSB0 --baud 115200 write_flash -z 0x1000 /home/max/Downloads/ESP32_GENERIC-20240602-v1.23.0.bin
esptool.py v4.7.0
Serial port /dev/ttyUSB0
Connecting....
Chip is ESP32-D0WDQ6 (revision v1.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 30:ae:a4:f5:a0:6c
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Flash will be erased from 0x00001000 to 0x001a8fff...
Compressed 1734240 bytes to 1142447...
Wrote 1734240 bytes (1142447 compressed) at 0x00001000 in 100.7 seconds (effective 137.8 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
I think we're going off-tangent here: what I'd like to see is that ulab
in indeed compiled into your firmware. Lines like
CC /home/runner/work/micropython-ulab/micropython-ulab/code/scipy/linalg/linalg.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/scipy/optimize/optimize.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/scipy/signal/signal.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/scipy/special/special.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/ndarray_operators.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/ulab_tools.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/ndarray.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/numpy/ndarray/ndarray_iter.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/ndarray_properties.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/numpy/approx.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/numpy/bitwise.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/numpy/compare.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/numpy/carray/carray.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/numpy/carray/carray_tools.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/numpy/create.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/numpy/fft/fft.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/numpy/fft/fft_tools.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/numpy/filter.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/numpy/io/io.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/numpy/linalg/linalg.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/numpy/linalg/linalg_tools.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/numpy/numerical.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/numpy/poly.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/numpy/random/random.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/numpy/stats.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/numpy/transform.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/numpy/vector.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/numpy/numpy.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/scipy/scipy.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/user/user.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/utils/utils.c
CC /home/runner/work/micropython-ulab/micropython-ulab/code/ulab.c
would confirm that. What you've posted relates to the uploading of the firmware, and since that's linked to your hardware, I can't really comment on that.
You should, however, keep in mind that your firmware might be too large. If that's indeed the case, you can check out the instructions here: https://github.com/v923z/micropython-ulab?tab=readme-ov-file#what-to-do-if-the-firmware-is-too-large.
I have solved the issue. I write down the steps I did because it can be useful for somebody.
chmod +x esp32-cmake.sh
and then run the script ./esp32-cmake.sh
.micropython/ports/esp32/build-GENERIC/firmware.bin
you have the new firmware for your esp32 device with ulab lib module. esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 115200 write_flash -z 0x1000 micropython/ports/esp32/build-GENERIC/firmware.bin
/home/max/lib-esp32/ulab/code/numpy/random/random.c:82:28: error: 'MICROPY_PY_RANDOM_SEED_INIT_FUNC' undeclared (first use in this function); did you mean 'MICROPY_PY_URANDOM_SEED_INIT_FUNC'? generator->state = MICROPY_PY_RANDOM_SEED_INIT_FUNC; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MICROPY_PY_URANDOM_SEED_INIT_FUNC /home/max/lib-esp32/ulab/code/numpy/random/random.c:82:28: note: each undeclared identifier is reported only once for each function it appears in [1424/1468] Building C object esp-idf/main/CMak...max/lib-esp32/ulab/code/ndarray_operators.c.obj ninja: build stopped: subcommand failed. ninja failed with exit code 1 -e See https://github.com/micropython/micropython/wiki/Build-Troubleshooting make: *** [Makefile:54: all] Error 1
The error message indicates that MICROPY_PY_RANDOM_SEED_INIT_FUNC is undeclared, and it suggests that you might have meant to use MICROPY_PY_URANDOM_SEED_INIT_FUNC instead.
To resolve this issue I have modify the random.c
class.
$ nano /home/max/lib-esp32/ulab/code/numpy/random/random.c
generator->state = MICROPY_PY_RANDOM_SEED_INIT_FUNC;
to generator->state = MICROPY_PY_URANDOM_SEED_INIT_FUNC;
After this change,
$ cd /home/max/lib-esp32/micropython/ports/esp32
$ make clean
$ make
I had to run the ESP-IDF installation.
$ cd /home/max/lib-esp32/micropython/esp-idf
$ ./install.sh
After installation, you need to set up the environment variables, so run:
$ . ./export.sh
I had to change the path because the build system wasn't finding the ulab module's CMake file.
$ nano /home/max/lib-esp32/micropython/ports/esp32/Makefile
USER_C_MODULES = /ulab/code/micropython.cmake
to USER_C_MODULES=your_correct_path
$ make clean
$ make
Once you flashed the firmware.bin
, check if the ulab module can be imported and be used.
$ screen /dev/ttyUSB0 115200
>> import ulab
>> print(ulab.__version__)
>> from ulab import numpy as np
If everythin goes right, you have ulab installed and you can use numpy. This is the path and the errors that I've found through my way. Thank you @v923z for the support. I can close the issues now.
Hi there,
I am new with micropython development and I am struggling to have the correct libraries for my project. I need numpy for my project and I found ulab as numpy-like library.
I am using your project to achieve this. I've followed your steps listed in the doc but I do not understand which file I should flash on my device in order to import ulab as library. It probabily sounds as a silly question but I'm a rookie in this environment.
Thank you for your time. Max