diff --git a/.github/actions/deps/ports/zephyr-cp/action.yml b/.github/actions/deps/ports/zephyr-cp/action.yml index 516499b0c8f..b39cc49e592 100644 --- a/.github/actions/deps/ports/zephyr-cp/action.yml +++ b/.github/actions/deps/ports/zephyr-cp/action.yml @@ -37,7 +37,7 @@ runs: with: app-path: zephyr-config base-path: ports/zephyr-cp - toolchains: arm-zephyr-eabi + toolchains: arm-zephyr-eabi:riscv64-zephyr-elf # The action's ccache stores a new ~150 MB entry per board job under one key # shared by every board, and each job restores whichever entry was saved last. # Measured across all 30 boards: hits on 5 boards by luck, none on the other 25, diff --git a/ports/zephyr-cp/boards/adafruit/metro_ch32v407_zephyr/autogen_board_info.toml b/ports/zephyr-cp/boards/adafruit/metro_ch32v407_zephyr/autogen_board_info.toml new file mode 100644 index 00000000000..8d1b5c0b752 --- /dev/null +++ b/ports/zephyr-cp/boards/adafruit/metro_ch32v407_zephyr/autogen_board_info.toml @@ -0,0 +1,143 @@ +# This file is autogenerated when a board is built. Do not edit. Do commit it to git. Other scripts use its info. +name = "Adafruit Industries LLC Metro CH32V407" + +[modules] +__future__ = true +_airlift = false +_bleio = false +_eve = false +_pew = false +_pixelmap = false +_stage = false +adafruit_bus_device = true +adafruit_pixelbuf = false +aesio = true +alarm = false +analogbufio = false +analogio = false +async_spi = true # Zephyr board has async_spi +atexit = true +audiobusio = false +audiocore = false +audiodelays = false +audiofilewriter = false +audiofilters = false +audiofreeverb = false +audioi2sin = false +audioio = false +audiomixer = false +audiomp3 = false +audiopwmio = false +audiospeed = false +audiotap = false +aurora_epaper = false +bitbangio = true +bitmapfilter = true # Zephyr board has busio +bitmaptools = true # Zephyr board has busio +bitops = false +board = true # Always enabled +busdisplay = true # Zephyr board has busio +busio = true # Zephyr board has busio +camera = false +canio = false +codeop = true +countio = false +cryptography = false +digitalio = true +displayio = true # Zephyr board has busio +dotclockframebuffer = false +dualbank = false +emmcio = false +epaperdisplay = true # Zephyr board has busio +floppyio = false +fontio = true # Zephyr board has busio +fourwire = true # Zephyr board has busio +framebufferio = true # Zephyr board has busio +frequencyio = false +getpass = true +gifio = true # Zephyr board has busio +gnss = false +hardwarekey = false +hashlib = true +hmac = false +hostnetwork = false +i2cdisplaybus = true # Zephyr board has busio +i2cioexpander = false +i2ctarget = false +imagecapture = false +ipaddress = false +is31fl3741 = false +jpegio = true # Zephyr board has busio +keypad = true +keypad_demux = true +locale = true +lvfontio = true # Zephyr board has busio +math = true +max3421e = false +mcp4822 = false +mdns = false +memorymap = false +memorymonitor = false +microcontroller = true +mii = false +mipicsi = false +mipidsi = false +msgpack = true +neopixel_write = false +nvm = true # Board has NVM partition +onewireio = false +os = true +paralleldisplaybus = false +picogame = false +ps2io = false +pulseio = false +pwmio = false +qrio = false +qspibus = false +rainbowio = true +random = true +rclcpy = false +rgbmatrix = false +rotaryio = true # Zephyr board has rotaryio +rtc = false +sdcardio = true # Zephyr board has busio +sdioio = false +sharpdisplay = true # Zephyr board has busio +socketpool = false +spitarget = false +ssl = false +storage = true # Zephyr board has flash +struct = true +supervisor = true +synthio = false +terminalio = true # Zephyr board has busio +tilepalettemapper = true # Zephyr board has busio +time = true +touchio = true +traceback = true +uheap = false +usb = false +usb_audio = false +usb_cdc = true +usb_hid = true +usb_host = false +usb_host_audio = false +usb_host_bulk = false +usb_midi = false +usb_video = false +ustack = false +vectorio = true # Zephyr board has busio +videocore = false +videogif = false +warnings = true +watchdog = true # Zephyr board has watchdog +wifi = false +zephyr_display = false +zephyr_kernel = false +zlib = true +# extmod modules shared with MicroPython +asyncio = true +binascii = true +json = true +re = true +select = true diff --git a/ports/zephyr-cp/boards/adafruit/metro_ch32v407_zephyr/board.conf b/ports/zephyr-cp/boards/adafruit/metro_ch32v407_zephyr/board.conf new file mode 100644 index 00000000000..2ed82902d9b --- /dev/null +++ b/ports/zephyr-cp/boards/adafruit/metro_ch32v407_zephyr/board.conf @@ -0,0 +1,6 @@ +# Nothing on this board uses settings, so leave settings and NVS off. +CONFIG_SETTINGS=n +CONFIG_NVS=n + +# REPL is on USB. No Zephyr UART console, so D0/D1 are free for busio.UART. +CONFIG_UART_CONSOLE=n diff --git a/ports/zephyr-cp/boards/adafruit/metro_ch32v407_zephyr/board.overlay b/ports/zephyr-cp/boards/adafruit/metro_ch32v407_zephyr/board.overlay new file mode 100644 index 00000000000..98d277751b2 --- /dev/null +++ b/ports/zephyr-cp/boards/adafruit/metro_ch32v407_zephyr/board.overlay @@ -0,0 +1,25 @@ +/* No Zephyr console by default, so D0/D1 (USART1) are free for busio.UART. A + * CONSOLE=1 build puts the console back on USART1 (console.overlay). */ +/ { + chosen { + /delete-property/ zephyr,console; + /delete-property/ zephyr,shell-uart; + }; + + // Named pins that are not on the Arduino header. + // Their names are in circuitpython.toml [connectors.metro_ch32v4x7_pins]. + metro_ch32v4x7_pins: metro-ch32v4x7-pins { + compatible = "adafruit-metro-ch32v4x7-pins"; + #gpio-cells = <2>; + gpio-map-mask = <0xffffffff 0xffffffc0>; + gpio-map-pass-thru = <0 0x3f>; + gpio-map = <0 0 &gpioa 5 0>, /* SCK */ + <1 0 &gpioa 7 0>, /* MOSI */ + <2 0 &gpioa 6 0>, /* MISO */ + <3 0 &gpioc 14 0>, /* NEOPIXEL */ + <4 0 &gpioc 15 0>, /* BUTTON */ + <5 0 &gpioa 10 0>; /* SD_CD */ + }; +}; + +#include "../../../app.overlay" diff --git a/ports/zephyr-cp/boards/adafruit/metro_ch32v407_zephyr/circuitpython.toml b/ports/zephyr-cp/boards/adafruit/metro_ch32v407_zephyr/circuitpython.toml new file mode 100644 index 00000000000..ebc7bd7b793 --- /dev/null +++ b/ports/zephyr-cp/boards/adafruit/metro_ch32v407_zephyr/circuitpython.toml @@ -0,0 +1,36 @@ +CIRCUITPY_BUILD_EXTENSIONS = ["uf2"] +USB_VID=0x239A +USB_PID=0x817E +NAME="Metro CH32V407" + +[connectors.arduino_header] +"0" = "A0" +"1" = "A1" +"2" = "A2" +"3" = "A3" +"4" = "A4" +"5" = "A5" +"6" = ["D0", "RX"] +"7" = ["D1", "TX"] +"8" = "D2" +"9" = "D3" +"10" = "D4" +"11" = "D5" +"12" = "D6" +"13" = "D7" +"14" = "D8" +"15" = "D9" +"16" = "D10" +"17" = "D11" +"18" = "D12" +"19" = ["D13", "LED"] +"20" = "SDA" +"21" = "SCL" + +[connectors.metro_ch32v4x7_pins] +"0" = "SCK" +"1" = "MOSI" +"2" = "MISO" +"3" = "NEOPIXEL" +"4" = "BUTTON" +"5" = "SD_CD" diff --git a/ports/zephyr-cp/boards/adafruit/metro_ch32v407_zephyr/console.overlay b/ports/zephyr-cp/boards/adafruit/metro_ch32v407_zephyr/console.overlay new file mode 100644 index 00000000000..2c4aab32afb --- /dev/null +++ b/ports/zephyr-cp/boards/adafruit/metro_ch32v407_zephyr/console.overlay @@ -0,0 +1,9 @@ +/* Applied after board.overlay in CONSOLE=1 and DEBUG=1 builds: the Zephyr + * console on USART1, on the D0/D1 pins. D0/D1 are then not available to + * busio.UART. */ +/ { + chosen { + zephyr,console = &usart1; + zephyr,shell-uart = &usart1; + }; +}; diff --git a/ports/zephyr-cp/boards/adafruit/metro_ch32v467_zephyr/autogen_board_info.toml b/ports/zephyr-cp/boards/adafruit/metro_ch32v467_zephyr/autogen_board_info.toml new file mode 100644 index 00000000000..b121d26f89f --- /dev/null +++ b/ports/zephyr-cp/boards/adafruit/metro_ch32v467_zephyr/autogen_board_info.toml @@ -0,0 +1,143 @@ +# This file is autogenerated when a board is built. Do not edit. Do commit it to git. Other scripts use its info. +name = "Adafruit Industries LLC Metro CH32V467" + +[modules] +__future__ = true +_airlift = false +_bleio = false +_eve = false +_pew = false +_pixelmap = false +_stage = false +adafruit_bus_device = true +adafruit_pixelbuf = false +aesio = true +alarm = false +analogbufio = false +analogio = false +async_spi = true # Zephyr board has async_spi +atexit = true +audiobusio = false +audiocore = false +audiodelays = false +audiofilewriter = false +audiofilters = false +audiofreeverb = false +audioi2sin = false +audioio = false +audiomixer = false +audiomp3 = false +audiopwmio = false +audiospeed = false +audiotap = false +aurora_epaper = false +bitbangio = true +bitmapfilter = true # Zephyr board has busio +bitmaptools = true # Zephyr board has busio +bitops = false +board = true # Always enabled +busdisplay = true # Zephyr board has busio +busio = true # Zephyr board has busio +camera = false +canio = false +codeop = true +countio = false +cryptography = false +digitalio = true +displayio = true # Zephyr board has busio +dotclockframebuffer = false +dualbank = false +emmcio = false +epaperdisplay = true # Zephyr board has busio +floppyio = false +fontio = true # Zephyr board has busio +fourwire = true # Zephyr board has busio +framebufferio = true # Zephyr board has busio +frequencyio = false +getpass = true +gifio = true # Zephyr board has busio +gnss = false +hardwarekey = false +hashlib = true +hmac = false +hostnetwork = false +i2cdisplaybus = true # Zephyr board has busio +i2cioexpander = false +i2ctarget = false +imagecapture = false +ipaddress = false +is31fl3741 = false +jpegio = true # Zephyr board has busio +keypad = true +keypad_demux = true +locale = true +lvfontio = true # Zephyr board has busio +math = true +max3421e = false +mcp4822 = false +mdns = false +memorymap = false +memorymonitor = false +microcontroller = true +mii = false +mipicsi = false +mipidsi = false +msgpack = true +neopixel_write = false +nvm = true # Board has NVM partition +onewireio = false +os = true +paralleldisplaybus = false +picogame = false +ps2io = false +pulseio = false +pwmio = false +qrio = false +qspibus = false +rainbowio = true +random = true +rclcpy = false +rgbmatrix = false +rotaryio = true # Zephyr board has rotaryio +rtc = false +sdcardio = true # Zephyr board has busio +sdioio = false +sharpdisplay = true # Zephyr board has busio +socketpool = false +spitarget = false +ssl = false +storage = true # Zephyr board has flash +struct = true +supervisor = true +synthio = false +terminalio = true # Zephyr board has busio +tilepalettemapper = true # Zephyr board has busio +time = true +touchio = true +traceback = true +uheap = false +usb = false +usb_audio = false +usb_cdc = true +usb_hid = true +usb_host = false +usb_host_audio = false +usb_host_bulk = false +usb_midi = false +usb_video = false +ustack = false +vectorio = true # Zephyr board has busio +videocore = false +videogif = false +warnings = true +watchdog = true # Zephyr board has watchdog +wifi = false +zephyr_display = false +zephyr_kernel = false +zlib = true +# extmod modules shared with MicroPython +asyncio = true +binascii = true +json = true +re = true +select = true diff --git a/ports/zephyr-cp/boards/adafruit/metro_ch32v467_zephyr/board.conf b/ports/zephyr-cp/boards/adafruit/metro_ch32v467_zephyr/board.conf new file mode 100644 index 00000000000..2ed82902d9b --- /dev/null +++ b/ports/zephyr-cp/boards/adafruit/metro_ch32v467_zephyr/board.conf @@ -0,0 +1,6 @@ +# Nothing on this board uses settings, so leave settings and NVS off. +CONFIG_SETTINGS=n +CONFIG_NVS=n + +# REPL is on USB. No Zephyr UART console, so D0/D1 are free for busio.UART. +CONFIG_UART_CONSOLE=n diff --git a/ports/zephyr-cp/boards/adafruit/metro_ch32v467_zephyr/board.overlay b/ports/zephyr-cp/boards/adafruit/metro_ch32v467_zephyr/board.overlay new file mode 100644 index 00000000000..98d277751b2 --- /dev/null +++ b/ports/zephyr-cp/boards/adafruit/metro_ch32v467_zephyr/board.overlay @@ -0,0 +1,25 @@ +/* No Zephyr console by default, so D0/D1 (USART1) are free for busio.UART. A + * CONSOLE=1 build puts the console back on USART1 (console.overlay). */ +/ { + chosen { + /delete-property/ zephyr,console; + /delete-property/ zephyr,shell-uart; + }; + + // Named pins that are not on the Arduino header. + // Their names are in circuitpython.toml [connectors.metro_ch32v4x7_pins]. + metro_ch32v4x7_pins: metro-ch32v4x7-pins { + compatible = "adafruit-metro-ch32v4x7-pins"; + #gpio-cells = <2>; + gpio-map-mask = <0xffffffff 0xffffffc0>; + gpio-map-pass-thru = <0 0x3f>; + gpio-map = <0 0 &gpioa 5 0>, /* SCK */ + <1 0 &gpioa 7 0>, /* MOSI */ + <2 0 &gpioa 6 0>, /* MISO */ + <3 0 &gpioc 14 0>, /* NEOPIXEL */ + <4 0 &gpioc 15 0>, /* BUTTON */ + <5 0 &gpioa 10 0>; /* SD_CD */ + }; +}; + +#include "../../../app.overlay" diff --git a/ports/zephyr-cp/boards/adafruit/metro_ch32v467_zephyr/circuitpython.toml b/ports/zephyr-cp/boards/adafruit/metro_ch32v467_zephyr/circuitpython.toml new file mode 100644 index 00000000000..3db237eec18 --- /dev/null +++ b/ports/zephyr-cp/boards/adafruit/metro_ch32v467_zephyr/circuitpython.toml @@ -0,0 +1,36 @@ +CIRCUITPY_BUILD_EXTENSIONS = ["uf2"] +USB_VID=0x239A +USB_PID=0x8180 +NAME="Metro CH32V467" + +[connectors.arduino_header] +"0" = "A0" +"1" = "A1" +"2" = "A2" +"3" = "A3" +"4" = "A4" +"5" = "A5" +"6" = ["D0", "RX"] +"7" = ["D1", "TX"] +"8" = "D2" +"9" = "D3" +"10" = "D4" +"11" = "D5" +"12" = "D6" +"13" = "D7" +"14" = "D8" +"15" = "D9" +"16" = "D10" +"17" = "D11" +"18" = "D12" +"19" = ["D13", "LED"] +"20" = "SDA" +"21" = "SCL" + +[connectors.metro_ch32v4x7_pins] +"0" = "SCK" +"1" = "MOSI" +"2" = "MISO" +"3" = "NEOPIXEL" +"4" = "BUTTON" +"5" = "SD_CD" diff --git a/ports/zephyr-cp/boards/adafruit/metro_ch32v467_zephyr/console.overlay b/ports/zephyr-cp/boards/adafruit/metro_ch32v467_zephyr/console.overlay new file mode 100644 index 00000000000..2c4aab32afb --- /dev/null +++ b/ports/zephyr-cp/boards/adafruit/metro_ch32v467_zephyr/console.overlay @@ -0,0 +1,9 @@ +/* Applied after board.overlay in CONSOLE=1 and DEBUG=1 builds: the Zephyr + * console on USART1, on the D0/D1 pins. D0/D1 are then not available to + * busio.UART. */ +/ { + chosen { + zephyr,console = &usart1; + zephyr,shell-uart = &usart1; + }; +}; diff --git a/ports/zephyr-cp/boards/board_aliases.cmake b/ports/zephyr-cp/boards/board_aliases.cmake index 71e2b3edbd7..893d7ec21e7 100644 --- a/ports/zephyr-cp/boards/board_aliases.cmake +++ b/ports/zephyr-cp/boards/board_aliases.cmake @@ -33,6 +33,8 @@ cp_board_alias(adafruit_feather_nrf52840_sense_zephyr adafruit_feather_nrf52840/ cp_board_alias(adafruit_feather_rp2040_zephyr adafruit_feather_rp2040/rp2040) cp_board_alias(adafruit_itsybitsy_nrf52840_zephyr adafruit_itsybitsy/nrf52840) cp_board_alias(adafruit_macropad_rp2040_zephyr adafruit_macropad_rp2040/rp2040) +cp_board_alias(adafruit_metro_ch32v407_zephyr adafruit_metro_ch32v407) +cp_board_alias(adafruit_metro_ch32v467_zephyr adafruit_metro_ch32v467) cp_board_alias(adafruit_metro_m7_zephyr adafruit_metro_m7) cp_board_alias(adafruit_metro_m7_airlift_zephyr adafruit_metro_m7_airlift) cp_board_alias(native_native_sim native_sim/native) diff --git a/ports/zephyr-cp/cptools/compat2driver.py b/ports/zephyr-cp/cptools/compat2driver.py index 8cd3c248265..186c70e77b9 100644 --- a/ports/zephyr-cp/cptools/compat2driver.py +++ b/ports/zephyr-cp/cptools/compat2driver.py @@ -1074,6 +1074,7 @@ "nxp_imx_src": "hwinfo", "nxp_imx_src_rev2": "hwinfo", "nxp_lpc_uid": "hwinfo", + "wch_esig": "hwinfo", # # hwspinlock "nxp_sema42": "hwspinlock", @@ -2874,6 +2875,7 @@ "st_stm32_otgfs": "usb/udc", "st_stm32_otghs": "usb/udc", "st_stm32_usb": "usb/udc", + "wch_usbhs2": "usb/udc", "zephyr_udc_skeleton": "usb/udc", "zephyr_udc_virtual": "usb/udc", # diff --git a/ports/zephyr-cp/dts/bindings/adafruit-metro-ch32v4x7-pins.yaml b/ports/zephyr-cp/dts/bindings/adafruit-metro-ch32v4x7-pins.yaml new file mode 100644 index 00000000000..018dcddae91 --- /dev/null +++ b/ports/zephyr-cp/dts/bindings/adafruit-metro-ch32v4x7-pins.yaml @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2026 Adafruit Industries +# SPDX-License-Identifier: MIT + +description: | + Named Adafruit Metro CH32V407/CH32V467 pins that are not on its Arduino + header: the 2x3 SPI header, the NeoPixel, the USER button and the microSD + card detect. + + The pin names come from the board's circuitpython.toml + [connectors.] table, keyed by gpio-map position. + +compatible: "adafruit-metro-ch32v4x7-pins" + +include: [gpio-nexus.yaml, base.yaml] diff --git a/ports/zephyr-cp/supervisor/flash.c b/ports/zephyr-cp/supervisor/flash.c index ad1158431db..9c43dcfd758 100644 --- a/ports/zephyr-cp/supervisor/flash.c +++ b/ports/zephyr-cp/supervisor/flash.c @@ -170,6 +170,8 @@ void supervisor_flash_init(void) { // printk("flash area %d %d\n", filesystem_area->fa_id, filesystem_area->fa_size); printk("hello from flash init\n"); bool covered_by_areas[circuitpy_flash_device_count]; + // fa_cb only sets entries to true, so start from all false. + memset(covered_by_areas, 0, sizeof(covered_by_areas)); flash_area_foreach(fa_cb, covered_by_areas); for (int i = 0; i < circuitpy_flash_device_count; i++) { const struct device *d = flashes[i]; diff --git a/ports/zephyr-cp/zephyr-config/west.yml b/ports/zephyr-cp/zephyr-config/west.yml index 1cc4fa5e9be..71d6bf8a055 100644 --- a/ports/zephyr-cp/zephyr-config/west.yml +++ b/ports/zephyr-cp/zephyr-config/west.yml @@ -10,16 +10,16 @@ manifest: path: modules/bsim_hw_models/nrf_hw_models - name: mcuboot url: https://github.com/adafruit/adaboot - revision: 25a68bc32f019976b7c1d0c30ac46c0ea035011e + revision: df45e384c3e1a99c391bbb72de424b02f6111988 path: bootloader/mcuboot - name: zephyr url: https://github.com/adafruit/zephyr - revision: 90cba5dc632d9b4691739e3de304d259dc77eb3f + revision: ab22ad4b118709cd02119d50b04fce4e3c37e50a clone-depth: 100 import: - # Skip what no CircuitPython board can use, so west update fetches 37 + # Skip what no CircuitPython board can use, so west update fetches 38 # projects instead of 80. Boards come from adafruit, nordic, nxp, - # raspberrypi, renesas, silabs and st; the Pico W's CYW43 is in hal_infineon. + # raspberrypi, renesas, silabs, st and wch; the Pico W's CYW43 is in hal_infineon. name-blocklist: # HALs of vendors without a board here - hal_adi @@ -40,7 +40,6 @@ manifest: - hal_tdk - hal_telink - hal_ti - - hal_wch - hal_wurthelektronik - hal_xtensa # libraries the port never enables