Commit Graph

16389 Commits

Author SHA1 Message Date
iabdalkader
bab6a016b3 lib/arduino-lib: Update submodule.
Changes:
- Add ISO7816, APDU and SE05x package.
- Add support for Opta Expansion protocol.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-10-25 01:18:33 +11:00
iabdalkader
68f1c20145 extmod/modtls_mbedtls: Support alternate sign callbacks in Python.
This commit enables the implementation of alternative mbedTLS cryptography
functions, such as ECDSA sign and verify, in pure Python.  Alternative
functions are implemented in Python callbacks, that get invoked from
wrapper functions when needed.  The callback can return None to fall back
to the default mbedTLS function.

A common use case for this feature is with secure elements that have
drivers implemented in Python.  Currently, only the ECDSA alternate sign
function wrapper is implemented.

Tested signing with a private EC key stored on an NXP SE05x secure element.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-10-25 01:16:06 +11:00
iabdalkader
2644f577f1 extmod/modtls_mbedtls: Add a thread-global ptr for current SSL context.
This is necessary for mbedTLS callbacks that do not carry any user state,
so those callbacks can be customised per SSL context.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-10-25 01:12:36 +11:00
Damien George
09ea901317 tests/extmod: Add test to compare time_ns with time.
They should be close together.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-24 23:24:09 +11:00
Damien George
1ec0c9b886 tests/extmod: Use time_ns instead of time in lfs mtime test.
Because VfsLfs2 uses time_ns to create timestamps for files, and for the
test to give consistent results it also needs to use this same function.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-24 23:24:09 +11:00
Damien George
120ac0f8d2 rp2/modmachine: Re-sync time_ns offset when coming out of lightsleep.
Prior to this fix, `tests/extmod/vfs_lfs_mtime.py` would fail when run
after the `tests/ports/rp2/rp2_lightsleep.py` test, because
`time.time_ns()` would have a large and constant offset from `time.time()`.

Fix this by re-syncing the time-ns offset when coming out of lightsleep.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-24 23:24:09 +11:00
Damien George
ca6aed7649 tests/extmod: Fix access of RTC class in machine.RTC test.
This previously passed on some targets that automatically import the
`machine` module in `boot.py`.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-24 16:29:43 +11:00
Damien George
6d98280fda tests/extmod: Add a simple test for machine.RTC.
Tests at least that the datetime can be set and get correctly.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-24 11:43:03 +11:00
Damien George
47741e2757 rp2/datetime_patch: Fix year and month offset for mktime wrapper.
Signed-off-by: Damien George <damien@micropython.org>
2024-10-24 11:22:59 +11:00
Damien George
43bd57f94b shared/timeutils: Document the range of year/month/day etc input values.
These differ to, eg, the standard `mktime()` function.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-24 11:22:22 +11:00
Jared Hancock
078ead24f3 extmod/network_wiznet5k: Reset mDNS when interface is brought up.
The LwIP interface is removed in wiznet5k_deinit() which is called as part
of the init sequence.  Therefore, if using mDNS, then the interface will
need to be re-added when bringing the interface up.

Additionally, this allows to set the hostname from MicroPython code prior
to bringing the interface up and mDNS responding to the (new) hostname.
This allows the hostname to be configured and saved on the flash or be
based on dynamic information such as the MAC or unique_id().

Signed-off-by: Jared Hancock <jared.hancock@centeredsolutions.com>
2024-10-23 16:29:28 +11:00
Damien George
3f54e5dff2 tests/extmod: Support esp32,mimxrt,stm32,samd ports in UART TX test.
Getting this test running on stm32- and mimxrt-based boards requires adding
a small delay after constructing the UART so that the initial idle frame
has time to be transmitted before the test starts.

Also, the timing margin needs to account for an additional 1-bit worth of
time on some MCUs.

Thanks to @robert-hh for the esp32, mimxrt and samd settings.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-22 22:21:17 +11:00
Alessandro Gatti
6328958a39 rp2/mpconfigport: Leave callable pointers alone on RV32.
The port configuration file tagged callable pointers' LSB on both Arm
and RISC-V variants.  This is needed on Arm due to Thumb/Thumb2
code addresses having their LSB set, but on RISC-V this is not required.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-10-22 15:01:53 +11:00
Plaque FCC
324871f380 qemu/mcu/rv32: Fix test of mcause value in lookup_cause.
Signed-off-by: Plaque FCC <plaque-fcc@github>
2024-10-22 14:52:01 +11:00
Volodymyr Shymanskyy
8fef67bda5 esp32/modmachine: Allow building with USB CDC disabled.
Signed-off-by: Volodymyr Shymanskyy <vshymanskyi@gmail.com>
2024-10-22 14:45:51 +11:00
Damien George
0646177997 tests/extmod: Make invalid-blockdev test work consistently on all ports.
Some ports (eg stm32) configure the FAT driver differently (eg with
multi-partition support) and that leads to a slightly different sequence of
block reads, compared to other configurations (eg rp2).

Comment out the printing in `readblocks()` so the tests are deterministic
(the printing is still useful for debugging).

Signed-off-by: Damien George <damien@micropython.org>
2024-10-22 14:32:51 +11:00
Damien George
f7abb52847 tests/run-tests.py: Skip large viper test on esp8266.
Signed-off-by: Damien George <damien@micropython.org>
2024-10-22 14:31:13 +11:00
Damien George
52f2ba5677 tests/micropython: Tweak ringio test for targets with terse errors.
Signed-off-by: Damien George <damien@micropython.org>
2024-10-22 14:31:13 +11:00
Damien George
1e3b24238e tests/extmod: Adjust ssl/tls tests to run on targets with axTLS.
Signed-off-by: Damien George <damien@micropython.org>
2024-10-22 14:31:13 +11:00
Damien George
7d442373af tests/extmod: Config SPI test for esp8266 and skip SoftTimer test.
Signed-off-by: Damien George <damien@micropython.org>
2024-10-22 14:31:13 +11:00
Corran Webster
d1574de3b6 extmod/modframebuf: Fix FrameBuffer size check for stride corner-cases.
This is a fix for issue #15944, and handles corner cases in the FrameBuffer
code when using stride values where the last line's stride may extend past
the end of the underlying buffer.  This commit includes extra tests for
these corner cases.

For example a GS8 format FrameBuffer with a width of 8, height of 2 and
stride of 10 should be able to fit into a buffer of size 18 (10 bytes for
the first horizontal line, and 8 bytes for the second -- the full 10 bytes
are not needed).

Similarly a 1 by 9 FrameBuffer in MONO_VLSB format with a stride of 10
should be able to fit into a buffer of length 11 (10 bytes for the first
8 lines, and then one byte for the 9th line.

Being able to do this is particularly important when cropping the corner of
an existing FrameBuffer, either to copy a sprite or to clip drawing.

Signed-off-by: Corran Webster <cwebster@unital.dev>
2024-10-22 13:05:31 +11:00
Damien George
7ed480fc6f Revert "stm32/machine_uart: Allow changing only the baudrate."
This reverts commit c94a3205b0.

The idea behind this reverted commit was that it allowed to reconfigure the
UART to change only the baudrate, which is important in the context of a
PPP connection where the baudrate may be changed as part of the protocol.
Also, other ports like the rp2 port have this behaviour, where individual
parameters of the UART can be changed with the `.init()` method.

But this commit was no good for a few reasons:

1. It's a subtle breaking change to the UART API, because existing code
   that constructs or initialises a UART with just the baudrate would
   expect all other parameters to be reset to their defaults.  But with
   this commit those parameters would remain unchanged.

2. Constructing a UART like `UART(1, 9600)` also hits this code path of
   only changing the baudrate and does not reset other parameters, which is
   unexpected.

3. It doesn't support setting the baudrate via keyword, eg
   `UART.init(baudrate=9600)`.

4. The `timeout_char` field is not updated when changing only the baudrate,
   which can lead to unexpected timeouts when reading/writing.

Due to point (4), this commit broke the `tests/ports/stm32/uart.py` test,
the `uart.writechar(1)` has a timeout because the `uart.init(2400)` does
not set the `timeout_char` for the new baudrate.

Points (2)-(4) could be fixed, but point (1) (being a breaking change)
would remain as an issue.  So the commit is reverted.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-22 11:50:05 +11:00
Damien George
97af1001ae rp2/machine_uart: Make it so TX is done only when no longer busy.
Prior to this commit, when flushing a UART on the rp2 port, it returns just
before the last character is sent out the wire.

Fix this by waiting until the BUSY flag is cleared.

This also fixes the behaviour of `UART.txdone()` to return `True` only when
the last byte has gone out.

Updated docs and tests to match.  The test now checks that UART TX time is
very close to the expected time (prior, it was just testing that the TX
time was less than the expected time).

Signed-off-by: Damien George <damien@micropython.org>
2024-10-22 10:17:05 +11:00
Damien George
1b89c503db py/objtype: Don't delegate lookup of descriptor methods to __getattr__.
When descriptors are enabled, lookup of the `__get__`, `__set__` and
`__delete__` descriptor methods should not be delegated to `__getattr__`.
That follows CPython behaviour.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-16 15:03:30 +11:00
Andrew Leech
3fecab58a0 esp32/mphalport: Always poll stdin ring-buffer to include UART use.
This fixes a regression introduced in commit
4247921c4e, where this ring-buffer polling
was accidentally put inside the `#if MICROPY_HW_ESP_USB_SERIAL_JTAG`.

Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-10-16 14:50:11 +11:00
Damien George
838f21298a unix/main: Add --version command-line option.
CPython also has this option.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 14:44:10 +11:00
Damien George
51663b9aa7 rp2/machine_uart: Clear timeout_char when UART is first constructed.
Otherwise a previous value of `timeout_char` may be left over after a soft
reset.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 12:23:06 +11:00
Damien George
b33f64792f tests/run-tests.py: Only run inlineasm tests on rp2 ARM targets.
Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 12:23:06 +11:00
Damien George
b42bb911c6 tests/ports/rp2: Update lightsleep/machine_idle to skip on RP2350.
Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 12:23:06 +11:00
Damien George
651b63cd79 tests/ports/rp2: Add simple rp2-specific UART test.
To test construction of UART instances.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 12:23:06 +11:00
Damien George
fda7ae83a8 tests/ports/rp2: Update DMA test to work on RP2350.
Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 12:21:10 +11:00
Damien George
f9cebe676e tools/ci.sh: Add RPI_PICO2 to CI.
Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 12:21:10 +11:00
Peter Harper
e32e13f7e4 rp2/boards/RPI_PICO2: Add new RPI_PICO2 board definition.
This is the same form-factor as the Pico but with an RP2350.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 12:20:12 +11:00
Damien George
137e9e8c79 rp2/main: Set CPU frequency to default for the MCU.
Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 12:20:12 +11:00
Phil Howard
27904ae4b9 rp2/machine_pwm: Add RP2350 slices to machine.PWM.
Signed-off-by: Phil Howard <phil@gadgetoid.com>
2024-10-15 12:19:52 +11:00
Angus Gratton
8cc7c64d01 rp2: Workaround pico_aon_timer timezone binary size increase.
Provide stub implementations of localtime_r() and mktime() to avoid
code size increase.

Reported upstream at https://github.com/raspberrypi/pico-sdk/issues/1810

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-10-15 12:18:53 +11:00
Damien George
fa15ae4503 rp2/machine_bitstream: Implement bitstream for RISC-V using mcycle.
Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 12:18:51 +11:00
Damien George
ea2eed1b23 rp2/mphalport: Implement mp_hal_ticks_cpu for RISCV using mcycle.
Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 12:18:32 +11:00
Dryw Wade
957cea23d5 rp2/machine_uart: Allow new TX/RX pins on RP2350.
Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 12:18:32 +11:00
Dryw Wade
7a78e5ae7c rp2/machine_bitstream: Set SysTick reset value.
In case it doesn't have the correct value.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 12:18:29 +11:00
Damien George
f2f08ef2d9 rp2/Makefile: Allow CMAKE_ARGS to be set by user.
Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 12:16:46 +11:00
Damien George
4fc6cf9141 rp2: Add support for RP2350 in RISCV mode.
As part of this change, the RV32I native emitter is enabled on RISCV
board variants.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 12:16:46 +11:00
Phil Howard
34e463d861 rp2/machine_adc: Add ADC support for RP2350B.
Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 12:16:46 +11:00
Peter Harper
d0bc42796b rp2/clocks_extra: Update runtime_clocks_init based on new pico-sdk.
Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 12:15:48 +11:00
Phil Howard
57f4cabff9 rp2/machine_pin: Generalise gpio_irq handler for pins >32.
Fix the gpio_irq function so that it looks at all six iobank0_hw->intr[n]
registers, for up to 48 IOs.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
2024-10-15 12:14:59 +11:00
Peter Harper
733052f6b9 rp2/machine_pin: Use 64-bit gpio functions to allow gpios >=32 to work.
Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 12:14:25 +11:00
Peter Harper
4af09de19c rp2/boards/make-pins.py: Pass num-gpios/num-ext-gpios into make-pins.
NUM_GPIOS amd NUM_EXT_GPIOS are currently hardcoded in make-pins.py, which
makes it difficult to support SoCs with different pin count.

This commit generalises make-pins.py by passing in the pin count in via the
new arguments `--num-gpios` and `--num-ext-gpios`.  These default to the
current values supported by Pico, namely 30/10.  This can be changed with
PICO_NUM_GPIOS and PICO_NUM_EXT_GPIOS in `mpconfigboard.cmake`.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 12:12:04 +11:00
Phil Howard
e6093c0fbd rp2/rp2_pio: Add support for RP2350A/B variants in PIO interface.
Add support for 32 and 48 pin variants of RP2350.

Add new `PIO.gpio_base()` method, mirroring the Pico SDK.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 12:09:48 +11:00
Damien George
a3d1c59ca3 rp2/machine_pin: Move decl of machine_pin_obj_table to public header.
So other code can include `machine_pin.h` and use the pin name macros such
as `pin_GPIO0`.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 12:09:48 +11:00
Phil Howard
6d39418f69 rp2: Add support for 48-pin RP2350 variant.
Update NUM_GPIOS to match NUM_BANK0_GPIOS, and increase bit-width of
variables that store pin numbers.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
2024-10-15 12:08:39 +11:00