Thanks to visit codestin.com
Credit goes to github.com

Skip to content

zephyr: a few quality-of-life improvements, and additional board configurations #17552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

dpgeorge
Copy link
Member

Summary

The main aim here was to get mpremote mip install unittest working on the zephyr port, so it could run more of the test suite. And that lead to a lot of little changes.

Overall this PR aims to bring the zephyr port a bit closer to other ports in terms of functionality and usability:

  • execute boot.py and main.py like other ports
  • add /flash/lib to sys.path on start up if there's a filesystem (eg mpremote mip install now works)
  • enable sys.stdin/out/err
  • improve REPL reliability and performance, it now passes the test from tools/test_serial.py: Add test for serial throughput. #15909, and copying files with mpremote is now reliable
  • fix USB device_next driver compilation error
  • add Pin.OPEN_DRAIN support
  • allow constructing a Pin from an existing Pin (follows other ports)
  • implement C-level pin HAL
  • enable machine.SoftI2C
  • enable importing of .mpy files

It also tweaks/adds a few board configurations:

  • frdm_k64f: get ctrl-C working, enable PWM, increase heap size
  • nucleo_wb55rg: enable BLE, I2C, SPI and add filesystem
  • rpi_pico: use USB for REPL, enable I2C, SPI, add filesystem, increase heap size

In particular, the filesystem settings for rpi_pico now match the rp2 port RPI_PICO board, so you can switch between zephyr and rp2 firmware and retain the filesystem (and even .mpy files on that filesystem work across the two ports!). That allows some nice side-by-side comparisons between the zephyr and rp2 ports for the same hardware. Eg USB CDC throughput is quite a lot higher on the rp2 port using TinyUSB, compared with zephyr's USB device (but maybe this is due to zephyr configuration issues, I didn't investigate further).

Testing

Tested with frdm_k64f, nucleo_wb55rg and rpi_pico zephyr firmware:

Trade-offs and Alternatives

This increases the firmware size of zephyr builds a bit, but (1) these boards have enough flash and RAM; and (2) it's easy enough for custom boards to reconfigure/disable features if needed.

dpgeorge added 14 commits June 23, 2025 14:19
Changes here make the zephyr port act the same as other ports for the
start up and shut down sequence:
- `boot.py` is executed if it exists, and can force a soft reset
- `main.py` is only executed if in friendly REPL and if `boot.py` executed
  successfully; and it can also force a soft reset
- print "MPY: " before "soft reboot" on soft reset

Signed-off-by: Damien George <[email protected]>
If there is a filesystem available, this change makes sure there is a "lib"
in `sys.path`, eg so that "mip install" works correctly.

Signed-off-by: Damien George <[email protected]>
This change enables `sys.stdin`, `sys.stdout` and `sys.stderr` objects.
They are useful for general IO, and also help with testing zephyr boards.

Signed-off-by: Damien George <[email protected]>
There are two changes here:

1. Increase the UART input bufffer to 512 bytes.  That's necessary to get
   basic REPL reliability tests working, and helps improve `mpremote`
   usage, eg copying large files.

2. Remove `uart_sem` semaphore.  This is no longer needed because
   `zephyr_getchar()` should be fully non-blocking and have as low a
   latency as possible.  `mp_hal_stdin_rx_chr()` (which calls
   `zephyr_getchar`) already uses `MICROPY_EVENT_POLL_HOOK` to get
   an efficient wait, and doing an extra wait and check for the
   semaphore in `zephyr_getchar()` just introduces unnecessary latency and
   can lead to slower input, and potentially overflowing the UART input
   buffer.

Signed-off-by: Damien George <[email protected]>
The blocklist argument is no longer used (it seems it never was?).

Signed-off-by: Damien George <[email protected]>
Adding this constant is all that's needed to support open-drain pins.

Signed-off-by: Damien George <[email protected]>
This works now that the C-level pin HAL is implemented.

Signed-off-by: Damien George <[email protected]>
Support for importing .mpy files is quite fundamental to MicroPython these
days, eg it allows installing more efficient .mpy code via "mip install"
(and installing `unittest` only works with the .mpy version because the .py
version uses f-strings, which are not enabled on the zephyr port).  So
enable it generally for use by all boards.

As part of this, also enable:
- min/max: needed by `micropython/import_mpy_invalid.py`, and widely used
- sys.modules: needed by `run-tests.py` to run .mpy tests with --via-mpy
- io module: needed to run .mpy tests, and useful for `io.IOBase`
- array slice assign: needed to run .mpy tests, and generally useful as a
  way to do a memory copy.

Signed-off-by: Damien George <[email protected]>
Needed for some ARMv6M boards, eg rpi_pico.

Signed-off-by: Damien George <[email protected]>
Changes:
- Disable CONFIG_CONSOLE_SUBSYS and use UART directly, so that ctrl-C can
  break out of code.
- Enable CONFIG_PWM so that `machine.PWM()` works.
- Increase MicroPython GC heap size.

Signed-off-by: Damien George <[email protected]>
Bluetooth works well now on this board, so enable all supported features.

Also increase the MicroPython GC heap size to make use of the available
RAM.

Unfortunately the filesystem does not match the stm32 port's NUCLEO_WB55
configuration.  That's not possible to do because stm32 uses a 512 byte
flash erase size, while zephyr uses 4096 bytes.  But at least here in
zephyr there's now a sizable and usable filesystem.

Signed-off-by: Damien George <[email protected]>
Although the rpi_pico can already build and run with the zephyr port, this
configuration improves it in a number of ways:
- Use the USB CDC ACM as the REPL, rather than just a UART.
- Enable I2C and SPI, and add I2C1.
- Enable a filesystem, which matches exactly the rp2 port's RPI_PICO
  configuration.  So switching between zephyr and rp2 is possible and will
  retain the filesystem.
- Make the MicroPython GC heap make the most use of the available RAM.

Signed-off-by: Damien George <[email protected]>
dpgeorge added 2 commits June 23, 2025 14:49
Signed-off-by: Damien George <[email protected]>
@dpgeorge dpgeorge added this to the release-1.26.0 milestone Jun 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant