← index #5162PR #7635
Related · medium · value 1.396
QUERY · ISSUE

[nRF port] Unable to activate MICROPY_PY_SYS_STDFILES in mpconfigport.h

openby sebi5361opened 2019-09-30updated 2021-06-08
port-nrf

I was unable to turn on some of the features in mpconfigport.h, such as MICROPY_PY_SYS_STDFILES, MICROPY_PY_MATH_SPECIAL_FUNCTIONS, MICROPY_PY_IO_FILEIO and MICROPY_PY_MACHINE_SPI, as make would fail with those features on (nRF port).

Below are the error messages:

  • Error when #define MICROPY_PY_SYS_STDFILES (1):
LINK build-pca10040-s132/firmware.elf
/usr/local/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld: /tmp/ccCsRh6Z.ltrans2.ltrans.o: in function `mp_sys_print_exception.lto_priv.992':
/mnt/c/Users/sebi/Documents/TINKERING/MicroPython/FORKS/micropython/ports/nrf/../../py/modsys.c:110: undefined reference to `mp_sys_stdout_obj'
/usr/local/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld: /tmp/ccCsRh6Z.ltrans2.ltrans.o:(.rodata+0xb4): undefined reference to `mp_sys_stdout_obj'
/usr/local/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld: /tmp/ccCsRh6Z.ltrans2.ltrans.o:(.rodata+0x1c8): undefined reference to `mp_sys_stdout_obj'
/usr/local/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld: /tmp/ccCsRh6Z.ltrans2.ltrans.o:(.rodata+0x246c): undefined reference to `mp_sys_stdin_obj'
/usr/local/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld: /tmp/ccCsRh6Z.ltrans2.ltrans.o:(.rodata+0x2474): undefined reference to `mp_sys_stdout_obj'
/usr/local/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld: /tmp/ccCsRh6Z.ltrans2.ltrans.o:(.rodata+0x247c): undefined reference to `mp_sys_stderr_obj'
collect2: error: ld returned 1 exit status
make: *** [Makefile:344: build-pca10040-s132/firmware.elf] Error 1
  • Error when #define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (1)
CC build-pca10040-s132/pins_gen.c
LINK build-pca10040-s132/firmware.elf
/usr/local/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld: /tmp/cchaRFoM.ltrans2.ltrans.o: in function `mp_math_lgamma.lto_priv.1007':
/mnt/c/Users/sebi/Documents/TINKERING/MicroPython/FORKS/micropython/ports/nrf/../../py/modmath.c:170: undefined reference to `lgammaf'
/usr/local/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld: /tmp/cchaRFoM.ltrans2.ltrans.o: in function `mp_math_gamma.lto_priv.1006':
/mnt/c/Users/sebi/Documents/TINKERING/MicroPython/FORKS/micropython/ports/nrf/../../py/modmath.c:168: undefined reference to `tgammaf'
/usr/local/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld: /tmp/cchaRFoM.ltrans2.ltrans.o: in function `mp_math_erfc.lto_priv.1005':
/mnt/c/Users/sebi/Documents/TINKERING/MicroPython/FORKS/micropython/ports/nrf/../../py/modmath.c:166: undefined reference to `erfcf'
/usr/local/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld: /tmp/cchaRFoM.ltrans2.ltrans.o: in function `mp_math_erf.lto_priv.1004':
/mnt/c/Users/sebi/Documents/TINKERING/MicroPython/FORKS/micropython/ports/nrf/../../py/modmath.c:164: undefined reference to `erff'
/usr/local/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld: /tmp/cchaRFoM.ltrans2.ltrans.o: in function `mp_math_atanh.lto_priv.982':
/mnt/c/Users/sebi/Documents/TINKERING/MicroPython/FORKS/micropython/ports/nrf/../../py/modmath.c:120: undefined reference to `atanhf'
/usr/local/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld: /tmp/cchaRFoM.ltrans2.ltrans.o: in function `mp_math_asinh.lto_priv.981':
/mnt/c/Users/sebi/Documents/TINKERING/MicroPython/FORKS/micropython/ports/nrf/../../py/modmath.c:118: undefined reference to `asinhf'
/usr/local/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld: /tmp/cchaRFoM.ltrans2.ltrans.o: in function `mp_math_acosh.lto_priv.980':
/mnt/c/Users/sebi/Documents/TINKERING/MicroPython/FORKS/micropython/ports/nrf/../../py/modmath.c:116: undefined reference to `acoshf'
/usr/local/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld: /tmp/cchaRFoM.ltrans2.ltrans.o: in function `mp_math_log2.lto_priv.975':
/mnt/c/Users/sebi/Documents/TINKERING/MicroPython/FORKS/micropython/ports/nrf/../../py/modmath.c:106: undefined reference to `log2f'
collect2: error: ld returned 1 exit status
make: *** [Makefile:344: build-pca10040-s132/firmware.elf] Error 1
  • Error when #define MICROPY_PY_IO_FILEIO (1)
LINK build-pca10040-s132/firmware.elf
/usr/local/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld: /tmp/ccKalfRU.ltrans2.ltrans.o:(.rodata+0x25fc): undefined reference to `fatfs_type_fileio'
/usr/local/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld: /tmp/ccKalfRU.ltrans2.ltrans.o:(.rodata+0x2604): undefined reference to `fatfs_type_textio'
collect2: error: ld returned 1 exit status
make: *** [Makefile:344: build-pca10040-s132/firmware.elf] Error 1
  • Error when #define MICROPY_PY_MACHINE_SPI (1):
CC ../../extmod/machine_spi.c
../../extmod/machine_spi.c: In function 'mp_machine_soft_spi_print':
../../extmod/machine_spi.c:175:67: error: expected ')' before 'MP_HAL_PIN_FMT'
     mp_printf(print, "SoftSPI(baudrate=%u, polarity=%u, phase=%u,"
                                                                   ^
                                                                   )
         " sck=" MP_HAL_PIN_FMT ", mosi=" MP_HAL_PIN_FMT ", miso=" MP_HAL_PIN_FMT ")",
                 ~~~~~~~~~~~~~~
../../extmod/machine_spi.c:174:32: error: unused variable 'self' [-Werror=unused-variable]
     mp_machine_soft_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
                                ^~~~
At top level:
../../extmod/machine_spi.c:146:17: error: 'baudrate_from_delay_half' defined but not used [-Werror=unused-function]
 STATIC uint32_t baudrate_from_delay_half(uint32_t delay_half) {
                 ^~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [../../py/mkrules.mk:47: build-pca10040-s132/extmod/machine_spi.o] Error 1
CANDIDATE · PULL REQUEST

nrf/mpy: Set features consistent with documentation and other ports.

closedby mzdanielopened 2021-08-10updated 2021-08-13
port-nrf

While following https://docs.micropython.org/en/latest/reference/mpyfiles.html,
I stumbled upon sys.implementation.mpy. Turns out MICROPY_PERSISTENT_CODE_LOAD is needed for it and this PR proposes to bring NRF in par with the other archs.

Next step was to follow https://docs.micropython.org/en/latest/develop/natmod.html and again was crossed with compatibility issues. Today, the master branch builds micropython with no unicode as reflected by

>>> print('0x%02x' % (sys.implementation.mpy >> 8))
0x00

Building the documented factorial example renders an incompatible mpy that has unicode enabled by default, shown in its 3rd byte:

$ hexdump -C -n 4 factorial.mpy 
00000000  4d 05 0b 1f      |M...|

We dont want to enable by default features that compromize precious flash size, so I tried adding MPY_CROSS_FLAGS += -mno-unicode in the Makefile, but the unicode bit was still present after recompilation.
I've been thinking to look deeper here for a PR, and that's when I realized unicode is the default across other archs. At this point, enabling unicode still doesnt make mpy compatible but nonetheless seems much better to be consistent with the other archs.

The final part was to find configs that allows matching feature flags as required by the micropython import system. Long story short, mpy-cross unconditionally emits thumb and inline thumb code and this needs to be reflected in the target arch. No all archs agree here, and looks like the best practice is to enable them conditionally according to stm32. After applying this PR on nrf52840 the data will look like:

>>> print('0x%02x' % (sys.implementation.mpy >> 8))
0x1e
$ hexdump -C -n 4 factorial.mpy 
00000000  4d 05 1e 1f      |M...|

In short with this PR, NRF users of nrf9160 and nrf52840 series (1M flash) should be able to follow the docs as intended. For nrf52832 (512K/256K flash) and nrf51822 (256K/128K flash) I am not so sure what defaults are best.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied