Commit Graph

16428 Commits

Author SHA1 Message Date
Damien George
611d8f9ce8 esp32/modsocket: Fix getaddrinfo hints to set AI_CANONNAME.
Because the `ai_canonname` field is subsequently used.

ESP32_GENERIC_S3 (at least) crashes with IDF 5.2.3 without this set.

Signed-off-by: Damien George <damien@micropython.org>
2024-11-13 13:35:37 +11:00
Daniël van de Giessen
77406b4240 extmod/network_ppp: Allow stream=None to suspend PPP.
This allows the stream to be set to `None`, which essentially stops all PPP
communication without disconnecting the session.

This allows replacing the stream on-the-fly to suspend it, for example to
send AT commands to a modem without completely disconnecting and
re-establishing the PPP connection:

    uart = ppp.config('stream')
    ppp.config(stream=None)
    uart.write(b'+++')
    # do some AT commands
    uart.write(b'ATO\r\n')
    ppp.config(stream=uart)

Any attempted communication by PPP while the stream is not connected will
register as simple packet loss to the LwIP stack because we return 0 for
any write calls, and protocols like TCP will then automatically handle
retrying.

Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2024-11-13 13:11:32 +11:00
Daniël van de Giessen
161e2bd37d extmod/network_ppp: Add stream config parameter.
This makes the stream that the PPP object wraps, which is normally only set
once via the constructor, accessible and configurable via the
`ppp.config()` method.

Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2024-11-13 13:10:58 +11:00
Damien George
4fd5b72a8b tools/mpremote: Support trailing slash on dest for non-recursive copy.
This fixes a regression in db59e55fe7: prior
to that commit `mpremote` supported trailing slashes on the destination of
a normal (non-recursive) copy.

Add back support for that, with the semantics that a trailing slash
requires the destination to be an existing directory.

Also add a test for this.

Signed-off-by: Damien George <damien@micropython.org>
2024-11-13 11:51:35 +11:00
Damien George
3b6024a699 tools/mpremote: Add test for forced copy.
Signed-off-by: Damien George <damien@micropython.org>
2024-11-13 11:51:35 +11:00
Damien George
76e6c6345c tools/mpremote: Make sure stdout and stderr output appear in order.
mpremote error messages now go to stderr, so make sure stdout is flushed
before printing them.

Also update the test runner to capture error messages.

Signed-off-by: Damien George <damien@micropython.org>
2024-11-13 11:51:35 +11:00
Damien George
69023622ee tests/net_hosted: Improve and simplify non-block-xfer test.
CPython changed its non-blocking socket behaviour recently and this test
would not run under CPython anymore.  So the following steps were taken to
get the test working again and then simplify it:

- Run the test against CPython 3.10.10 and capture the output into the .exp
  file for the test.

- Run this test on unix port of MicroPython and verify that the output
  matches the CPython 3.10.10 output in the new .exp file (it did).  From
  now on take unix MicroPython as the source of truth for this test when
  modifying it.

- Remove all code that was there for CPython compatibility.

- Make it print out more useful information during the test run, including
  names of the OSError errno values.

- Add polling of the socket before the send/write/recv/read to verify that
  the poll gives the correct result in non-blocking mode.

Tested on unix MicroPython, ESP32_GENERIC, PYBD_SF2 and RPI_PICO_W boards.

Signed-off-by: Damien George <damien@micropython.org>
2024-11-13 11:44:09 +11:00
Damien George
eab2869990 extmod/modlwip: Don't allow writing to a TCP socket that is connecting.
This follows the behaviour of unix MicroPython (POSIX sockets) and the
esp32 port.

Signed-off-by: Damien George <damien@micropython.org>
2024-11-13 11:44:09 +11:00
Jeff Epler
3844733d60 tests/cpydiff: Fix test case for modules_json_nonserializable.
The test case was producing the following error:

    Traceback (most recent call last):
      File "<stdin>", line 12, in <module>
    UnicodeError:

which did not demonstrate the intended difference (this particular
non-json-serializable object DID throw an exception! just not TypeError).

The updated test uses a byte string with all ASCII bytes inside, which
better illustrates the diference.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2024-11-11 12:35:03 +11:00
Angus Gratton
5dfbd43714 tests: Use the recommended network.WLAN.IF_[AP|STA] constants.
Removes the deprecated network.[AP|STA]_IF form from unit tests.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-11-08 12:03:50 +11:00
Angus Gratton
f5b81bee61 esp8266: Use the recommended network.WLAN.IF_[AP|STA] constants.
Removes the deprecated network.[AP|STA]_IF form from the esp8266 port

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-11-08 12:03:48 +11:00
Angus Gratton
285e1d0b80 esp32: Use the recommended network.WLAN.IF_[AP|STA] constants.
Removes the deprecated network.[AP|STA]_IF form from the esp32 port

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-11-08 10:11:03 +11:00
Angus Gratton
48f96e9660 docs: Specify the recommended network.WLAN.IF_[AP|STA] constants.
Removes the deprecated network.[AP|STA]_IF form from the docs.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-11-08 10:11:03 +11:00
Angus Gratton
df6b40a87f esp32: Workaround native code execution crash on ESP32-S2.
Seemingly ESP-IDF incorrectly marks RTC FAST memory region
as MALLOC_CAP_EXEC on ESP32-S2 when it isn't. This memory is
the lowest priority, so it only is returned if D/IRAM is exhausted.

Apply this workaround to treat the allocation as failed if it gives us
non-executable RAM back, rather than crashing.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-11-06 16:08:23 +11:00
Angus Gratton
594670e446 esp32/machine_pwm: Restore PWM support for ESP-IDF v5.0.x and v5.1.x.
The cleanup in 548babf8 relies on some functions not available in older
ESP-IDF. Temporarily restore them, until we drop support for ESP-IDF <5.2.

PWM functionality should end up the same regardless of ESP-IDF version, and
also no different from MicroPython V1.23.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-11-05 17:19:58 +11:00
Damien George
275b3afae7 esp32/network_wlan: Add missing WLAN security constants.
These were added to the `network` module but not the `network.WLAN` class,
which is the new home for such constants.

Also:
- Mark the WLAN constants in the `network` module as deprecated, to be
  removed in MicroPython 2.0.
- Move the static assert to the WLAN source code, to be close to where it
  relates to.

Signed-off-by: Damien George <damien@micropython.org>
2024-11-05 11:34:35 +11:00
Damien George
d278ba5cc5 extmod/nimble: Remove asserts of ediv_rand_present and adjust comments.
Recent versions of NimBLE (since release 1.6.0) removed this variable; see
7cc8c08d67.

We never used it except in an assert, so remove those asserts to make the
code compatible with newer NimBLE versions (eg for the esp32 port).

Signed-off-by: Damien George <damien@micropython.org>
2024-11-05 11:27:06 +11:00
Damien George
919756cea4 extmod/modlwip: Fix IGMP address type when IPv6 is enabled.
This was missed in 628abf8f25.  The the bug
was that, when IPv6 is enabled, the `sizeof(ip_addr_t)` is much larger than
IPv4 size, which is what's needed for IGMP addressing.

Fixes issue #16100.

Signed-off-by: Damien George <damien@micropython.org>
2024-11-04 13:12:18 +11:00
Damien George
85053adb24 tests/run-tests.py: Add mimxrt and samd platforms.
Signed-off-by: Damien George <damien@micropython.org>
2024-11-04 12:48:10 +11:00
Damien George
8978102f35 tests/run-tests.py: Change --target/--device options to --test-instance.
Previously to this commit, running the test suite on a bare-metal board
required specifying the target (really platform) and device, eg:

    $ ./run-tests.py --target pyboard --device /dev/ttyACM1

That's quite a lot to type, and you also need to know what the target
platform is, when a lot of the time you either don't care or it doesn't
matter.

This commit makes it easier to run the tests by replacing both of these
options with a single `--test-instance` (`-t` for short) option.  That
option specifies the executable/port/device to test.  Then the target
platform is automatically detected.

The `--test-instance` can be passed:
- "unix" (the default) to use the unix version of MicroPython
- "webassembly" to test the webassembly port
- anything else is considered a port/device to pass to Pyboard

There are also some shortcuts to specify a port/device, following
`mpremote`:
- a<n> is short for /dev/ttyACM<n>
- u<n> is short for /dev/ttyUSB<n>
- c<n> is short for COM<n>

For example:

    $ ./run-tests.py -t a1

Note that the default test instance is "unix" and so this commit does not
change the standard way to run tests on the unix port, by just doing
`./run-tests.py`.

As part of this change, the platform (and it's native architecture if it
supports importing native .mpy files) is show at the start of the test run.

Signed-off-by: Damien George <damien@micropython.org>
2024-11-04 12:47:47 +11:00
Damien George
f2ac471989 tests/run-tests.py: Simplify the way target-specific tests are given.
Signed-off-by: Damien George <damien@micropython.org>
2024-11-04 12:02:55 +11:00
Damien George
c88a9d60a1 tests/basics/deque2.py: Add tests for deque subscript-from-end.
Signed-off-by: Damien George <damien@micropython.org>
2024-11-04 11:22:43 +11:00
Jan Sturm
7e1098befe py/objdeque: Fix buffer overflow in deque_subscr.
In `deque_subscr()`, if `index_val` equals `self->alloc`, the index
correction `index_val -= self->alloc` does not execute, leading to an
out-of-bounds access in `self->items[index_val]`.

The fix in this commit ensures that the index correction is applied
whenever `index_val >= self->alloc`, preventing access beyond the allocated
buffer size.

Signed-off-by: Jan Sturm <jansturm92@googlemail.com>
2024-11-04 11:21:56 +11:00
Jan Klusáček
0e490b7c8f docs/reference/packages: Fix description of --target option in mip.
Descripton of mip usage with micropython port suggest using it like this:

    ./micropython -m mip install --target=third-party pkgname

But it should be called without equal sign:

    ./micropython -m mip install --target third-party pkgname

Signed-off-by: honza.klu@gmail.com
2024-10-31 23:23:58 +11:00
Angus Gratton
787c424cfc tools/ci.sh: Fix reference commit for code size comparison.
Previously the code size comparison was between the merge base (i.e. where
the PR branched), and the generated merge commit into master.  If the PR
branch was older than current master, this meant the size comparison could
incorrectly include changes already merged on master but missing from the
PR branch.

This commit changes it to compare the generated merge commit against
current master, i.e. the size impact if this PR was to be merged.

This commit also disables running the code size check on "push", it now
only runs on pull_request events.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-10-31 23:19:55 +11:00
Angus Gratton
9591b0a53c tools/ci.sh: Fix commit msg checking when PR branch HEAD behind master.
Fixes the problem noted at
https://github.com/micropython/micropython/pull/15547#issuecomment-2434479702
which is that, because default CI HEAD for a PR is a (generated) merge
commit into the master branch's current HEAD, then if the PR branch isn't
fully rebased then the commit check runs against commits from master as
well!

Also drops running this check on push, the pull_request event is triggered
by default on open and update ("synchronized" event), which probably covers
the cases where this check should run.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-10-31 23:16:25 +11:00
Alessandro Gatti
d34b15ac6f pic16bit: Make it build with recent XC16 versions.
The PIC16 port didn't catch up with the other ports, so it required a bit
of work to make it build with the latest version of XC16.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-10-30 17:21:30 +11:00
Andrew Leech
548babf8a0 esp32/machine_pwm: Use IDF functions to calculate resolution correctly.
This commit fixes PWM configuration across C3, C6, S2 and S3 chips, which
was broken by 6d799378ba.  Without this fix
the PWM frequency is limited to a maximum of 2446Hz (on S2 at least).

Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-10-30 16:28:17 +11:00
Alessandro Gatti
86c71a0307 esp32/machine_hw_spi: Reject invalid number of bits in constructor.
This commit adds an extra bit of parameters validation to the SPI bus
constructor on ESP32.  Passing 0 as the number of bits would trigger a
division by zero error when performing read/write operations on an SPI
bus created in such a fashion.

Fixes issue #5910.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-10-30 15:14:30 +11:00
Glenn Moloney
9ea8d2a031 tools/mpremote: Fix UnboundLocalError in Transport.fs_writefile().
The variable `written` was being used before it was defined in the
`fs_writefile()` method of the Transport class.  This was causing an
`UnboundLocalError` to be raised when the `progress_callback` was not
provided.

Fixes issue #16084.

Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
2024-10-28 12:23:10 +11:00
Angus Gratton
043ba45bc3 esp32: Add some notes about the different CMake files.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-10-28 11:24:15 +11:00
Angus Gratton
ff70a91581 esp32: Move the linker wrap options out of the project CMakeLists.
For in-tree builds, these are effectively equivalent. However for
out-of-tree builds it's preferable to have as little as possible in the
top-level CMakeLists.txt file (as the out-of-tree build needs its own
copy).

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-10-28 11:24:15 +11:00
Steve Holden
4601dcb8a1 rp2/README: Remove redundant global statement from example code.
Since `led` is not being rebound inside the `tick` function the standard
Python name resolution method will find it.

Signed-off-by: Steve Holden <steve@holdenweb.com>
2024-10-28 11:16:04 +11:00
Damien George
44dc6eb30d all: Bump version to 1.25.0-preview.
Signed-off-by: Damien George <damien@micropython.org>
2024-10-28 11:08:24 +11:00
Damien George
f212bbe837 all: Bump version to 1.24.0.
Signed-off-by: Damien George <damien@micropython.org>
2024-10-26 01:43:23 +11:00
Damien George
18c9abc329 lib/micropython-lib: Update submodule to latest.
This brings in:
- requests improvements with overriding headers
- use non-u versions of built-in modules, including asyncio
- fix to logging so StreamHandler calls parent constructor
- various fixes to usb-device packages
- fixes to lora sx126x and sx127x drivers
- improvements to unix-ffi/sqlite3
- support additional gap_connect arguments in aioble

Signed-off-by: Damien George <damien@micropython.org>
2024-10-25 01:26:58 +11:00
iabdalkader
4c54335195 stm32/boards/ARDUINO_OPTA: Add Opta expansion module.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-10-25 01:19:54 +11:00
iabdalkader
57bc98f499 stm32/boards/ARDUINO_NICLA_VISION: Add SE05x driver.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-10-25 01:19:48 +11:00
iabdalkader
28009a78cf stm32/boards/ARDUINO_PORTENTA_H7: Add SE05x driver.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-10-25 01:19:06 +11:00
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