Commit Graph

16389 Commits

Author SHA1 Message Date
Andrew Leech
9670666623 stm32/boards: Enable RAM_ISR feature on boards with UART REPL.
Allows mpremote file transfer to work correctly when mpremote is used over
the ST-link USB/UART REPL port.

Fixes issue #8386.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2024-09-02 11:30:40 +10:00
Andrew Leech
1f5cab9edb stm32: Add option to put ISR, flash and UART code in RAM.
This allows UART RX to function while flash erase/writes operations are
under way, preventing lost serial data so long as it fits in the UART RX
buffer.

This enables (among other things) mpremote to successfully copy files to
boards that use a UART REPL.

Enable via the following option placed in `mpconfigboard.mk`:

    MICROPY_HW_ENABLE_ISR_UART_FLASH_FUNCS_IN_RAM = 1

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2024-09-02 11:30:34 +10:00
Damien George
35b6a66b0b docs/library: Document the network.PPP class.
Signed-off-by: Damien George <damien@micropython.org>
2024-08-29 23:47:55 +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
Damien George
aee002dd80 stm32/lwip_inc: Implement LWIP_PLATFORM_DIAG macro in terms of printf.
This allows enabling lwIP debugging output.  For example, to enable PPP
debugging add the following to `mpconfigboard.h`:

    #define LWIP_DEBUG 1
    #define PPP_DEBUG LWIP_DBG_ON

Signed-off-by: Damien George <damien@micropython.org>
2024-08-29 23:47:55 +10:00
Damien George
a1a16ffd75 stm32/uart: Use timeout_char even with CTS enabled.
When timeout=0 (non-blocking mode) the UART should still wait for each
character to go out.  Otherwise non-blocking mode with CTS enabled is
useless because it can only write one character at a time.

Signed-off-by: Damien George <damien@micropython.org>
2024-08-29 23:47:55 +10:00
Damien George
d8b033776e stm32/machine_uart: Return number of bytes written even with timeout.
The errcode should be cleared so the caller sees a successful write, even
if it's a short write.

Signed-off-by: Damien George <damien@micropython.org>
2024-08-29 23:47:13 +10:00
Damien George
c94a3205b0 stm32/machine_uart: Allow changing only the baudrate.
Signed-off-by: Damien George <damien@micropython.org>
2024-08-29 23:46:13 +10:00
Damien George
a5cc4d4623 stm32: 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:46:13 +10:00
Damien George
bc952d37fe extmod/network_ppp_lwip: Add network.PPP via lwIP.
This commit adds a new `network.PPP` interface which works on any port that
has bare-metal lwIP, eg rp2, stm32, mimxrt.

It has been tested on stm32.  A board needs to enable
`MICROPY_PY_NETWORK_PPP_LWIP` and then it can use it as follows:

    import network

    ppp = network.PPP(uart)
    ppp.connect()

    while not ppp.isconnected():
        pass

    # use `socket` module as usual, etc

    ppp.disconnect()

Usually the application must first configure the cellular/etc UART link to
get it connected and in to PPP mode first (eg ATD*99#), before handing over
control to `network.PPP`.

The PPP interface automatically configures the UART IRQ callback to call
PPP.poll() on incoming data.

Signed-off-by: Damien George <damien@micropython.org>
2024-08-29 23:46:13 +10:00
Damien George
664dd7b54a extmod: Update make and cmake scripts to work with latest lwIP.
Signed-off-by: Damien George <damien@micropython.org>
2024-08-29 23:46:13 +10:00
Damien George
a89ac9e24a lib/lwip: Update lwIP to STABLE-2_2_0_RELEASE.
This updates lwIP from STABLE-2_1_3_RELEASE, which was released in November
2021.  The latest STABLE-2_2_0_RELEASE was released in September 2023.

Signed-off-by: Damien George <damien@micropython.org>
2024-08-29 23:45:34 +10:00
Damien George
09d070aa55 tests/extmod_hardware: Add tests for machine.UART.IRQ_RX/RXIDLE/BREAK.
These all require hardware connections, so live in a different directory.

Except for the IRQ_BREAK test of ESP32 devices a single UART with loopback
is sufficient.

General:
    SAMD21: Due to the limited flash size only SAMD21 devices with external
    flash support uart.irq().

IRQ_BREAK:
    ESP32 needs different UART devices for creating and sensing a break.
    Lacking a second UART the test is skipped for ESP32S2 and ESP32C3.  RP2
    does not pass the test reliable at 115200 baud, reason to be found.
    Thus the upper limit is set to 57600 Baud.

    Coverage:
        esp32  pass when different UART devices are used.
        rp2    pass up to 57600 baud

IRQ_RX:
    SAMD21: Being a slow device it needs data to be sent byte-by-byte at
    9600 baud, since the IRQ callback is scheduled delayed and then the
    flags do not match any more.  The data matches since it is queued in
    the FIFO resp. ringbuffer.

    CC3200: The test cannot be performed since no calls are accepted in the
    IRQ handler like u.read(). Skipped.

    Coverage:
        cc3200 fail due to major differences in the implementation.
        esp32  pass
        nrf    pass
        renesas-ra pass
        samd   pass see the notes.
        stm32  pass

IRQ_RXIDLE:
    STM32: With PyBoard the IRQ is called several times, but only once with
    the flag IRQ_RXIDLE set.

    Coverage:
        esp32    pass
        mimxrt   pass
        renesas-ra pass
        rp2      pass
        samd     pass for both SAMD21 and SAMD51
        stm32    fail. see notes.

Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: robert-hh <robert@hammelrath.com>
2024-08-29 16:48:09 +10:00
Damien George
b8513e6137 tests/extmod: Add test for machine.UART.IRQ_TXIDLE.
The test checks whether the message created by the IRQ handler appears
about at the end of the data sent by UART.

Supported MCUs resp. boards:
- RP2040
- Teensy 4.x
- Adafruit ItsyBitsy M0
- Adafruit ItsyBitsy M4
- NRF52 (Arduino Nano Connect 33 BLE)

Signed-off-by: Damien George <damien@micropython.org>
2024-08-29 16:48:09 +10:00
robert-hh
03b1b6d8e6 docs/library/machine.UART: Extend the documentation for UART.irq.
For more ports and trigger options, based on the current state of the code.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-08-29 16:48:09 +10:00
Damien George
9bbe61607a docs/library/machine.UART: Fix UART.irq docs to match current code.
These docs now match the code in `extmod/machine_uart.c`.  IRQ trigger
support still need to be updated for each port (to be done in a follow-up
commit).

Signed-off-by: Damien George <damien@micropython.org>
2024-08-29 16:34:45 +10:00
robert-hh
a38b4f4287 esp32/machine_uart: Implement UART.RX_IDLE based on machine.Timer.
The UART.IRQ_IDLE callback is called about two character times after the
last byte, or 1 ms, whichever is larger.  For the irq, timer 0 is used.

machine_timer.c had to be reworked to make it's mechanisms available for
machine_uart.c.

The irq.flags() value is change only at a requested event.  Otherwise keep
the state.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-08-29 16:34:33 +10:00
robert-hh
7045975d04 renesas-ra/machine_uart: Implement UART.IRQ_RXIDLE based on softtimer.
Allowing to define the trigger UART.IRQ_RXIDLE as well as UART.IRQ_RX.  The
delay for the IRQ_RXIDLE interrupt is about 3 character times or 1-2 ms,
whichever is larger.

The irq.flags() value is changed only with an expected event.  Do not
change it otherwise.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-08-29 16:27:43 +10:00
robert-hh
ef69d0f2d3 samd/machine_uart: Implement UART.IRQ_RXIDLE based on the softtimer.
With the softtimer the minimal delay between the end of a message and the
trigger is 2 ms.  For baud rates <= 9600 baud it's three character times.
Tested with baud rates up tp 115200 baud.  The timer used for RXIDLE is
running only during UART receive, saving execution cycles when the timer is
not needed.

The irq.flags() value is changed only with an expected event.  Do not
change it otherwise.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-08-29 16:27:43 +10:00
robert-hh
a86619fb6f stm32/machine_uart: Add the UART.IRQ_RX event for UART.irq().
Just adding the event symbol.  No code change required, and no impact on
code execution time when the event is not selected.

Tested with STM32F4xx, STM32F7xx and STM32H7xx.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-08-29 16:27:43 +10:00
robert-hh
bae809070e nrf/modules/machine/uart: Implement Python UART IRQ for nrf52840 boards.
Supported triggers: UART.IRQ_RX and UART.IRQ_TXIDLE.  It will probably work
on other boards as well, but so far untested.

The irq.flags() value is changed only when requested by a triggered event.
Do not change it otherwise.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-08-29 16:27:43 +10:00
robert-hh
4da5de94bb nrf/modules/machine/uart: Allow changing the UART baud rate w/o reset.
This commit fixes a bug in the existing driver, that the UART baud rate
could not be changed without reset or power cycle.  It adds as well
functionality to UART.deinit().

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-08-29 16:27:43 +10:00
robert-hh
a04a14163b esp32/machine_uart: Implement Python UART IRQ with IRQ_RX and IRQ_BREAK.
Supported trigger events: IRQ_RX and IRQ_BREAK.  Hard IRQ is not supported.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-08-29 16:27:43 +10:00
robert-hh
1027b5f083 cc3200/mods/pybuart: Add the UART.IRQ_RX class constant.
As alternative to RX_ANY to match the names used by the other ports.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-08-29 16:27:43 +10:00
robert-hh
324c675347 renesas-ra/machine_uart: Add the UART.IRQ_RX class constant.
The renesas-ra port supports calling a handler to be called on every byte
received by UART.  For consistency with other ports, the symbol IRQ_RX
is added as the trigger name.

Side change: Add the received UART data to the REPL input buffer only if it
is the REPL UART.  Otherwise, every UART would act as REPL input.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-08-29 16:27:43 +10:00
robert-hh
b7fa4e2fc8 mimxrt/machine_uart: Implement a Python UART IRQ handler.
Supported triggers are: IRQ_RXIDLE and IRQ_TXIDLE.

When IRQ_RXIDLE is set, the handler will be called 3 character times after
the data in burst stopped.

When IRQ_TXIDLE is set, the handler will be called immediately after the
data has been sent.

This commit requires a change to fsl_lpuart.c, because the existing code
does not support under-run appropriately.

The irq.flags() value is cleared only at an expected event.  Do not change
it otherwise.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-08-29 16:27:43 +10:00
robert-hh
8e1123b25b samd/machine_uart: Implement a Python UART IRQ handler.
Supported for all SAMD51 devices and SAMD21 with external flash.  For
interrupt events, IRQ_RX and IRQ_TXIDLE are provided.

IRQ_RX is called for every received byte.  This may not be useful for high
data rates, but can be used to build a wrapper class providing an
IRQ_RXIDLE event or to signal just the first byte of a message.

IRQ_TXIDLE is called only when messages are longer than 5 bytes and
triggers when still 5 bytes are due to be sent.

The SAMD hardware does not support implementing IRQ_RXIDLE.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-08-29 16:27:43 +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
Damien George
fd03a0587f examples/network: Support full URLs in HTTP(S) client examples.
Not just the domain name.  This gives better HTTP 1.0 examples if someone
wants to copy them.

Signed-off-by: Damien George <damien@micropython.org>
2024-08-28 12:28:58 +10:00
Damien George
d75705311a examples/network: Use SSLContext instead of old ssl.wrap_socket.
`ssl.wrap_socket()` is deprecated in CPython, so use `SSLContext` instead,
so the example is a good example to copy.

Signed-off-by: Damien George <damien@micropython.org>
2024-08-28 12:28:58 +10:00
Damien George
c8385ef75a examples/network: Support IPv4 and IPv6 in HTTP client examples.
The main changes here are to pass the address family and socket type to
`getaddrinfo()`, and then use the result of the address lookup when
creating the socket, so it has the correct address family.

This allows both IPv4 and IPv6 to work, because the socket is created with
the correct AF_INETx type for the address.

Also add some more comments to the examples to explain what's going on.

Fixes issue #15580.

Signed-off-by: Damien George <damien@micropython.org>
2024-08-28 12:28:58 +10:00
Damien George
d9a0fdda9a qemu-arm: Rework to provide a REPL and run tests via a pty serial port.
Currently, the qemu-arm (and qemu-riscv) port has two build modes:
- a simple test that executes a Python string; and
- a full test that uses tinytest to embed all tests within the firmware,
  then executes that and captures the output.

This is very different to all the other ports.  A difficulty with using
tinytest is that with the large number of tests the firmware overflows its
virtual flash size.  It's also hard to run tests via .mpy files and with
the native emitter.  Being different to the other ports also means an extra
burden on maintenance.

This commit reworks the qemu-arm port so that it has a single build target
that creates a standard firmware which has a REPL.  When run under
qemu-system-arm, the REPL acts like any other bare-metal port, complete
with soft reset (use machine.reset() to turn it off and exit
qemu-system-arm).

This approach gives many benefits:
- allows playing with a REPL without hardware;
- allows running the test suite as it would on a bare-metal board, by
  making qemu-system-arm redirect the UART serial of the virtual device to
  a /dev/pts/xx file, and then running run-tests.py against that serial
  device;
- skipping tests is now done via the logic in `run-tests.py` and no longer
  needs multiple places to define which tests to skip
  (`tools/tinytest-codegen.py`, `ports/qemu-arm/tests_profile.txt` and also
  `tests/run-tests.py`);
- allows testing/using mpremote with the qemu-arm port.

Eventually the qemu-riscv port would have a similar change.

Prior to this commit the test results were:

    743 tests ok.  (121 skipped)

With this commit the test results are:

    753 tests performed (22673 individual testcases)
    753 tests passed
    138 tests skipped

More tests are skipped because more are included in the run. But overall
more tests pass.

Signed-off-by: Damien George <damien@micropython.org>
2024-08-28 11:52:08 +10:00
Damien George
8a3842eba7 qemu-arm/uart: Implement uart_rx_chr.
Signed-off-by: Damien George <damien@micropython.org>
2024-08-28 11:52:08 +10:00
Damien George
e8863e44e5 qemu-arm/Makefile: Make the build directory reflect the board.
So multiple boards can be built at once.

Signed-off-by: Damien George <damien@micropython.org>
2024-08-28 11:52:08 +10:00
Damien George
1090f1a60c shared/runtime/semihosting_arm: Add mp_semihosting_exit.
Signed-off-by: Damien George <damien@micropython.org>
2024-08-28 11:52:08 +10:00
Damien George
70a6791b09 shared/runtime/semihosting_arm: Add mp_semihosting_rx_chars.
Signed-off-by: Damien George <damien@micropython.org>
2024-08-28 11:52:08 +10:00
Damien George
9f9c283ef4 shared/runtime/semihosting_arm: Support semihosting on non-Thumb ARM.
Signed-off-by: Damien George <damien@micropython.org>
2024-08-28 11:52:08 +10:00
Damien George
c8838b5004 github/workflows: Add CI to run tests against zephyr with qemu.
With this change, the zephyr port is tested against the standard test suite
via the following scheme:
- the zephyr port is built with the `qemu_cortex_m3` board and the
  `prj_minimal.conf` configuration
- `qemu-system-arm` runs `zephyr.elf`
- the zephyr console is redirected to a pts/pty
- `tests/run-tests.py` is run in bare-metal mode against the pts/pty device

This allows testing the zephyr port as though it were a physical board
attached over a serial port.

Signed-off-by: Damien George <damien@micropython.org>
2024-08-28 11:23:11 +10:00
Damien George
9af333f2c6 zephyr: Increase CONFIG_CONSOLE_GETCHAR_BUFSIZE to 258.
It needs to be at least this big for `tools/pyboard.py` to work, which is
used (among other things) by `tests/run-tests.py`.

Signed-off-by: Damien George <damien@micropython.org>
2024-08-28 11:23:11 +10:00
Damien George
05cad7b56f zephyr: Remove obsolete tinytest test framework.
Commit f573e73bae rewored the zephyr port to
build MicroPython as a cmake target, and since that commit the
`make-bin-testsuite` helper script no longer works (it requires a Makefile)
and hence the tinytest test framework can no longer be run.

Instead of fixing this, remove the option to use tinytest.  Boards running
zephyr can use the standard `tests/run-tests.py` script to run tests in the
usual way.

Signed-off-by: Damien George <damien@micropython.org>
2024-08-28 11:23:11 +10:00
Damien George
86aa61918a tests/run-tests.py: Skip additional tests when slice unavailable.
Both of these tests require slice to be enabled.

Signed-off-by: Damien George <damien@micropython.org>
2024-08-28 11:23:11 +10:00
Damien George
b095c097e6 tools/pyboard.py: Capture stdout for pts line.
The pts line printed by qemu-system-arm goes to stdout, not stderr.

Redirect stderr to stdout in case other tools do print to stderr.

Signed-off-by: Damien George <damien@micropython.org>
2024-08-28 11:23:11 +10:00
stijn
a8d1c25a1b unix/coveragecpp: Include all API headers in the C++ code.
Make the CI builds compile the public API as C++ to catch accidental
introductions of incompatible code.

Signed-off-by: stijn <stijn@ignitron.net>
2024-08-26 14:11:40 +10:00
Jared Hancock
e901ff8557 extmod/network_wiznet5k: Add support for IPv6.
This adds support for the WIZNET5K nic to use IPv6 with the LWIP stack.
Additionally, if LWIP_IPV6 is disabled, the device is configured to drop
all IPv6 packets to reduce load on the MCU.

Signed-off-by: Jared Hancock <jared@greezybacon.me>
2024-08-26 13:02:44 +10:00
Angus Gratton
b82c9ca706 extmod/modtls_mbedtls: Optimise the DER certificate parsing fix.
Small code size and binary size optimisation for the fix merged in
4d6d84983f.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-08-26 12:48:12 +10:00
iabdalkader
706e09dff3 shared/tinyusb: Allow ports to define CDC TX/RX buffer sizes.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-08-26 12:42:09 +10:00
Rick Sorensen
260568e081 samd/mcu/samd21: Allow user to enable additional options.
Currently for samd21 some features are disable because of limited memory.
With the ability to trade firmware and filesystem space, a user may wish to
selectively enable some of these features.  This change allows them to be
enabled in board `mpconfigboard.h` or on the build command line for
example.  The selectively enable functions are: MICROPY_PY_FRAMEBUF,
MICROPY_PY_SELECT, MICROPY_PY_ONEWIRE and MICROPY_PY_ASYNCIO.

Signed-off-by: Rick Sorensen <rick.sorensen@gmail.com>
2024-08-26 12:32:37 +10:00
Christian Walther
0b7f6e1d3d py/mkrules.mk: Fix 'make submodules' when building out-of-tree.
When MicroPython is used as a submodule and built from the containing
project, e.g. for the embed port, `make submodules` fails because it goes
looking for the sub-sub-module paths in the outer repository instead of in
the micropython repository. Fix this by invoking git inside the micropython
submodule.

Signed-off-by: Christian Walther <cwalther@gmx.ch>
2024-08-26 12:30:24 +10:00
nspsck
6c3dc0c0b0 stm32/boards/STM32H7B3I_DK: Fix octo-spi pin configuration.
The original OSPIFLASH settings in the `mpconfigboard.h` contained some
mistakes that prevented the firmware from compiling.  These are now
corrected and the firmware can be built with support for OSPI flash.

Note: external storage in OSPI flash is not yet configured on this board.

Signed-off-by: nspsck <teng.jiang94@gmail.com>
2024-08-22 12:35:12 +10:00
nspsck
20a95b249a stm32/system_stm32: Allow selection of OSPI clock source.
Added a #if-block to `system_stm32.c` to check whether
`MICROPY_HW_RCC_OSPI_CLKSOURCE` is defined.  If that is the case, the
clock source for the OSPI will be changed to the specified source.

Signed-off-by: nspsck <teng.jiang94@gmail.com>
2024-08-22 12:29:09 +10:00