Commit Graph

15948 Commits

Author SHA1 Message Date
Damien George
3c8089d1b1 py/lexer: Support raw f-strings.
Support for raw str/bytes already exists, and extending that to raw
f-strings is easy.  It also reduces code size because it eliminates an
error message.

Signed-off-by: Damien George <damien@micropython.org>
2024-06-06 17:34:28 +10:00
Damien George
a066f2308f py/lexer: Support concatenation of adjacent f-strings.
This is quite a simple and small change to support concatenation of
adjacent f-strings, and improve compatibility with CPython.

Signed-off-by: Damien George <damien@micropython.org>
2024-06-06 14:58:46 +10:00
Alessandro Gatti
d7aa2fe9d7 lib/libm: Define _IEEE_LIBM only if not set.
fdilibm was originally meant to see _IEEE_LIBM defined from outside the
libm code, not it being hardcoded in.  Picolibc assumes this assumption
holds true and attempts to define itself, conflicting with the existing
definition.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-06-06 13:01:42 +10:00
Alessandro Gatti
ace08c3978 shared/runtime/semihosting: Add RISC-V semihosting support.
This adds a RISC-V RV32 semihosting implementation, with all defined
system calls exposed to the user.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-06-06 12:55:21 +10:00
Alessandro Gatti
90d50ce918 shared/runtime/semihosting: Rename ARM semihosting files.
Make room for RISC-V semihosting code, by renaming the existing
`semihosting.[ch]` files into `semihosting_arm.[ch]`.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-06-06 12:55:15 +10:00
Alessandro Gatti
de0e13a9a8 shared/runtime/gchelper: Add RISC-V RV32I native gchelper.
Add native gchelper support for 32 bits RISC-V RV32I targets.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-06-06 12:01:00 +10:00
Alessandro Gatti
e6ae699998 py/nlrrv32: Add RISC-V RV32I NLR implementation.
Add custom NLR support for 32 bits RISC-V RV32I targets.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-06-06 11:56:58 +10:00
Alessandro Gatti
596f92bf77 tools/makemanifest.py: Generate working code for empty manifests.
When no usable manifest directives are found (as opposed to no manifest
being set in the makefile), non-compiling code was generated for the
empty frozen constants pool block.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-06-05 14:07:26 +02:00
Andrew Leech
8809ae7161 shared/tinyusb: Buffer startup CDC data to send to host on connection.
At startup, buffer initial stdout / MicroyPthon banner so that it can be
sent to the host on initial connection of the USB serial port.  This
buffering also works for when the CDC becomes disconnected and the device
is still printing to stdout, and when CDC is reconnected the most recent
part of stdout (depending on how big the internal USB FIFO is) is flushed
to the host.

This change is most obvious when you've first plugged in a MicroPython
device (or hit reset), when it's a board that uses USB (CDC) serial in the
chip itself for the REPL interface.  This doesn't apply to UART going via a
separate USB-serial chip.

The stm32 port already has this buffering behaviour (it doesn't use
TinyUSB) and this commit extends such behaviour to rp2, mimxrt, samd and
renesas-ra ports, which do use TinyUSB.

Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-06-04 17:49:19 +10:00
Andrew Leech
d144f0699d lib/tinyusb: Update to the most recent master.
Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-06-04 17:47:51 +10:00
robert-hh
e138bafbc7 cc3200/mods: Implement network.ipconfig and network.WLAN.ipconfig.
Signed-off-by: robert-hh <robert@hammelrath.com>
2024-06-04 12:45:01 +10:00
Felix Dörre
9ece9f9b52 esp8266/network_wlan: Implement network.ipconfig and WLAN.ipconfig.
Co-authored-by: robert-hh <robert@hammelrath.com>

Signed-off-by: Felix Dörre <felix@dogcraft.de>
2024-06-04 12:45:01 +10:00
Felix Dörre
b555d6ccaf esp32/network_ppp: Implement network.PPP.ipconfig method.
Signed-off-by: Felix Dörre <felix@dogcraft.de>
2024-06-04 12:45:01 +10:00
robert-hh
a71471be66 extmod/network_lwip: Allow using the CIDR notation for addr4.
There was a little omisssion in the code.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-06-04 12:45:01 +10:00
robert-hh
7e7cc2b427 extmod/network_ninaw10: Implement the ipconfig methods for ninaw10.
This implements network.ipconfig() and network.WLAN.ipconfig() when the
ninaw10 driver is used for WLAN.

Due to a omission in the ninaw10 driver stack, setting the DNS address has
no effect.  But the interface is kept here just in case it's fixed
eventually.

dhcp4 and has_dhcp4 are dummy arguments.  Ninaw10 seems to always use DHCP.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-06-04 12:45:01 +10:00
Felix Dörre
1f23ab1e3d esp32,mimxrt,stm32: Implement ipconfig() for more network interfaces.
Implements:
- esp32: network.ipconfig()
- esp32: network.LAN.ipconfig()
- esp32: network.WLAN.ipconfig()
- mimxrt: network.LAN.ipconfig()
- stm32: network.LAN.ipconfig()

Signed-off-by: Felix Dörre <felix@dogcraft.de>
2024-06-04 12:45:01 +10:00
Damien George
0e19286c94 tools/metrics.py: Change rp2 board selection to RPI_PICO_W.
This tool is used to compute size differences in the firmware (eg as part
of CI), but it doesn't currently check any firmware that has bare-metal
lwIP/networking, making it hard to see how firmware size changes when
networking related changes are made.

So, change the board selection for the rp2 port to RPI_PICO_W.  Changes in
size to standard RPI_PICO firmware will be very similar to other bare-metal
boards like PYBV10.

Signed-off-by: Damien George <damien@micropython.org>
2024-06-04 10:54:35 +10:00
Phil Howard
932f76c6ba rp2/CMakeLists: Use MICROPY_BOARD_DIR to find pins.csv.
Assuming that ${MICROPY_PORT_DIR}/boards/${MICROPY_BOARD} is equal to
${MICROPY_BOARD_DIR} is not valid, because the latter could point to a path
outside the main MicroPython repository.

Replace this path with the canonical ${MICROPY_BOARD_DIR} so that pins.csv
is correctly located when building against out-of-tree board definitions.

Additionally remove MICROPY_BOARDS_DIR to discourage similar mistakes.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
2024-06-03 16:26:08 +10:00
Angus Gratton
a84c7a0ed9 rp2/modmachine: Selectively leave the USB clocks enabled in lightsleep.
Without this change going to lightsleep stops the USB peripheral clock, and
can lead to either the device going into a weird state or the host deciding
to issue a bus reset.

This change only keeps the USB peripheral clocks enabled if the USB device
is currently active and a host has configured the device.  This means the
USB device continues to respond to host transfers and (presumably) will
even complete pending endpoint transfers.  All other requests are NAKed
while still asleep, but the interaction with the host seems to resume
correctly on wake

Otherwise, if USB is not active or configured by a host, USB clocks are
disabled, the same as before.

With the change, one can issue a `machine.lightsleep(...)` with USB CDC
connected and the USB CDC remains connected during the sleep and resumes
when the lightsleep finishes.

Tested on a RPi Pico, the power consumption is:
- During normal idle at the REPL, about 15.3mA.
- During lightsleep, prior to this change, about 1.35mA.
- During lightsleep, with this change and USB CDC connected, about 3.7mA.

If power consumption should be as low as possible when USB is connected,
one can use `machine.USBDevice` to disable the USB before entering
lightsleep.

As discussed at https://github.com/orgs/micropython/discussions/14401

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-06-03 16:00:52 +10:00
Matthias Blankertz
93394da69c rp2/modmachine: Use atomic section macros in lightsleep code.
To avoid undefined references to `mp_thread_begin_atomic_section()` /
`mp_thread_end_atomic_section()`, replace them with the
`MICROPY_BEGIN_ATOMIC_SECTION` / `MICROPY_END_ATOMIC_SECTION`
macros.  That way, it's possible to build again with `MICROPY_PY_THREAD`
disabled (made possible by efa54c27b9).

Fixes commit 19844b4983.

Signed-off-by: Matthias Blankertz <matthias@blankertz.org>
2024-06-03 14:40:23 +10:00
Damien George
84a8f7ea6d shared/tinyusb: Allow ports to use 1200bps-touch without other CDC code.
This fixes the build for some esp32 and nrf boards (for example
`ARDUINO_NANO_33_BLE_SENSE` and `ARDUINO_NANO_ESP32`) due to commit
c98789a6d8.  Changes are:

- Allow the CDC TX/RX functions in `mp_usbd_cdc.c` to be enabled
  separately to those needed for `MICROPY_HW_USB_CDC_1200BPS_TOUCH`.

- Add `MICROPY_EXCLUDE_SHARED_TINYUSB_USBD_CDC` option as a temporary
  workaround for the nrf port to use.

- Declare `mp_usbd_line_state_cb()` in a header as a public function.

- Fix warning with type cast of `.callback_line_state_changed`.

Signed-off-by: Damien George <damien@micropython.org>
2024-06-02 23:27:33 +10:00
Angus Gratton
c1a6b95bf2 github/ISSUE_TEMPLATE: Update issue form to remove checklist generation.
Update to the issue forms added earlier this year, that seem to generally
be working well.  Improvements in this commit:

- No longer generates TODO checklists in new issues.

- Issue bodies (and therefore email previews) no longer start with the same
  fixed checklist text for each new issue.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-05-31 22:17:45 +10:00
Andrew Leech
c11efc74ee samd/mphalport: Refactor to use shared TinyUSB CDC functions.
Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-05-31 19:47:55 +10:00
Andrew Leech
2d33071b17 renesas-ra/mphalport: Refactor to use shared TinyUSB CDC functions.
Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-05-31 19:47:37 +10:00
Andrew Leech
2475a52f5c mimxrt/mphalport: Refactor to use shared TinyUSB CDC functions.
Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-05-31 19:47:25 +10:00
Andrew Leech
1eaa562fdf rp2/mphalport: Refactor to use shared TinyUSB CDC functions.
Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-05-31 19:47:05 +10:00
Andrew Leech
c98789a6d8 shared/tinyusb: Add common CDC TX/RX functions.
There are a few TinyUSB CDC functions used for stdio that are currently
replicated across a number of ports.  Not surprisingly in a couple of cases
these have started to diverge slightly, with additional features added to
one of them.

This commit consolidates a couple of key shared functions used directly by
TinyUSB based ports, and makes those functions available to all.

Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-05-31 19:45:42 +10:00
Alessandro Gatti
3613ad9624 lib/libm: Do not force floating point type size evaluation.
Since C99, `FLT_EVAL_METHOD` should be left for the compiler/libc to
define.  Its redefinition breaks compilation with picolibc as the
target's libc, since it defines said symbol in math.h before the libm
define is evaluated by the compiler.

In its place, there is a check to make sure floating point type sizes
are what are expected to be, triggering a compilation error if those
assumptions are no longer valid.

Co-authored-by: Angus Gratton <angus@redyak.com.au>
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-05-31 17:04:24 +10:00
Angus Gratton
3af006efb3 rp2: Support calling pendsv_suspend/resume from core 1.
Previously, this was subject to races incrementing/decrementing
the counter variable pendsv_lock.

Technically, all that's needed here would be to make pendsv_lock an atomic
counter.

This implementation fulfils a stronger guarantee: it also provides mutual
exclusion for the core which calls pendsv_suspend(). This is because the
current use of pendsv_suspend/resume in MicroPython is to ensure exclusive
access to softtimer data structures, and this does require mutual
exclusion.

The conceptually cleaner implementation would split the mutual exclusion
part out into a softtimer-specific spinlock, but this increases the
complexity and doesn't seem like it makes for a better implementation in
the long run.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-05-31 16:46:27 +10:00
Angus Gratton
83e82c5ad3 rp2: Refactor to not use pico-sdk alarm pool functions for sleeping.
The best_effort_wfe_or_timeout() and sleep_us() pico-sdk functions use the
pico-sdk alarm pool internally, and that has a bug.

Some usages inside pico-sdk (notably multicore_lockout_start_blocking())
will still end up calling best_effort_wfe_or_timeout(), although usually
with "end_of_time" as the timeout value so it should avoid any alarm pool
race conditions.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-05-31 16:44:09 +10:00
Angus Gratton
74fb42aa82 rp2: Refactor soft timer to use hardware timer alarm.
Progress towards removing pico-sdk alarm pool, due to a known issue.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-05-31 16:43:52 +10:00
Damien George
2926001b60 all: Bump version to 1.24.0-preview.
Signed-off-by: Damien George <damien@micropython.org>
2024-05-31 16:35:27 +10:00
Damien George
a61c446c0b all: Bump version to 1.23.0.
Signed-off-by: Damien George <damien@micropython.org>
2024-05-31 14:19:55 +10:00
Damien George
30a9ccf4ca tests/basics: Move str/bytes tests that give SyntaxWarning to sep file.
In CPython 3.12 these invalid str/bytes/fstring escapes will issue a
SyntaxWarning, and so differ to MicroPython.

Signed-off-by: Damien George <damien@micropython.org>
2024-05-28 10:58:37 +10:00
Damien George
dd4767a7d1 tests/basics: Add .exp file for slice_op test.
CPython 3.12 implemented hashing for slices, so now differs to MicroPython.

Signed-off-by: Damien George <damien@micropython.org>
2024-05-28 10:50:57 +10:00
Damien George
ad6750b22e tests/float: Use "not" instead of ~ to invert bool value.
Otherwise CPython gives a deprecation warning.

This test is not actually testing inversion of bools, rather that bit of
the test is used to compute the pass/fail result.

Signed-off-by: Damien George <damien@micropython.org>
2024-05-28 10:49:22 +10:00
Damien George
5f6e689124 LICENSE,docs: Update copyright year range to include 2024.
Signed-off-by: Damien George <damien@micropython.org>
2024-05-27 23:39:16 +10:00
Damien George
8a8c65f309 lib/micropython-lib: Update submodule to latest.
This brings in:
- fixes to: aiohttp, tarfile, lora, gzip
- fixes and improvements to aioble
- deprecation of cbor2 decoder and encoder modules
- new usb package
- new pyusb package

Signed-off-by: Damien George <damien@micropython.org>
2024-05-27 16:27:41 +10:00
Matt Trentini
03cf4d4980 rp2/boards/W5500_EVB_PICO: Update incorrect url in board.json.
Fixes issue #15122.

Signed-off-by: Matt Trentini <matt.trentini@gmail.com>
2024-05-27 16:14:20 +10:00
Damien George
a34b5d1b79 tests/net_inet/tls_text_errors.py: Tweak test for newer CPython version.
Signed-off-by: Damien George <damien@micropython.org>
2024-05-27 13:56:55 +10:00
Damien George
e1111d873a tests/net_hosted/ssl_verify_callback.py: Make exp match actual output.
The `cert` argument passed to the verify callback is actually a memoryview.
And the `depth` argument seems to start at 1 for the tested URL.

Signed-off-by: Damien George <damien@micropython.org>
2024-05-27 13:56:55 +10:00
Damien George
1a2fdcac0d tests/basics: Split out generator.throw tests that pass multiple args.
The three-argument form of `.throw()` is deprecated since CPython 3.12.  So
split out into separate tests (with .exp files) the parts of the generator
tests that test more than one argument.

Signed-off-by: Damien George <damien@micropython.org>
2024-05-27 13:56:55 +10:00
Damien George
2e852522b1 tests/extmod: Add .exp test files for asyncio.get_event_loop tests.
And use `asyncio.new_event_loop()` where possible.  This change is needed
because CPython 3.12 deprecated the `get_event_loop()` function.

Signed-off-by: Damien George <damien@micropython.org>
2024-05-27 13:56:55 +10:00
Damien George
1ea06b99d8 tests/extmod: Fix regex strings to be of r"" type.
Otherwise escape characters like \s and \W won't work correctly.

Signed-off-by: Damien George <damien@micropython.org>
2024-05-27 13:56:55 +10:00
Damien George
c0a25a69eb extmod/modos: Only sync FAT filesystems using disk_ioctl.
Eventually this needs to be made a generic call to the underlying VFS.  But
for now this prevents `disk_ioctl()` crashing on non-FAT filesystems.

Signed-off-by: Damien George <damien@micropython.org>
2024-05-27 12:44:02 +10:00
Damien George
fbf811474a tools/ci.sh: Simplify selection of natmod tests to run.
The `run-natmodtests.py` script now properly excludes tests that don't use
the corresponding native module.

Signed-off-by: Damien George <damien@micropython.org>
2024-05-27 11:45:59 +10:00
Damien George
5d07d0c7b0 tests/run-natmodtests.py: Fix search for supported native tests.
Signed-off-by: Damien George <damien@micropython.org>
2024-05-27 11:44:54 +10:00
Damien George
df41913782 examples/natmod/btree: Make btree.open use mp_arg_parse_all for kwargs.
Python code is no longer needed to implement keyword arguments in
`btree.open()`, it can now be done in C.

Signed-off-by: Damien George <damien@micropython.org>
2024-05-24 13:50:57 +10:00
Brian Pugh
c624a5c0c4 py/dynruntime: Export mp_load_method_maybe and mp_arg_parse_all* funcs.
Also define `mp_type_bytearray`.  These all help to write native modules.

Signed-off-by: Brian Pugh <bnp117@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
2024-05-24 13:50:57 +10:00
Jared Hancock
a196468c47 esp32: Add support for TCP_NODELAY.
This adds support for the TCP_NODELAY socket option for lwIP sockets.
Generally, TCP sockets use the Nagle algorithm and will send data when
an ACK is received or after all previously-sent data has already been
ACKed.

If the TCP_NODELAY option is set for a socket, every write to the socket
will trigger a packet to be sent.

Signed-off-by: Jared Hancock <jared@greezybacon.me>
2024-05-23 20:47:17 -05:00