This commit converts `tests/extmod/machine_spi_rate.py` to use the target
wiring mechanism, moving the port-specefic definition of the SPI instances
that are being tested out of the `tests/extmod/machine_spi_rate.py` file
and into the target wiring code. As part of this, the test is changed to
always use the default pins for the given SPI instance.
This simplifies the test, makes it easier to add support for new
ports/boards, and allows reusing the `spi_standalone_args_list` definition
in other tests (if needed one day).
Signed-off-by: Damien George <damien@micropython.org>
The `getrandbits()` function is guaranteed to exist on all ports that have
the `random` module (but `randrange()` is not).
Signed-off-by: Damien George <damien@micropython.org>
The axTLS implementation of the tls module only has a basic set of
features. In particular it doesn't support the CERT_REQUIRED constant nor
DTLS, nor can it load the `ec_key.der` key when acting as a server. So
skip tests that require these features, which ends up being all the ssl/tls
tests.
Signed-off-by: Damien George <damien@micropython.org>
With this change, can simply add `LD_FILES` to a board's `mpconfigboard.mk`
to change the linker scripts, such as to change the section sizes, or
change the contents for each region. Example usage:
LD_FILES = $(BOARD_DIR)/my_board.ld boards/common.ld
Signed-off-by: Dryw Wade <dryw.wade@sparkfun.com>
MicroPython needs to handle the UART idle interrupt, which is not something
that the standard SDK provides. This was previously fixed by including in
the mimxrt port a modified copy of `fsl_lpuart.c`.
This commit changes how that's done by building the unmodified
`fsl_lpuart.c` directly from the SDK, and using linker wrapping to override
the necessary functions to get at the idle IRQ. As part of this, the code
is updated to work with the latest SDK.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
This allows user C modules to be built into the mimxrt port. The change is
copied from `samd/Makefile`.
Fixes issue #18292.
Signed-off-by: Dryw Wade <dryw.wade@sparkfun.com>
This commit adds PSRAM support for Teensy 4.1 and other mimxrt boards.
It's enabled by default for Teensy 4.1.
This implementation is based on the Teensy Arduino core PSRAM code, and
Paul Stoffregen has agreed for it to be published here under the MIT
license, see https://github.com/micropython/micropython/pull/18288#issuecomment-3806784632
This addresses issue #18281.
Signed-off-by: Dryw Wade <dryw.wade@sparkfun.com>
The test runners have evolved over time and become more and more complex.
In particular `tests/run-tests.py` is rather large now. The test runners
also duplicate some functionality amongst themselves.
As a start to improving this situation, this commit factors out the helper
functions from `run-tests.py` into a new `test_utils.py` file, and uses
that new module in all test runners.
There should be no functional change here.
Signed-off-by: Damien George <damien@micropython.org>
(Can be overridden by setting STFLASH variable.)
Generalises the change from 6b13e6c498 to all
stm32 boards. As we're resetting the target to flash it anyway, it
shouldn't hurt to put the target into reset before trying to connect.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This adds docs for the `mimxrt` module and the `mimxrt.Flash` class, the
implementation for which was first added in
dfd4324eb1
The docs are simple, following the conventions used for similar classes in
the rp2 and stm32 ports.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Currently the mimxrt port has a resolution of only 1 second for
`machine.RTC().datetime()` and `time.time_ns()`. This means (among other
things) that it fails the `tests/extmod/time_time_ns.py` test, which
requires requires at least 5ms of resolution.
The underlying RTC hardware is just a 64-bit counter, and the HAL functions
`SNVS_LP_SRTC_GetDatetime()` and `SNVS_LP_SRTC_SetDatetime()` do
conversions between y/m/d/h/m/s and this 64-bit value, which counts at a
rate of 32kHz.
This commit changes the RTC code to access the 64-bit counter directly and
therefore improve resolution of all RTC functions to 1/32768 seconds.
That makes things much simpler because it a lot of places the code wants to
know the number of seconds since the Epoch. Currently it uses a
combination of `SNVS_LP_SRTC_GetDatetime()` and
`timeutils_seconds_since_epoch()` which converts the 64-bit counter to
date-time and then back to seconds. Those operations are computationally
expensive.
With this commit, getting the number of seconds since the Epoch is as
simple as reading the 64-bit counter and dividing by 32768. We can
leverage a lot of the timeutils functions to simplify everything, and make
it similar to other ports like rp2.
Benefits of this change:
- simpler, more efficient code to get/set RTC
- `machine.RTC().datetime()` now has a non-zero value in the last slot,
being the number of microseconds, and has a resolution of 1/32768 seconds
- `time.time_ns()` now has a resolution of 1/32768 seconds
- the `test/extmod/time_time_ns.py` test now passes
Signed-off-by: Damien George <damien@micropython.org>
This adds support for the ALT11 alternate function mode on MIMXRT1176
MCUs, enabling FLEXPWM channels on GPIO_AD pins that were previously
unavailable for PWM use.
Changes:
- Add PIN_AF_MODE_ALT11 enum to pin.h
- Add ALT11 column to MIMXRT1176_af.csv with FLEXPWM mappings
- Enables FLEXPWM1-4 on GPIO_AD_06 through GPIO_AD_21
This change only affects MIMXRT1176-based boards (MIMXRT1170_EVK and
PHYBOARD_RT1170). Other MIMXRT family chips use alternate function
modes ALT0-ALT9 and are not affected.
Tested on MIMXRT1176 hardware with PWM output on GPIO_AD_14
(FLEXPWM3_PWM0_X).
Signed-off-by: Algy Tynan <algy@tynan.io>
The rt117x uses the LPADC peripheral which supports both A-side and B-side
channel inputs, e.g. ADC1_CH1A and ADC1_CH1B.
Previously, only `kLPADC_SampleChannelSingleEndSideA` was being used during
capture, while the pin may be in side B. The fix in this commit detects
the side based on the pin configuration and sets `sampleChannelMode`
appropriately.
Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
This commit adds support to the `marshal` module to be able to dump
functions that have child functions. For example:
import marshal
def f():
def child():
return 1
return child
marshal.dumps(f.__code__)
It also covers the case of marshalling functions that use list
comprehensions, because a list comprehension uses a child function.
This is made possible by the newly enhanced
`mp_raw_code_save_fun_to_bytes()` that can now handle nested functions.
Unmarshalling via `marshal.loads()` already supports nested functions
because it uses the standard `mp_raw_code_load_mem()` function which is
used to import mpy files (and hence can handle all possibilities).
Signed-off-by: Damien George <damien@micropython.org>
If a function has children then the code object returned from __code__ must
contain an `mp_raw_code_t` (actually `mp_raw_code_truncated_t` is enough)
that points to the child table.
Signed-off-by: Damien George <damien@micropython.org>
This adds support to `mp_raw_code_save_fun_to_bytes()` so that it can
handle saving functions that have children. It does this by inspecting
the MP_BC_MAKE_FUNCTION/etc opcodes to work out how many children there
are, and creating a tree of simplified raw code information.
Signed-off-by: Damien George <damien@micropython.org>
In case `MICROPY_PY_MARSHAL` is enabled manually. Otherwise the marshal
module is not very usable.
Signed-off-by: Damien George <damien@micropython.org>
When `MICROPY_PY_FUNCTION_ATTRS_CODE` is enabled, constructing a function
instance through `fun_bc_make_new()` can call
`mp_make_function_from_proto_fun()` with pure bytecode as the proto-fun.
Signed-off-by: Damien George <damien@micropython.org>
These changes test a few more things related to TCP RST:
- add a second iteration to drain incoming data after TCP RST
- read data after closing socket
Signed-off-by: Damien George <damien@micropython.org>
This commit fixes a long standing bug/deficiency in the lwIP socket code,
whereby it would abandon all incoming TCP data if the remote sent a TCP
RST.
This behaviour it tested by the existing
`tests/multi_net/tcp_client_rst.py` and
`tests/multi_net/asyncio_tcp_client_rst.py` tests, and they both fail on
boards like PYBD_SFx and RPI_PICO_W due to the deficiency.
With the fix here, both of those tests now pass on lwIP targets, along with
all existing socket tests.
Signed-off-by: Damien George <damien@micropython.org>
This test can now run correctly with the native emitter because the
`thread()` function will run the scheduler during the call to
`time.sleep_ms(1)`.
Signed-off-by: Jeff Epler <jepler@unpythonic.net>
This variant of `schedule.py` explicitly calls a zero sleep. The existing
variant is kept to ensure the scheduler is called between bytecodes.
Signed-off-by: Jeff Epler <jepler@unpythonic.net>
This allows tests like `asyncio_event_queue.py` to succeed under the native
emitter when poll is enabled.
Signed-off-by: Jeff Epler <jepler@unpythonic.net>
This test was ignored since 2020, which hid a new bug in the test for the
native emitter added in 2024. Hopefully other changes to the test will
make it more reliable.
Signed-off-by: Jeff Epler <jepler@unpythonic.net>
As of January 12 the default Python version changed from 3.9 to
3.12, and 3.12 has issues running the settrace tests.
3.13 seems to also have some issues, so setting 3.11 for now.
See https://github.com/actions/runner-images/issues/13468
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This commit fixes a test exercising complex numbers creation, working
around a deprecation introduced in CPython 3.14.
Creating complex numbers using a complex number as the real part in the
constructor is deprecated in CPython 3.14, but that construction method
is still supported by MicroPython and covered by tests. To work around
this, the specific constructor is extracted into its own test, providing
an expected output file recorded using CPython 3.11.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit makes tests exercising certain math functions' limit work
when using CPython 3.14 to validate the tests' output.
CPython 3.14 introduced more descriptive messages when math domain error
conditions are encountered rather than a single generic message. This
breaks the tests in question as MicroPython uses a single error message
when reporting these conditions (both to closely follow CPython and to
save firmware space).
The math domain tests now look for an error pattern that is compatible
with both CPython 3.14 and previous versions, converting messages in the
newer format into the previous one. This makes the tests' behaviour
under MicroPython comparable with CPython for the foreseeable future.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit fixes tests that will always fail when using CPython 3.14
to get a known-good output to compare MicroPython's behaviour against.
Starting from CPython 3.14, statements inside a `finally` block that
will prevent the execution flow to reach the block's last statement will
raise a SyntaxWarning. That text would end up in the comparison data
and thus make known-good tests fail.
Given that those tests explicitly exercise flow control interruptions
in finally blocks, there is no real workaround that can be applied to
the tests themselves. Therefore those tests will now check
MicroPython's behaviour against expected output files recorded from
the tests' output with CPython 3.11.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
STM32CubeMX shows a conflict of UART5 with ETH MII.
However UART1 can be used with TX and RX on the pin headers.
PLL1Q is reduced from 200 to 100 MHz because it may be used for FDCAN
or SDMMC. FDCAN needs <= 150 MHz, and 100 MHz is enough for an SDCard
connected to pin headers to work reliably.
Signed-off-by: Oliver Joos <oliver.joos@hispeed.ch>
To connect STM32H7 that is in SLEEPD1 state (e.g. during REPL)
debuggers like st-flash or openocd must assert SRST.
Signed-off-by: Oliver Joos <oliver.joos@hispeed.ch>