Repository navigation
ESP32-C6 Support - #67
AlexLanzano wants to merge 22 commits into
Conversation
- Replace the per-peripheral UART0/IOMUX helpers with a PeriphClk descriptor and EnablePeriphClk/DisablePeriphClk - Add UART0 and IOMUX gate macros to the platform header - Document the CPU clock helpers and enums
- Define whal_Esp32c6_Gpio_Dev unconditionally from WHAL_CFG_ESP32C6_GPIO_DEV and drop the passed-dev paths - Deinit is a no-op returning WHAL_SUCCESS - Use WHAL_ESP32C6_IOMUX_BASE for IO MUX writes
- SYSTIMER drives one comparator per instance in periodic or one-shot mode on a shared counter unit - UART functions return WHAL_ENOTSUP for now - Both support WHAL_CFG_ESP32C6_*_SINGLE_INSTANCE
- Rename board.h/board.c to wolfHAL_board.h/wolfHAL_board.c - Drop the board-local Makefile and main.c; build through examples/blinky and tests - Map GPIO directly, enable clocks through PeriphClk, and hook in the peripheral board.mk
- Polled 8N1 Send/Recv with timeouts and line error reporting - Add WHAL_ESP32C6_UART_CLKDIV for the baud divisor - Route UART0 to GPIO16/17 at 115200 and enable uart tests
…SYSTIMER tick - Add INTMTX/INTPRI driver that routes peripheral sources to CPU lines - Add SYSTIMER IrqHandler to clear the comparator interrupt - Drive g_tick from SYSTIMER on CPU line 1 and implement Board_WaitMs
- Install gcc-riscv64-unknown-elf for the ESP32-C6 jobs and skip the ARM toolchain - Set GCC_PREFIX to riscv64-unknown-elf- for the ESP32-C6 build
- Add esp32c6_xiao based on esp32c6_devkitc1, with the active-low user LED on GPIO15 and UART0 on D6/D7 (GPIO16/17) - Build it in the CI board matrix, using the RISC-V toolchain for all esp32c6 boards
… group watchdog drivers - Add RTC_WDT driver for the RTC watchdog with an Ext_DisableSwd helper for the super watchdog - Add TIMG watchdog driver for the per-timer-group MWDT - Disable the ROM-armed boot watchdogs at the start of Board_Init
- Add flash driver that erases, programs and reads the XIP flash through the SPI1 memory-SPI controller - Run flash commands from SRAM (.ramfunc) with interrupts disabled - Add memcpy/memset to ivt.c and enable flash tests on both boards
- Add generic ieee802154 device type with attribute, transmit, energy detect and frame pending table calls, and IrqHandler callbacks - Add dispatcher and generic radio tests - Document the driver contract in writing_a_driver.md
- Clear the HP_APM, LP_APM0 and LP_APM filters in Board_Init so bus masters other than the CPU, such as peripheral DMA, can reach memory
…802.15.4 radio driver - Add radio driver using Espressif's PHY and baseband libraries, with software CSMA-CA and retransmission - Add fetch_blobs.sh to download the libraries and ROM linker scripts - Add modem clock helpers, clock gating maps and eFuse MAC macros - Build the radio with RADIO=1 and pass LDLIBS to the link - End SRAM below the ROM data and place .iram1 in RAM - Drive the XIAO RF switch and select the ceramic antenna - Build both boards with the radio in CI
- Add ping-pong example that keeps the LED on while waiting for a ping - Add BOARD_LED_ON for the LED's active level
…river - Add UART driver for the USB Serial/JTAG controller's CDC-ACM port - Route XIAO serial output over USB and expose the port on DevKitC-1 - Give the port a short timeout so writes don't stall without a host
- Apply radio settings whenever the radio returns to idle - Report energy detection as the max of 8-symbol averages - Split EINVAL and ENOTSUP in the 802.15.4 dispatcher - Check Transmit arguments in the ESP32-C6 driver - Read GPIO_IN_REG for pins with the input buffer enabled - Add SYSTIMER, intc and 802.15.4 platform tests - Fix channel and TX power comments
Use whal_Reg32_* calls, uintptr_t bases and uint32_t Get outputs.
There was a problem hiding this comment.
🟡 Changes recommended
Incorrect GPIO matrix bit definitions, failure to disable output for input configuration, and UART initialization before its timeout clock starts can cause faulty pin behavior and startup hangs.
3 open issues
What changed in this PR
Adds ESP32-C6 support to wolfHAL, including Direct Boot support for the DevKitC-1 and XIAO boards, peripheral drivers, and an IEEE 802.15.4 radio interface.
Changes:
- Adds board startup, memory layouts, clock configuration, and peripheral integration.
- Introduces IEEE 802.15.4 support with radio-library fetching and a two-board ping example.
- Extends dispatch tests, hardware tests, documentation, and CI builds.
| File | Description |
|---|---|
wolfHAL/wolfHAL.h |
Exposes the IEEE 802.15.4 interface. |
wolfHAL/watchdog/esp32c6_timg_wdt.h |
Declares timer-group watchdog configuration and API. |
wolfHAL/watchdog/esp32c6_rtc_wdt.h |
Declares RTC and super-watchdog controls. |
wolfHAL/uart/esp32c6_usb_serial_jtag.h |
Declares USB serial transport support. |
wolfHAL/uart/esp32c6_uart.h |
Defines UART configuration and baud-rate helpers. |
wolfHAL/timer/esp32c6_systimer.h |
Declares system timer configuration and operations. |
wolfHAL/platform/esp/esp32c6.h |
Defines peripheral addresses, interrupts, and clock descriptors. |
wolfHAL/irq/esp32c6_intc.h |
Declares interrupt routing and priority controls. |
wolfHAL/ieee802154/esp32c6_ieee802154.h |
Declares the ESP32-C6 radio API. |
wolfHAL/gpio/esp32c6_gpio.h |
Defines pin and signal-routing configuration. |
wolfHAL/flash/esp32c6_flash.h |
Declares SPI flash operations and constraints. |
wolfHAL/clock/esp32c6_clock.h |
Adds CPU, peripheral, and modem clock controls. |
tools/esp32c6_radio/fetch_blobs.sh |
Fetches pinned radio libraries with checksum verification. |
tests/timer/test_esp32c6_timer.c |
Tests system timer configuration and lifecycle. |
tests/Makefile |
Supports additional link libraries. |
tests/main.c |
Registers IEEE 802.15.4 test suites. |
tests/irq/test_esp32c6_irq.c |
Tests interrupt routing and validation. |
tests/ieee802154/test_esp32c6_ieee802154.c |
Tests radio capabilities, tables, and configuration limits. |
tests/core/test_dispatch.c |
Adds radio dispatch and argument-validation tests. |
tests/core/Makefile |
Includes radio dispatch in host tests. |
src/watchdog/esp32c6_timg_wdt.c |
Implements timer-group watchdog control. |
src/watchdog/esp32c6_rtc_wdt.c |
Implements RTC and super-watchdog control. |
src/uart/esp32c6_usb_serial_jtag.c |
Implements polled USB serial transfers. |
src/irq/esp32c6_intc.c |
Implements interrupt routing, priorities, and masking. |
src/ieee802154/ieee802154.c |
Implements generic radio API dispatch. |
src/gpio/esp32c6_gpio.c |
Implements pin setup, routing, and digital I/O. |
src/flash/esp32c6_flash.c |
Implements RAM-resident SPI flash commands. |
examples/ieee802154_ping/Makefile |
Builds the radio ping example. |
examples/ieee802154_ping/main.c |
Demonstrates two-board radio communication. |
examples/blinky/Makefile |
Supports additional link libraries. |
docs/writing_a_driver.md |
Documents the radio driver contract. |
boards/README.md |
Lists both ESP32-C6 boards. |
boards/esp32c6_xiao/wolfHAL_board.h |
Defines XIAO devices, pins, and configuration. |
boards/esp32c6_xiao/wolfHAL_board.c |
Initializes XIAO peripherals and optional radio. |
boards/esp32c6_xiao/linker.ld |
Defines the XIAO Direct Boot memory layout. |
boards/esp32c6_xiao/ivt.c |
Adds XIAO startup and trap vectors. |
boards/esp32c6_xiao/board.mk |
Configures XIAO builds and flashing. |
boards/esp32c6_devkitc1/wolfHAL_board.h |
Defines DevKitC-1 devices, pins, and configuration. |
boards/esp32c6_devkitc1/wolfHAL_board.c |
Initializes DevKitC-1 peripherals and optional radio. |
boards/esp32c6_devkitc1/linker.ld |
Defines the DevKitC-1 Direct Boot memory layout. |
boards/esp32c6_devkitc1/ivt.c |
Adds DevKitC-1 startup and trap vectors. |
boards/esp32c6_devkitc1/board.mk |
Configures DevKitC-1 builds and flashing. |
.gitignore |
Excludes downloaded radio libraries. |
.github/workflows/boards.yml |
Adds ESP32-C6 toolchains and radio-enabled builds. |
Review effort: Balanced
| return err; | ||
| } | ||
|
|
||
| err = whal_Uart_Init(&g_whalUart); |
| if (pinCfg->outputEnable) { | ||
| whal_Reg32_Write(base, GPIO_ENABLE_W1TS_REG, 1UL << pinCfg->pin); | ||
| } |
| #define GPIO_FUNC_OUT_SEL_Msk (WHAL_BITMASK(9) << GPIO_FUNC_OUT_SEL_Pos) | ||
| #define GPIO_FUNC_OUT_INV_SEL_Pos 9 | ||
| #define GPIO_FUNC_OUT_INV_SEL_Msk (1UL << GPIO_FUNC_OUT_INV_SEL_Pos) | ||
| #define GPIO_FUNC_OEN_SEL_Pos 10 | ||
| #define GPIO_FUNC_OEN_SEL_Msk (1UL << GPIO_FUNC_OEN_SEL_Pos) | ||
| #define GPIO_FUNC_OEN_INV_SEL_Pos 11 | ||
| #define GPIO_FUNC_OEN_INV_SEL_Msk (1UL << GPIO_FUNC_OEN_INV_SEL_Pos) |
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #67
Scan targets checked: wolfhal-src, wolfhal-bugs
Not reviewed (no scan target covers them): .github/workflows/boards.yml, .gitignore, boards/README.md, boards/esp32c6_devkitc1/board.mk, boards/esp32c6_devkitc1/ivt.c, boards/esp32c6_devkitc1/linker.ld, boards/esp32c6_devkitc1/wolfHAL_board.c, boards/esp32c6_devkitc1/wolfHAL_board.h, boards/esp32c6_xiao/board.mk, boards/esp32c6_xiao/ivt.c, boards/esp32c6_xiao/linker.ld, boards/esp32c6_xiao/wolfHAL_board.c, boards/esp32c6_xiao/wolfHAL_board.h, docs/writing_a_driver.md, examples/blinky/Makefile, examples/ieee802154_ping/Makefile, examples/ieee802154_ping/main.c, tests/Makefile, tests/core/Makefile, tools/esp32c6_radio/fetch_blobs.sh
Coverage: 24 of 29 in-scope changed file(s) opened by the reviewer; not opened: tests/ieee802154/test_esp32c6_ieee802154.c, tests/irq/test_esp32c6_irq.c, wolfHAL/flash/esp32c6_flash.h, wolfHAL/ieee802154/esp32c6_ieee802154.h, wolfHAL/wolfHAL.h
Findings: 6
6 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
Review tier: Max
|
|
||
| /* GPIO_FUNCn_OUT_SEL_CFG_REG fields (Cfg.outputCfg values). */ | ||
| #define GPIO_FUNC_OUT_SEL_Pos 0 | ||
| #define GPIO_FUNC_OUT_SEL_Msk (WHAL_BITMASK(9) << GPIO_FUNC_OUT_SEL_Pos) |
There was a problem hiding this comment.
ESP32-C6 GPIO output-matrix field macros use the 9-bit ESP32/S3 layout · Copy-paste errors across MCU-family drivers
These macros use the ESP32/S3 layout, where OUT_SEL is 9 bits wide. On ESP32-C6 GPIO_FUNCn_OUT_SEL is bits [7:0]. As a result, GPIO_FUNC_OUT_INV_SEL_Msk sets OE_SEL, GPIO_FUNC_OEN_SEL_Msk inverts output-enable, and GPIO_FUNC_OEN_INV_SEL_Msk writes a reserved bit.
Suggested fix: Make GPIO_FUNC_OUT_SEL 8 bits wide and put OUT_INV_SEL, OEN_SEL and OEN_INV_SEL at bits 8, 9 and 10.
Basis: Espressif ESP32-C6 Technical Reference Manual, GPIO_FUNCn_OUT_SEL_CFG_REG: OUT_SEL [7:0], OUT_INV_SEL [8], OE_SEL [9], OE_INV_SEL [10], bits [31:11] reserved.
| do { | ||
| whal_Reg32_Write(base, SPI_MEM_CMD_REG, SPI_MEM_FLASH_RDSR_Msk); | ||
| while (whal_Reg32_Read(base, SPI_MEM_CMD_REG)); | ||
| } while (whal_Reg32_Read(base, SPI_MEM_RD_STATUS_REG) & FLASH_SR_WIP_Msk); |
There was a problem hiding this comment.
Flash RAM routines spin forever on SPI1 busy and WIP with interrupts masked · Unbounded wait loops on hardware flags
Esp32c6_Flash_RamProgram, Esp32c6_Flash_RamEraseSector and Esp32c6_Flash_RamRead wait on SPI_MEM_CMD_REG and the WIP status bit with no limit while mstatus.MIE is cleared. A flash that never clears WIP hangs the CPU for good, and Write/Erase can only return success.
Suggested fix: Give each poll loop an iteration limit and return WHAL_ETIMEOUT from Read, Write and Erase when the limit is reached.
Basis: Project convention: wolfHAL/error.h defines WHAL_ETIMEOUT, and whal_Reg32_ReadPoll returns it for hardware polls that expire.
Related known findings (similar but distinct; listed for context, not part of this finding)
| whal_Reg32_Write(base, SYSTIMER_TARGET_CONF_REG(cfg->comp), | ||
| whal_SetBits(SYSTIMER_TARGET_TIMER_UNIT_SEL_Msk, | ||
| SYSTIMER_TARGET_TIMER_UNIT_SEL_Pos, cfg->unit) | | ||
| whal_SetBits(SYSTIMER_TARGET_PERIOD_Msk, |
There was a problem hiding this comment.
SYSTIMER periodic Init silently truncates period to the 26-bit hardware field · Integer overflow / narrowing in length & address math
whal_Esp32c6_Systimer_Init masks cfg->period into the 26-bit TARGETx_PERIOD field with no range check and returns WHAL_SUCCESS. Periods of 2^26 ticks or more (about 4.2 s at 16 MHz) wrap silently: a 5 s period (80,000,000) becomes about 0.8 s.
Suggested fix: In periodic mode, return WHAL_EINVAL when cfg->period exceeds SYSTIMER_TARGET_PERIOD_Msk, in the same check that already validates unit/comp.
Basis: ESP32-C6 Technical Reference Manual, SYSTIMER_TARGETx_CONF_REG: SYSTIMER_TARGETx_PERIOD is a 26-bit field [25:0].
| * (at 40 MHz the lowest baud rate is 9766). | ||
| */ | ||
| #define WHAL_ESP32C6_UART_CLKDIV(baud, sclkHz) \ | ||
| ((uint32_t)(((((uint64_t)(sclkHz) * 16 + (baud) / 2) / (baud)) >> 4) & 0xFFF) | \ |
There was a problem hiding this comment.
UART CLKDIV macro silently wraps integer divisors above 12 bits, giving the wrong baud rate · Incorrect sizeof/type usage
WHAL_ESP32C6_UART_CLKDIV masks the integer divisor with & 0xFFF and never checks for overflow, so any baud rate below about 9.77 kbaud on a 40 MHz clock wraps silently. WHAL_ESP32C6_UART_CLKDIV(9600, 40000000) gives divisor 70.69, which is about 566 kbaud.
Suggested fix: Compute the divisor from baud and sclk in Init and return WHAL_EINVAL when its integer part exceeds 12 bits, instead of masking it in the macro.
Basis: ESP32-C6 Technical Reference Manual, UART_CLKDIV_SYNC_REG: UART_CLKDIV is a 12-bit integer field [11:0], with the fractional part in UART_CLKDIV_FRAG [23:20].
| { | ||
| uint64_t start = ReadCount(unit); | ||
|
|
||
| while (ReadCount(unit) - start < counts) {} |
There was a problem hiding this comment.
SpinCounts busy-waits on the SYSTIMER counter with no bound, so the HW test suite hangs instead of reporting a failure · Unbounded wait loops on hardware flags
SpinCounts polls the unit counter with no iteration cap. If whal_Timer_Stop halts the unit, or VALUE_VALID never latches, ReadCount keeps returning the same value and the whole suite hangs. The unit-enable assert at line 157 runs after the spin, so it can never report that regression.
Suggested fix: Cap the loop at a fixed iteration count, like the other polls in this file, and fail the test when the counter does not advance by counts.
Basis: Project convention in this file: ReadCount and TickAdvances bound their hardware polls with VALID_SPIN_MAX and TICK_SPIN_MAX so a hardware fault fails the test instead of hanging it.
| static whal_Error MockRadioDeinit(whal_Ieee802154 *d) { (void)d; return WHAL_SUCCESS; } | ||
| static whal_Error MockRadioTransmit(whal_Ieee802154 *d, const uint8_t *f, size_t len, const whal_Ieee802154_TxCfg *c) { (void)d; (void)f; (void)len; (void)c; return WHAL_SUCCESS; } | ||
|
|
||
| static const whal_Ieee802154Driver mockRadioDriver = { |
There was a problem hiding this comment.
Radio dispatch success path is tested for only 3 of the 15 new dispatchers · Weak or missing assertions
mockRadioDriver fills in only Init, Deinit and Transmit. The other 12 new dispatchers (GetCaps, SetAttr, GetAttr, GetRssi, Cca, EnergyDetect and the six PendingTable calls) are never called through a populated slot. A dispatcher that calls the wrong vtable slot or drops an argument would pass every host test.
Suggested fix: Add a mock for every whal_Ieee802154Driver slot, and in Test_Ieee802154_ValidDispatch call each dispatcher and check that its mock received the forwarded arguments.
Basis: Project convention: Test_Rng_ValidDispatch in the same file calls every Rng entry point through a fully populated mock driver.
Related known findings (similar but distinct; listed for context, not part of this finding)

No description provided.