-
When running though a test suite ran into an issue that I did not notice on other boards. def foo_complex():
return 54 + 55j fails with So now I learned that this is an optional feature , and want to change my tests accordingly. try:
def foo_complex(): # type: ignore
return 54 + 55j
except:
# complex numbers are not supported on all ports/boards
def foo_complex():
return "MICROPY_PY_BUILTINS_COMPLEX=0" Any suggestions on a workaround or way to detect this (without access to the source that the firmware was compiled from) { 'family': 'micropython',
'version': '1.22.0',
'port': 'samd',
'mpy': 'v6.2',
'build': '',
'cpu': 'SAMD51P19A',
'board': 'Wio Terminal D51R with SAMD51P19A',
'arch': 'armv7emsp',
} |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
can you try to do:
using function syntax, for the complex instead of direct numerical syntax? I don't have a suitable platform to test this on, so I cannot guarantee it will work. |
Beta Was this translation helpful? Give feedback.
-
Support for complex numbers is not enabled on the SAMD port. Since you build your firmware yourself you can easily enable it. In mcu/samd51/mpconfigmcu.h the flags for it are included for best visibility. Just set them to 1 and build. It adds about 2.5 k to the flash size. So it could be enabled for SAMD51, maybe not for SAMD21. Edit: The method @mendenm suggests works. |
Beta Was this translation helpful? Give feedback.
-
With a file def foo_complex(): # type: ignore
return 54 + 55j and try:
import imp_complex
MICROPY_PY_BUILTINS_COMPLEX=1
except:
# complex numbers are not supported on all ports/boards
MICROPY_PY_BUILTINS_COMPLEX=0 the exception mechanism works and one can test the builtin capabilities. Nice: # --- internal ---
# a6 .. idx or tab[idx]
# --- arguments ---
# a5 .. lookup table address
# a4 .. n (length of data), then data address + n
# a3 .. data address
# a2 .. crc
@micropython.asm_xtensa
def _crc8_tr(a2, a3, a4, a5) -> uint:
add(a4, a4, a3) # final data address
label(loop)
l8ui(a6, a3, 0) # a6 = idx = data[0]
addi(a3, a3, 1) # increment data pointer
xor(a6, a6, a2) # idx ^= crc
add(a6, a6, a5) # table data address
l8ui(a2, a6, 0) # fetch table entry: a2 = tab[idx]
bne(a3, a4, loop) # --- test and outer end --- and
which solves the problem of testing which decorators for higher speed may be used. This solves/closes issue 11805 |
Beta Was this translation helpful? Give feedback.
-
Thanks to all that pitched in a collection of detection methods of optional functionality, all in a single file : https://github.com/Josverl/micropython-magic/blob/main/samples/detect_optional_features.ipynb The format is a Jupyter notebook, be able to see the code and results of the last run, but can run as '.py' code as well. |
Beta Was this translation helpful? Give feedback.
can you try to do:
using function syntax, for the complex instead of direct numerical syntax? I don't have a suitable platform to test this on, so I cannot guarantee it will work.