Commit Graph

16366 Commits

Author SHA1 Message Date
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
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
Damien George 70a884d6ec lib/pico-sdk: Update to version 2.0.0.
Adds support for the new RP2350 MCU.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 11:51:56 +11:00
Phil Howard 525fce7170 py/usermod.cmake: Check target exists in usermod_gather_sources.
Check a target exists before accessing properties.  Otherwise
usermod_gather_sources would recurse into garbage property names and break.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
2024-10-15 11:51:56 +11:00
Ayush Singh fa942d532f zephyr/boards: Add support for BeagleConnect Freedom.
Enable the following capabilities: I2C, SPI, FLASH.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2024-10-15 11:44:42 +11:00
Damien George d92694c3e8 tools: Only issue a single Ctrl-C when entering raw REPL.
A long time ago when there was only the `stm` port, Ctrl-C would trigger a
preemptive NLR jump to break out of running code.  Then in commit
124df6f8d0 a more general approach to
asynchronous `KeyboardInterrupt` exceptions was implemented, and `stmhal`
supported both approaches, with the general (soft) interrupt taking
priority.

Then in commit bc1488a05f `pyboard.py` was
updated with a corresponding change to make it issue a double Ctrl-C to
break out of any existing code when entering the raw REPL (two Ctrl-C
characters were sent in order to more reliably trigger the preemptive NLR
jump).

No other port has preemptive NLR jumps and so a double Ctrl-C doesn't
really behave any differently to a single Ctrl-C: with USB CDC the double
Ctrl-C would most likely be in the same USB packet and so processed in the
same low-level USB callback, so it's just setting the keyboard interrupt
flag twice in a row.  The VM/runtime then just sees one keyboard interrupt
and acts as though only one Ctrl-C was sent.

This commit changes the double Ctrl-C to a single Ctrl-C in `pyboard.py`
and `mpremote`.  That keeps things as simple as they need to be.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 11:40:08 +11:00
Damien George 7746785035 tests/run-tests.py: Wait for soft reset if a target skips a test.
Commit 69c25ea865 made raising `SystemExit`
do a soft reset (on bare-metal targets).  This means that any test which is
skipped by a target (by raising `SystemExit`) will trigger a soft reset on
that target, and then it must execute its startup code, such as `boot.py`.

If the timing is right, this startup code can be unintentionally
interrupted by the test runner when preparing the next test, because the
test runner enters the raw REPL again via a Ctrl-C Ctrl-A ctrl-D sequence
(in `Pyboard.enter_raw_repl()`).

When this happens (`boot.py` is interrupted) the target may not be set up
correctly, and it may (in the case of stm32 boards) flash LEDs and take
extra time, slowing down the test run.

Fix this by explicitly waiting for the target to finish its soft reset when
it skips a test.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 11:23:07 +11:00
Damien George 1223fa92f1 renesas-ra/pendsv: Remove preemptive keyboard interrupt via PendSV.
Following the same change to the stm32 port.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 10:32:24 +11:00
Damien George ece950d9be stm32/pendsv: Remove preemptive keyboard interrupt via PendSV.
Since the very beginning, the stm32 port (first called stm, then stmhal now
stm32) has had a special keyboard interrupt feature which works by using
PendSV to break out of any running code.  This preemptive ctrl-C was added
long ago in commit 01156d510c.

The stm32 port still uses that code, and current does this:

- If ctrl-C is received on UART or USB then `mp_sched_keyboard_interrupt()`
  is called (like all other ports) to set a flag for the VM to see, and
  then the VM (or any loop calling `mp_handle_pending(true)`) will
  eventually handle the `KeyboardInterrupt` exception, raising it via NLR.

- If another ctrl-C is received while the existing scheduled keyboard
  interrupt is still pending (ie the VM has not yet processed it) then a
  special hard NLR jump will activate, that preempts the calling code.
  Within the PendSV interrupt the stack is adjusted and an NLR jump is made
  to the most recent `nlr_push()` location.  This is like a normal NLR
  except it is called from an interrupt context and completely annihilates
  the code that was interrupted by the IRQ.

The reason for the preemptive interrupt was to handle ctrl-C before the VM
was able to handle it.  Eventually a mechanism (that's in use today by all
ports) was added to the VM and runtime to be able to check for pending
interrupts.  Then the stm32 port was updated to use this mechanism, with a
fallback to the old preemptive way if a second ctrl-C was received (without
the first one being processed).

This preemptive NLR jump is problematic because it can interrupt
long-running instructions (eg store multiple, usually used at the end of a
function to restore registers and return).  If such an instruction is
interrupted the CPU remembers that with some flags, and can resume the
long-running instruction when the interrupt finishes.  But the preemptive
NLR does a long jump to different code at thread level and so the
long-running interrupt is never resumed.  This leads to a CPU fault.

This fault has been previously reported in issues #3807 and #3842 (see also
issue #294).  It's now possible to easily reproduce this problem, since
commit 69c25ea865.  Running the test suite
over and over again on any stm32 board will eventually crash the board (it
can happen on a PYBv1.x, but it happens more regularly on PYBD-SF2/6).

The point is, a skipped test now soft resets the board and so the board
must run `boot.py` again.  The test runner may then interrupt the execution
of `boot.py` with the double-ctrl-C that it sends (in `tools/pyboard.py`,
`enter_raw_repl()`) in order to get the board into a known good state for
the next test.  If the timing is right, this can trigger the preemptive
PendSV in an unfortunate location and hard fault the board.

The fix in this commit is to just remove the preemptive NLR jump feature.
No other port has this feature and it's not needed, ctrl-C works very well
on those ports.  Preemptive NLR jump is a very dangerous thing (eg it may
interrupt and break out of an external SPI flash operation when reading
code from a filesystem) and is obviously buggy.

With this commit, stm32 borads no longer hard fault when running the test
suite (but it does leave an issue, the tests can still interrupt `boot.py`
with a single ctrl-C; that will be fixed separately).

An alternative to this commit would be to clear the CPU state for the
long-running instruction as suggested in issue #3842.  But it's much
simpler to just remove this code, which is now unnecessary and can have
other problems as per issue #294.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 10:32:14 +11:00
Damien George 44ed1c20ce esp32: Disable hardware stack protection on ESP32-C6.
The same as fee9d66e3a but for C6.

Fixes issue #15667.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-11 12:53:10 +11:00
Angus Gratton 82e69df33e esp32: Apply the LWIP active TCP socket limit.
This is a workaround for a bug in ESP-IDF where the configuration setting
for maximum active TCP sockets (PCBs) is not applied.

Fixes cases where a lot of short-lived TCP connections can cause:

- Excessive memory usage (unbounded number of sockets in TIME-WAIT).
- Much higher risk of stalled connections due to repeated port numbers. The
  maximum number of active TCP PCBs is reduced from 16 to 12 to further
  reduce this risk (trade-off against possibility of TIME-WAIT
  Assassination as described in RFC1337).

This is not a watertight fix for the second point: a peer can still reuse a
port number while a previous socket is in TIME-WAIT, and LWIP will reject
that connection (in an RFC compliant way) causing the peer to stall.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-10-10 17:55:03 +11:00
Angus Gratton 05ac69329d esp32: Fix hang in taskYIELD() on riscv CPUs when IRQs disabled.
Regression introduced in 337742f.

The hang occurs because the esp32 port was calling "from ISR" port-layer
functions to set/clear the interrupt mask. FreeRTOS kernel therefore
doesn't know the CPU is in a critical section. In taskYIELD() the riscv
port layer blocks after yielding until it knows the yield has happened, and
would block indefinitely if IRQs are disabled (until INT WDT triggers).

Moving to the "public" portENTER_CRITICAL/portEXIT_CRITICAL API means that
FreeRTOS knows we're in a critical section and can react accordingly.

Adds a regression test for this case (should be safe to run on all ports).

On single core CPUs, this should result in almost exactly the same
behaviour apart from fixing this case.

On dual core CPUs, we now have cross-CPU mutual exclusion for atomic
sections. This also shouldn't change anything, mostly because all the code
which enters an atomic section runs on the same CPU. If it does change
something, it will be to fix a thread safety bug.

There is some risk that this change triggers a FreeRTOS crash where there
is a call to a blocking FreeRTOS API with interrupts disabled. Previously
this code might have worked, but was probably thread unsafe and would have
hung in some circumstances.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-10-10 10:59:51 +11:00
Damien George 197becbdcc tests: Tweak machine SPI and UART tests to work with esp32c6.
Signed-off-by: Damien George <damien@micropython.org>
2024-10-09 23:34:27 +11:00
Andrew Leech 55dc482d3e esp32/sdkconfig: Disable PMP_IDRAM_SPLIT to fix native emit support.
Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-10-09 23:34:27 +11:00
Matt Trentini ce397d85af esp32/boards/UM_TINYC6: Add new UM C6 board definition.
Signed-off-by: Matt Trentini <matt.trentini@gmail.com>
2024-10-09 23:32:47 +11:00
Matt Trentini ee92198c8a esp32/boards/M5STACK_NANOC6: Add new M5Stack C6 board definition.
Signed-off-by: Matt Trentini <matt.trentini@gmail.com>
2024-10-09 23:32:26 +11:00
Andrew Leech 1bd312d737 esp32/boards/ESP32_GENERIC_C6: Add new generic esp32c6 board.
Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-10-09 23:32:10 +11:00
Andrew Leech 2f79854337 esp32/Makefile: Only set port & baud for jobs that access hardware.
In idf v5.2.1 if the port flag is set it's validated even on jobs that
don't access hardware like clean.  This causes the job to fail if device
isn't connected.

Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-10-09 23:31:54 +11:00
dmfaria 5aa115a4bc esp32/adc: Set ADC to 12bit by default on esp32c6.
Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-10-09 23:31:21 +11:00
Andrea Milazzo 68e95c73d3 esp32/machine_uart: Add support for LP_UART.
Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-10-09 23:31:16 +11:00