Commit Graph

548 Commits

Author SHA1 Message Date
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
Peter Harper
d2c85c74da rp2: Integrate RP2350 and use aon_timer instead of rtc API.
This commit separates various build settings and include files that are
specific to RP2040 and RP2350, and uses the aon_timer interface instead of
rtc, to work across both MCU variants.

Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Phil Howard <phil@gadgetoid.com>
2024-10-15 12:07:59 +11:00
Peter Harper
27aeade832 rp2/rp2_dma: Generalise DMA for RP2350.
Two new bits were added to the ctrl register, and existing bits were
shifted, so use DMA_CH0_CTRL_TRIG_xxx constants to generalise the code.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 11:57:06 +11:00
Peter Harper
d1423ef7a2 rp2/modmachine: Implement lightsleep for RP2350.
This isn't fully working, the CPU often wakes up early.  That will be fixed
when a newer version of pico-sdk is released.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 11:56:27 +11:00
Peter Harper
c90d996c9d rp2: Update custom linker scripts for new pico-sdk.
Signed-off-by: Phil Howard <phil@gadgetoid.com>
Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 11:51:56 +11:00
Peter Harper
815d6a131d rp2/mpconfigport: Set MCU name for RP2350.
Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 11:51:56 +11:00
Andrew Leech
548f88d2bd shared/tinyusb: Wake main task if needed at end of USB ISR.
Some checks are pending
unix port / settrace (push) Waiting to run
unix port / settrace_stackless (push) Waiting to run
unix port / macos (push) Waiting to run
unix port / qemu_mips (push) Waiting to run
unix port / qemu_arm (push) Waiting to run
unix port / qemu_riscv64 (push) Waiting to run
webassembly port / build (push) Waiting to run
windows port / build-vs (Debug, x64, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Debug, x64, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Debug, x86, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Debug, x86, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2019, dev, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2019, standard, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2022, standard, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-latest, standard, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2019, dev, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2019, standard, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2022, standard, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-latest, standard, 2017, [15, 16)) (push) Waiting to run
windows port / build-mingw (i686, mingw32, dev) (push) Waiting to run
windows port / build-mingw (i686, mingw32, standard) (push) Waiting to run
windows port / build-mingw (x86_64, mingw64, dev) (push) Waiting to run
windows port / build-mingw (x86_64, mingw64, standard) (push) Waiting to run
windows port / cross-build-on-linux (push) Waiting to run
zephyr port / build (push) Waiting to run
Python code lint and formatting with ruff / ruff (push) Waiting to run
Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-10-07 11:06:57 +11:00
Damien George
ca6723b144 rp2/cyw43_configport: Define CYW43_PRINTF to mp_printf to get messages.
Some checks failed
unix port / settrace (push) Has been cancelled
unix port / settrace_stackless (push) Has been cancelled
unix port / macos (push) Has been cancelled
unix port / qemu_mips (push) Has been cancelled
unix port / qemu_arm (push) Has been cancelled
unix port / qemu_riscv64 (push) Has been cancelled
webassembly port / build (push) Has been cancelled
windows port / build-vs (Debug, x64, windows-2022, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Debug, x64, windows-latest, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Debug, x86, windows-2022, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Debug, x86, windows-latest, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, x64, windows-2019, dev, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, x64, windows-2019, standard, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, x64, windows-2022, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x64, windows-2022, standard, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x64, windows-latest, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, x64, windows-latest, standard, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, x86, windows-2019, dev, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, x86, windows-2019, standard, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, x86, windows-2022, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x86, windows-2022, standard, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x86, windows-latest, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, x86, windows-latest, standard, 2017, [15, 16)) (push) Has been cancelled
windows port / build-mingw (i686, mingw32, dev) (push) Has been cancelled
windows port / build-mingw (i686, mingw32, standard) (push) Has been cancelled
windows port / build-mingw (x86_64, mingw64, dev) (push) Has been cancelled
windows port / build-mingw (x86_64, mingw64, standard) (push) Has been cancelled
windows port / cross-build-on-linux (push) Has been cancelled
zephyr port / build (push) Has been cancelled
Python code lint and formatting with ruff / ruff (push) Has been cancelled
The cyw43-driver uses `printf` by default for `CYW43_PRINTF`, but on the
rp2 port `printf` only goes to a UART output and not to USB CDC.

By defining `CYW43_PRINTF` to `mp_printf`, all the messages from the
cyw43-driver are seen on USB CDC.

For example this allows `network.WLAN().config(trace=1)` to show async
WALN events.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-03 12:12:18 +10:00
Angus Gratton
73feaaf931 rp2/machine_uart: Fix dropped UART REPL bytes on soft reset.
Necessary to fix "mpremote run" over hardware UART.

Bisect shows bug was introduced by d420b4e4, but looks like made more
complex by 01c046d2. Specifically: resetting and re-initialising the REPL
UART during soft reset clears the FIFO before it's done printing the "MPY:
soft reboot" line.

Fixed by adding a UART TX flush in the deinit path.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-09-26 23:43:11 +10:00
Damien George
40048f0f25 ports: Fix lwIP config setting to disable DHCP ARP check.
lwIP was recently updated in a89ac9e24a
to STABLE-2_2_0_RELEASE, and this introduced a change in the configuration
variable `DHCP_DOES_ARP_CHECK`, renaming it to `LWIP_DHCP_DOES_ACD_CHECK`.

This commit fixes the ports lwIP settings to use the new configuration
option.

Without this option, connecting to a WiFi access-point takes about 12.5
seconds.  With this option (ie disabling DHCP ARP checks) connecting takes
about 4 seconds.

Tested on an RPI_PICO_W and PYBD_SF2.

Signed-off-by: Damien George <damien@micropython.org>
2024-09-26 23:00:42 +10:00
iabdalkader
451ba1cf38 rp2/modules: Fix FatFS boot script to detect invalid FAT filesystem.
This change helps detect if the filesystem is invalid, by also including
the first mount attempt within the try-except.  Then the FAT is reformatted
if needed.

Fixes issue #15779.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-09-19 13:04:48 +10:00
ZodiusInfuser
ded8bbdd5e rp2/machine_pin_cyw43: Include check for CYW43_GPIO.
The `#if` check only checks that `MICROPY_PY_NETWORK_CYW43` and
`MICROPY_HW_PIN_EXT_COUNT` are defined.  This is a reasonable assumption
for the Pico W, but causes conflicts if someone wants to attach an external
IO expander to their Pico W and have its pins appear as Pin objects.

This commit addresses this by adding the additional checks, letting board
builds include wireless but separately choose whether the external IO pins
come from the cyw43 or not.

Signed-off-by: Christopher Parrott <chris@pimoroni.com>
2024-09-19 12:58:43 +10:00
ZodiusInfuser
79ba6d8ce7 rp2: Increase ext pins from 10 to 32.
To allow more pins when other ways are used to provide external GPIO (ie
not via cyw43).

Signed-off-by: Christopher Parrott <chris@pimoroni.com>
2024-09-19 12:54:20 +10:00
ZodiusInfuser
5dfd3ecd8b rp2: Add board-level hooks to main, and MICROPY_SOURCE_BOARD cmake var.
Signed-off-by: Christopher Parrott <chris@pimoroni.com>
2024-09-19 12:54:20 +10:00
Damien George
851aa06461 rp2: Integrate optional network.PPP.
Can be enabled by a board by enabling `MICROPY_PY_NETWORK_PPP_LWIP`.

Signed-off-by: Damien George <damien@micropython.org>
2024-08-29 23:47:55 +10:00
robert-hh
01c046d2a8 rp2/machine_uart: Implement a Python UART IRQ handler.
Supported trigger names: IRQ_RXIDLE, IRQ_TXIDLE, IRQ_BREAK

- IRQ_RXIDLE: The handler for IRQ_RXIDLE is called reliably 31 UART bit
  times after the last incoming data.

- IRQ_TXIDLE: This IRQ is triggered after at least >5 characters are sent
  at once.  It is triggered when the TX FIFO falls below 4 elements.  At
  that time, up to 5 bytes may still be in the FIFO and output shift
  register.

- IRQ_BREAK: The IRQ triggers if a BREAK state is detected at RX.
  Properties & side effects:
  - After a BREAK, a valid character must be received before another break
    can be detected.
  - Each break puts a 0xff character into the input buffer.

The irq.flags() value is cleared only with a new wanted event.  Do not
change the flags otherwise.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-08-29 16:27:43 +10:00
robert-hh
7270b871c2 rp2/modmachine: Set the peripheral frequency with machine.freq().
By default, the peripheral clock for UART and SPI is set to 48 MHz and will
not be affected by the MCU clock change.  This can be changed by a second
argument to `machine.freq(freq, peripheral_freq)`.  The second argument
must be either 48 MHz or identical with the first argument.

Note that UART and SPI baud rates may have to be re-configured after
changing the MCU clock.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-08-20 12:26:45 +10:00
robert-hh
d420b4e478 rp2/main: Set the default clock frequency at boot.
As a side effect, the peripheral clock will be set to 48Mhz and both UART
and I2C will not be affected by CPu speed changed using `machine.freq()`.

With the change the UART baud rate range is 50 to 3_000_000.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-08-20 12:26:45 +10:00
Phil Howard
26d91b897e rp2/mphalport: Skip core1_entry if thread disabled.
If `MICROPY_PY_THREAD` is set to 0 (ie: a user C module wishes to use core1
exclusively) then the test of `core1_entry` would fail to compile with an
"undeclared identifier" error.  Fix it by wrapping in `MICROPY_PY_THREAD`.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
2024-08-20 12:14:52 +10:00
Angus Gratton
fbc19596f0 rp2: Switch to use new cstack API for stack limit checks.
This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-08-14 12:57:23 +10:00
Phil Howard
d2e33fe309 rp2/machine_i2s: Deinit all active I2S instances on soft reset.
Add `machine_i2s_deinit_all` to teardown any active I2S instances on soft
reset.  Prior to this fix, code using I2S required a try/finally in order
to avoid a hard fault on soft reset.

Fixes issue #14339.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
2024-08-07 12:01:34 +10:00
Phil Howard
ad3552ae2c rp2/rp2_pio: Make PIO IRQ handlers have lazy initialisation.
Some checks failed
unix port / settrace (push) Has been cancelled
unix port / settrace_stackless (push) Has been cancelled
unix port / macos (push) Has been cancelled
unix port / qemu_mips (push) Has been cancelled
unix port / qemu_arm (push) Has been cancelled
unix port / qemu_riscv64 (push) Has been cancelled
webassembly port / build (push) Has been cancelled
windows port / build-vs (Debug, x64, windows-2022, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Debug, x64, windows-latest, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Debug, x86, windows-2022, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Debug, x86, windows-latest, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, x64, windows-2019, dev, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, x64, windows-2019, standard, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, x64, windows-2022, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x64, windows-2022, standard, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x64, windows-latest, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, x64, windows-latest, standard, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, x86, windows-2019, dev, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, x86, windows-2019, standard, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, x86, windows-2022, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x86, windows-2022, standard, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x86, windows-latest, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, x86, windows-latest, standard, 2017, [15, 16)) (push) Has been cancelled
windows port / build-mingw (i686, mingw32, dev) (push) Has been cancelled
windows port / build-mingw (i686, mingw32, standard) (push) Has been cancelled
windows port / build-mingw (x86_64, mingw64, dev) (push) Has been cancelled
windows port / build-mingw (x86_64, mingw64, standard) (push) Has been cancelled
windows port / cross-build-on-linux (push) Has been cancelled
zephyr port / build (push) Has been cancelled
Python code lint and formatting with ruff / ruff (push) Has been cancelled
This change has no impact on vanilla MicroPython builds, but is intended to
avoid RP2's PIO implementation from trampling PIO usage in USER_C_MODULES.

This is consistent with PIOs tracking of used state machines and managed
programs, and makes working with PIO in USER_C_MODULES much less of an
uphill battle.

Since PIO deinit runs before gc_sweep_all it's impossible to work around
this wrinkle otherwise.  A module finalizer does not get the opportunity to
put the PIOs back into a state which wont crash rp2_pio_deinit.

Changes are:
- init: Avoid exclusive handlers being added to all PIOs and add them only
  when needed.
- deinit: Only remove handlers we have set.
- rp2_pio_irq: Add the exlusive handler if needed.
- rp2_state_machine_irq: Add the exclusive handler if needed.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
2024-08-02 16:27:42 +10:00
Phil Howard
e7ff0b8a31 rp2/memmap_mp.ld: Lower the minimum GC heap to 32K.
Reduce mimimum heap requirement.  This value allows more room for large,
static buffers in user C modules (such as graphics buffers or otherwise)
which might be allocated outside of MicroPython's heap to guarantee
alignment or avoid fragmentation.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
2024-08-02 16:21:36 +10:00
Phil Howard
1557014ea4 rp2/boards/PIMORONI_TINY2040: Add an 8MB variant to Tiny 2040.
Add an 8MB "PIMORONI_TINY2040" variant.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
2024-08-02 16:17:48 +10:00
Phil Howard
cd1ab7645e rp2/boards/PIMORONI_PICOLIPO: Refactor Pico LiPo to use board variants.
Combine the 4MB and 16MB "PIMORONI_PICOLIPO" variants into a single board.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
2024-08-02 16:17:24 +10:00
Phil Howard
11becbe223 rp2/CMakeLists.txt: Add MICROPY_DEF_BOARD to compile definitions.
Add MICROPY_DEF_BOARD as per esp32 port, allows board variants to override
the board name with:

    list(APPEND MICROPY_DEF_BOARD
        MICROPY_HW_BOARD_NAME="New Board Name"
    )

Signed-off-by: Phil Howard <phil@gadgetoid.com>
2024-08-02 16:16:23 +10:00
Felix Dörre
7fe8f030ee rp2/lwip_inc: Enable IPv6 per default on rp2 port.
Some checks are pending
unix port / float_clang (push) Waiting to run
unix port / settrace (push) Waiting to run
unix port / settrace_stackless (push) Waiting to run
unix port / macos (push) Waiting to run
unix port / qemu_mips (push) Waiting to run
unix port / qemu_arm (push) Waiting to run
webassembly port / build (push) Waiting to run
windows port / build-vs (Debug, x64, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Debug, x64, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Debug, x86, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Debug, x86, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2019, dev, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2019, standard, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2022, standard, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-latest, standard, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2019, dev, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2019, standard, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2022, standard, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-latest, standard, 2017, [15, 16)) (push) Waiting to run
windows port / build-mingw (i686, mingw32, dev) (push) Waiting to run
windows port / build-mingw (i686, mingw32, standard) (push) Waiting to run
windows port / build-mingw (x86_64, mingw64, dev) (push) Waiting to run
windows port / build-mingw (x86_64, mingw64, standard) (push) Waiting to run
windows port / cross-build-on-linux (push) Waiting to run
zephyr port / build (push) Waiting to run
Python code lint and formatting with ruff / ruff (push) Waiting to run
Having IPv6 support is important, especially for IoT-Devices which might be
many, requiring individual IP-addresses. In particular direct access via
link-local addresses and having deterministic SLAAC-addresses can be quite
convenient. Also in IPv6-only networks or for connecting to IPv6-only
services, this is very useful.

For the Pico W, there is enough flash and RAM that enabling IPv6 by default
is the right choice.

Should IPv6 support in a network exist (i.e. there are Router
Advertisements), but not provide connectivity, connecting by domain name
should not be a problem as DNS will default to return the IPv4-address (if
that exists), unless reconfigured at runtime to prefer IPv6.

In any case a user can disable obtaining SLAAC-addresses with:

    <nic>.ipconfig(autoconf6=False)

Signed-off-by: Felix Dörre <felix@dogcraft.de>
2024-07-24 14:59:01 +10:00
Angus Gratton
ba98533454 rp2: Stop machine.idle() blocking indefinitely.
Some checks are pending
unix port / float_clang (push) Waiting to run
unix port / settrace (push) Waiting to run
unix port / settrace_stackless (push) Waiting to run
unix port / macos (push) Waiting to run
unix port / qemu_mips (push) Waiting to run
unix port / qemu_arm (push) Waiting to run
webassembly port / build (push) Waiting to run
windows port / build-vs (Debug, x64, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Debug, x64, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Debug, x86, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Debug, x86, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2019, dev, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2019, standard, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2022, standard, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-latest, standard, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2019, dev, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2019, standard, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2022, standard, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-latest, standard, 2017, [15, 16)) (push) Waiting to run
windows port / build-mingw (i686, mingw32, dev) (push) Waiting to run
windows port / build-mingw (i686, mingw32, standard) (push) Waiting to run
windows port / build-mingw (x86_64, mingw64, dev) (push) Waiting to run
windows port / build-mingw (x86_64, mingw64, standard) (push) Waiting to run
windows port / cross-build-on-linux (push) Waiting to run
zephyr port / build (push) Waiting to run
Python code lint and formatting with ruff / ruff (push) Waiting to run
Updates rp2 port to always resume from idle within 1ms max.

When rp2 port went tickless the behaviour of machine.idle() changed as
there is no longer a tick interrupt to wake it up every millisecond. On a
quiet system it would now block indefinitely. No other port does this.

See parent commit for justification of why this change is useful.

Also adds a test case that fails without this change.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-07-23 16:46:27 +10:00
Phil Howard
e1ecc232dc rp2/rp2_pio: Disable correct IRQ for PIO1.
Fix a typo that was disabling PIO0_IRQ_1 instead of PIO1_IRQ_0.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
2024-07-23 16:15:40 +10:00
Angus Gratton
9db16cfe31 rp2: Fix wakeup from WFE on core1.
If core1 executes `mp_wfe_or_timeout()` then it needs to receive an
interrupt or a SEV to resume execution, but the soft timer interrupt only
fires on core 0.  This fix adds a SEV to the soft timer interrupt handler.

This issue was masked by the issue fixed in the previous commit, as WFE
previously wasn't suspending properly.

Verified via the existing thread_sleep2 test.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-07-23 16:02:59 +10:00
Angus Gratton
eced9d86a7 rp2: Fix power consumption when sleeping with a timeout.
Fixes a regression introduced in 3af006efb3
where WFE never blocked in `mp_wfe_or_timeout()` function and would
busy-wait instead.  This increases power consumption measurably.

Root cause is that `mp_wfe_or_timeout()` calls soft timer functions that
(after the regression) call `recursive_mutex_enter()` and
`recursive_mutex_exit()`.  The exit calls
`lock_internal_spin_unlock_with_notify()` and the default pico-sdk
implementation of this macro issues a SEV which negates the WFE that
follows it, meaning the CPU never suspends.

See https://forums.raspberrypi.com/viewtopic.php?p=2233908 for more
details.

The fix in this comment adds a custom "nowait" variant mutex that doesn't
do WFE/SEV, and uses this one for PendSV.  This will use more power when
there's contention for the PendSV mutex as the other core will spin, but
this shouldn't happen very often.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-07-23 16:01:42 +10:00
robert-hh
2b8de7436b rp2/machine_adc: Initialise ADC GPIO when a Pin is referenced by int.
The change closes the gap in the API when an integer is used as Pin
reference.  With the change, e.g. ADC(26), ADC(Pin(26)) and ADC("GP26")
behave identically and the GPIO is initialised in ACD/high-Z mode.

Only when using ADC channel numbers 0-3 are the corresponding GPIO left
uninitialised, and then the user is responsible for configuring the GPIO.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-07-04 11:50:28 +10:00
Phil Howard
f61fac0ba6 rp2/rp2_pio: Replace explicit pio ternary expression with pio_get_index.
There are three changes here:
- Fix `rp2_pio_print` to use `pio_get_index()` too, since it had its own
  copy of the ternary expression.
- Remove a ternary from `rp2_pio_state_machine` and calculate it from
  `pio_get_index`.
- Remove a ternary on `GPIO_FUNC_PIO0` vs `GPIO_FUNC_PIO1`.  These
  constants are sequentially ordered so we can calculate them too.

Signed-off-by: Phil Howard <github@gadgetoid.com>
2024-07-03 16:48:18 +10:00
Phil Howard
462fa5f94f rp2/rp2_pio: Replace PIO_NUM macro with pio_get_index.
The `PIO_NUM` macro was defined when `rp2_pio.c` was first conceived.
There's now a Pico SDK function for this, `pio_get_index()`, which is
already used in some parts of the code.

This commit removes `PIO_NUM` in favour of using `pio_get_index()`
everywhere.

Signed-off-by: Phil Howard <github@gadgetoid.com>
2024-07-03 16:48:15 +10:00
Damien George
75350f9c8e rp2/mbedtls: Remove config options that are now in the common settings.
Signed-off-by: Damien George <damien@micropython.org>
2024-07-02 13:22:51 +10:00
Phil Howard
0e261443be rp2: Replace CMSIS funcs with Pico SDK equivalents.
Pico SDK defines `__dsb()` and `__sev()` so use those instead of the CMSIS
equivalents.  This matches the use of `__wfi()` in lieu of `__WFI()` and
lowers the dependency on CMSIS headers.

And then, move the include of "RP2040.h" from the widely-included
"mphalport.h" to specific source files that need this header, to keep its
inclusion contained.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
2024-07-01 11:27:42 +10:00
Damien George
0dd25a369e rp2/boards/WEACTSTUDIO: Fix variant names in board.json.
It looks like the variants for this board were never being built properly,
because the auto-build system used the variant name from `board.json` which
did not match the variant names in the original `mpconfigboard.mk`.  Eg
`FLASH_2MB` in `board.json` but `FLASH_2M` in `mpconfigboard.mk`.

This mistake is apparent since 5dff78f38e,
which made it a build error to specify an invalid variant.

Fix this by using the correct variant names in `board.json`.

Signed-off-by: Damien George <damien@micropython.org>
2024-06-28 22:48:46 +10:00
Damien George
5dff78f38e rp2: Rework board variant support to require mpconfigvariant file.
Following how the board variants now work in the esp32 port.

Signed-off-by: Damien George <damien@micropython.org>
2024-06-28 11:25:07 +10:00
Peter Harper
e35f13a22d rp2/pendsv: Fix variable typo in assert so it compiles.
Fixes issue #15276.

Signed-off-by: Peter Harper <peter.harper@raspberrypi.com>
2024-06-26 13:57:39 +10:00
Angus Gratton
f60c71d131 rp2: Don't disable USB if going to DORMANT mode.
In this mode, XOSC is stopped so can't really keep
the USB PLL enabled.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-06-25 16:48:39 +10:00
Angus Gratton
068d9bf2cf rp2: Fix USB PLL glitch during wake from light sleep.
Follow-up to a84c7a0ed9, this commit works most of the time but has an
intermittent bug where USB doesn't resume as expected after waking from
light sleep.

Turns out waking calls clocks_init() which will re-initialise the USB PLL.
Most of the time this is OK but occasionally it seems like the clock
glitches the USB peripheral and it stops working until the next hard reset.

Adds a machine.lightsleep() test that consistently hangs in the first
two dozen iterations on rp2 without this fix. Passed over 100 times in a
row with this fix.

The test is currently rp2-only as it seems similar lightsleep USB issues
exist on other ports (both pyboard and ESP32-S3 native USB don't send any
data to the host after waking, until they receive something from the host
first.)

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-06-25 16:25:19 +10:00
Angus Gratton
5dcffb53ab rp2/clocks_extra: Implement custom clocks_init function.
Adapts pico-sdk clocks_init() into clocks_init_optional_usb() which takes
an argument to initialise USB clocks or not.

To avoid a code size increase the SDK clocks_init() function is linker
wrapped to become clocks_init_optional_usb(true).

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-06-25 16:25:06 +10:00
Angus Gratton
cfa55b4ca1 rp2: Fix recursive atomic sections when core1 is active.
mp_thread_begin_atomic_section() is expected to be recursive (i.e. for
nested machine.disable_irq() calls, or if Python code calls disable_irq()
and then the Python runtime calls mp_handle_pending() which also enters an
atomic section to check the scheduler state).

On rp2 when not using core1 the atomic sections are recursive.

However when core1 was active (i.e. _thread) then there was a bug that
caused the core to live-lock if an atomic section recursed.

Adds a test case specifically for mutual exclusion and recursive atomic
sections when using two threads. Without this fix the test immediately
hangs on rp2.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-06-25 11:01:25 +10:00
Damien George
80a4f632ee rp2/cyw43_configport: Make cyw43_delay_ms() a busy loop.
Currently, `cyw43_delay_ms()` calls `mp_hal_delay_ms()` which uses PendSV
to set up a timer and wait for an interrupt, using wfe.  But in the cyw43
initialisation stage PendSV is disabled and so this delay suspends on the
wfe instruction for an indefinite amount of time.

Work around this by changing the implementation of `cyw43_delay_ms()` to a
busy loop.

Fixes issue #15220.

Signed-off-by: Damien George <damien@micropython.org>
2024-06-08 08:43:49 +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
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