Skip to content

nrf5x: fix hfclk_running() for nrfx v2.0.0#3766

Merged
HiFiPhile merged 1 commit into
hathach:masterfrom
mikeysklar:fix-nrfx-v2.0.0-hfclk
Jul 10, 2026
Merged

nrf5x: fix hfclk_running() for nrfx v2.0.0#3766
HiFiPhile merged 1 commit into
hathach:masterfrom
mikeysklar:fix-nrfx-v2.0.0-hfclk

Conversation

@mikeysklar

Copy link
Copy Markdown
Contributor

hfclk_running() doesn't compile against nrfx v2.0.0 (MDK 8.29.0):

dcd_nrf5x.c:847: implicit declaration of 'nrf_clock_is_running'
dcd_nrf5x.c:847: 'NRF_CLOCK_DOMAIN_HFCLK' undeclared
  • nrf_clock_is_running() was added in nrfx 2.1.0 (MDK 8.30.2)
  • autodetect (:53) puts MDK 8.29.0 in the v2 bucket, which calls it
  • CFG_TUD_NRF_NRFX_VERSION=1 doesn't help: v1's nrf_clock_hf_is_running() takes 1 arg, v2.0.0's takes 2

Fix: route v2 through nrf_clock_hf_is_running(), present in all of 2.x.

The other two v1-gated sites (nrf_clock_event_clear, nrf_clock_task_trigger) already use v2.0.0-compatible signatures — this is the only broken call.

Verified on nRF52840 (CircuitPython pins nrfx v2.0.0). Blocks adafruit/circuitpython#11093.

Note: I checked 2.0.0 and 2.1.0, not every 2.x in between. If you'd rather be exact, gate on MDK_VERSION < 83002 instead of the whole v2 tier.

@github-actions

Copy link
Copy Markdown

Hardware-in-the-loop (HIL) Test Report

hfp.json

✅ 52 passed · ❌ 0 failed · ⚪ 0 skipped · blank not run

Board cdc_dual_ports cdc_msc dfu cdc_msc_throughput audio_test_freertos dfu_runtime cdc_msc_freertos hid_boot_interface msc_dual_lun hid_generic_inout printer_to_cdc midi_test mtp
stm32l412nucleo ✅ CDC 628k/411k MSC 832k/749k
stm32f746disco ✅ CDC 13.7M/10.2M MSC 15.7M/28.7M
stm32f746disco-DMA ✅ CDC 15M/9.6M MSC 20.3M/30.2M
lpcxpresso43s67 ✅ CDC 12.7M/12.3M MSC 32.9M/35.4M

tinyusb.json

✅ 311 passed · ❌ 28 failed · ⚪ 11 skipped · blank not run

Board cdc_dual_ports cdc_msc dfu cdc_msc_throughput audio_test_freertos dfu_runtime cdc_msc_freertos hid_boot_interface msc_dual_lun hid_generic_inout printer_to_cdc midi_test mtp host_info_to_device_cdc cdc_msc_hid msc_file_explorer msc_file_explorer_freertos device_info hid_composite_freertos
ek_tm4c123gxl ✅ CDC 725k/673k MSC 804k/770k
espressif_p4_function_ev
espressif_p4_function_ev-DMA
espressif_s3_devkitm rd 409KB/s
espressif_s3_devkitm-DMA
feather_nrf52840_express ✅ CDC 534k/511k MSC 696k/467k
max32666fthr ✅ CDC 6.8M/12.7M MSC 7M/14.6M
metro_m4_express ✅ CDC 497k/554k MSC 540k/581k
mimxrt1015_evk ✅ CDC 7.2M/7M MSC 7M/6.6M
mimxrt1064_evk ✅ CDC 7.1M/7.9M MSC 7.2M/6.3M rd 1368KB/s rd 1365KB/s
lpcxpresso11u37 ✅ CDC 339k/347k MSC 668k/745k
ra4m1_ek ✅ CDC 819k/408k MSC 795k/777k
raspberry_pi_pico ✅ CDC 506k/566k MSC 561k/533k rd 62KB/s rd 62KB/s
raspberry_pi_pico_w rd 1106KB/s rd 1022KB/s
raspberry_pi_pico2 rd 1110KB/s rd 1022KB/s
adafruit_fruit_jam ✅ CDC 563k/565k MSC 580k/571k rd 62KB/s rd 62KB/s
stm32f072disco ✅ CDC 465k/338k MSC 592k/569k
stm32f407disco
stm32f723disco ✅ CDC 777k/807k MSC 867k/799k rd 13107KB/s rd 4032KB/s
stm32f723disco-DMA ✅ CDC 913k/868k MSC 940k/877k rd 15420KB/s rd 4032KB/s
stm32h743nucleo ✅ CDC 779k/769k MSC 829k/777k
stm32h743nucleo-DMA ✅ CDC 793k/810k MSC 819k/855k
stm32g0b1nucleo ✅ CDC 677k/428k MSC 781k/708k
stm32l476disco ✅ CDC 648k/575k MSC 720k/775k
stm32u083nucleo ✅ CDC 566k/446k MSC 792k/754k
nanoch32v203-fsdev ✅ CDC 508k/511k MSC 511k/511k
nanoch32v203-usbfs
ch32v103r_r1_1v0 ✅ CDC 146k/495k MSC 521k/523k
ch582m_evt ✅ CDC 231k/197k MSC 479k/481k

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected across 2404 targets. View Project Dashboard →

@mikeysklar

Copy link
Copy Markdown
Contributor Author

hil-tinyusb (tinyusb.json) is unrelated: 28 tests failed across 18 boards — 18 on stm32f407disco, rest on imxrt/esp32/rp2040/ch32. All 33 hil-build jobs pass, as does hil-tinyusb (hfp.json).

This adds only an #elif CFG_TUD_NRF_NRFX_VERSION == 2 branch. tinyusb pins nrfx at MDK 8.72.2 → autodetects to version 3, so the new code is compiled out everywhere here, feather_nrf52840_express included.

Which also means CI here doesn't exercise it. Verified by building CircuitPython's nRF52840 boards (nrfx v2.0.0), which don't compile without it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes hfclk_running() in the Nordic nrf5x device controller (dcd_nrf5x.c) to compile with nrfx v2.0.0 (MDK 8.29.0) by avoiding APIs that were only introduced in nrfx v2.1.0.

Changes:

  • Add an explicit CFG_TUD_NRF_NRFX_VERSION == 2 code path for hfclk_running().
  • Use nrf_clock_hf_is_running() for the v2 tier to maintain compatibility with nrfx 2.0.0.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/portable/nordic/nrf5x/dcd_nrf5x.c Outdated
nrf_clock_is_running() was added in nrfx 2.1.0 (MDK 8.30.2), but the
version autodetect puts 2.0.0 (MDK 8.29.0) in the v2 bucket, so
hfclk_running() fails to compile on that nrfx.

Route v2 through nrf_clock_hf_is_running(), which all of 2.x provides.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mikeysklar
mikeysklar force-pushed the fix-nrfx-v2.0.0-hfclk branch from e27b69c to 72e14c7 Compare July 10, 2026 13:17

@HiFiPhile HiFiPhile left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@HiFiPhile
HiFiPhile merged commit 5453ed0 into hathach:master Jul 10, 2026
226 of 256 checks passed
mikeysklar added a commit to mikeysklar/circuitpython that referenced this pull request Jul 10, 2026
fcd5a0603 -> 5453ed09f. Picks up hathach/tinyusb#3766, which adds an
nrfx v2.0.0 path to hfclk_running() in dcd_nrf5x.c; without it the nordic
port does not compile, since CircuitPython pins nrfx v2.0.0 (MDK 8.29.0)
and tinyusb's v2 path called nrf_clock_is_running(), added in nrfx 2.1.0.

Only other change in the range is a docs line in AGENTS.md.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@hathach

hathach commented Jul 11, 2026

Copy link
Copy Markdown
Owner

hil-tinyusb (tinyusb.json) is unrelated: 28 tests failed across 18 boards — 18 on stm32f407disco, rest on imxrt/esp32/rp2040/ch32. All 33 hil-build jobs pass, as does hil-tinyusb (hfp.json).

This adds only an #elif CFG_TUD_NRF_NRFX_VERSION == 2 branch. tinyusb pins nrfx at MDK 8.72.2 → autodetects to version 3, so the new code is compiled out everywhere here, feather_nrf52840_express included.

Which also means CI here doesn't exercise it. Verified by building CircuitPython's nRF52840 boards (nrfx v2.0.0), which don't compile without it.

I am re-org the hil pool, it will be a bit up and down with random failure for a while until my new pcie usb card + splitter arrived

@mikeysklar

Copy link
Copy Markdown
Contributor Author

@hathach - Thx for the confirmation. I figured all the HIL testing is newly added. Glad to see it getting implemented.

@hathach

hathach commented Jul 11, 2026

Copy link
Copy Markdown
Owner

@hathach - Thx for the confirmation. I figured all the HIL testing is newly added. Glad to see it getting implemented.

TinyUSB has been doing HIL for a couple of years, and go through a few hardware iteration (old pc, new usb card, new organizer/divider and mostly cable management). I would take a pix later when it looks more oragnized :). The pools increased one by one when I got more spare dev kits. There is several device and host tests already. But I tried to more upgrade to get more coverage since there is lots of LLM code nowsaday and they always sound very reasonable on reading, but could have side-effect and corrupt/cause more race. So it is best to verify with real hardware :).

PS: previously it ran as batch job, but I found that having the test result in comment make it easier to monitor/maintain. The downside is there is lots of bot reviewer and pr comments atm. I may try to make them less annoyning later.

@mikeysklar

Copy link
Copy Markdown
Contributor Author

That is really interesting. I'm curious to see how the current setup looks. I had thought this was Scott's ESP32-P4 PHIL board being implemented.

@hathach

hathach commented Jul 13, 2026

Copy link
Copy Markdown
Owner

it is nothing fancy, just an old dev PC with bunch of (unusded/available) dev boards. The cable management is a mess though. I used this breakout hub since type A head are too big and bulky plus it is 7-port hub, which reduce the number of hub level for larger pool. The complete list can be found in test/hil/tinyusb.json and hfp.json (separated rig from @HiFiPhile VM)

image

@mikeysklar

Copy link
Copy Markdown
Contributor Author

Thx. I see how this works.

I'm surprised you used a hub without uhubctl for hard power-cycle capability to each board.

@HiFiPhile

Copy link
Copy Markdown
Collaborator

I'm surprised you used a hub without uhubctl for hard power-cycle capability to each board.

uhubctl support too few hubs or they are too expensive. Apart from some J-Link OB glitch it's rare that a power cycle is needed.

My hub with soldered cables for space saving:
IMG_20260713_203445054

@hathach

hathach commented Jul 16, 2026

Copy link
Copy Markdown
Owner

my messy setup, there are currently 5 boxes, each has 2x7-hubs which have ~7 boards (each boards has its own flasher/debugger). each leaf hub is connected to 1 of 4 rootport of pcie renesas card (which is ppps). For board with host stack, there is a 4-port hub connected to the DUT with an msc + cdc (cp210x,ftdi,ch34x) with tx <-> rx for testing.

IMG_3992_1024 IMG_3991_1024

@mikeysklar

mikeysklar commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Oh, this is a cool rig. I understand now why the independent USB root ports are important with the PCIe setup you are using. As well as the hubs for storage / serial.

Inspired by your setup I started putting together my own mini HIL wall mount rig. See lightblue Skadis board in background. I'd like to verify PRs before pulling them out of draft to not waste anyones time. I'm using a mix of JTAG hardware (stlink, pico debug, jlink mini) on the major archs only RP2, nRF52840, M4, ESP32-S3.

I should be able to get PPPS control with this $50 RSHTECH 10-port with maybe a little scripting work around. I expect have something more interesting to show next week.

skadis-hil-jtag

@hathach

hathach commented Jul 16, 2026

Copy link
Copy Markdown
Owner

that is a nice hub, my ci rig is a VM with passthrough pcie usb card. The hil test abuse the usb bus enough It can hangs usb controller and have kernel into D-state several time a day. an pice card make it easier to unbind/rebind, or jsut reboot VM.

there is a test script https://github.com/hathach/tinyusb/blob/master/test/hil/hil_test.py which take config json typically https://github.com/hathach/tinyusb/blob/master/test/hil/tinyusb.json and flash all example binaries and do check of msc and its contents, cdc (echo) etc.. if you are interested.

@mikeysklar

Copy link
Copy Markdown
Contributor Author

Thanks the hil_test and json config are helpful reference. I put together my own per board probe pattern yesterday setting up OpenOCD. I'll see how far I get with uhubctl today. Waiting on more parts....

@hathach

hathach commented Jul 16, 2026

Copy link
Copy Markdown
Owner

feel free to @ me if you need any helps. I have struggled with this for some time :)

@mikeysklar

Copy link
Copy Markdown
Contributor Author

Thanks I appreciate the help. Honestly, since the moment I've hooked up the dedicated hardware I've been using it non-stop. Invaluable.

@HiFiPhile

Copy link
Copy Markdown
Collaborator

I think I'm gonna buy one of this during my summer holiday, a card with PLX switch + 4*uPD720201 controller:
image

@mikeysklar

Copy link
Copy Markdown
Contributor Author

Looks like a nice card and only ~$35 USD?

I asked Limor about writing a guide based on the wall mount Skadis HIL Farm I started scrapping together. It won't be as capable, but also can work with almost any Host OS setup.

skadis-hil-farm

@HiFiPhile

Copy link
Copy Markdown
Collaborator

Looks like a nice card and only ~$35 USD?

They have several variants, this one is about $60 on taobao. The max version has 32 ports 🤣

@hathach

hathach commented Jul 18, 2026

Copy link
Copy Markdown
Owner

nice card, but rather expensive though. I already go with the splitter and the cheaper uPD 4-port sibling (on order). Would consider this if found it earlier since this would sit nicely in the rig case. I guess I just have more boxes and put these card into one outside of the main rig. There is tons of boxes of boards anyway

PS: @mikeysklar is your 10-port hub a single hub with 10 ports or 7 + 4, or 3x4. If they are the later, you would want to put the debugger/probe on the leaf hub since they don't change.

image image

@mikeysklar

mikeysklar commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

I see uhubctl supports the Renesas uPD720202, but you have the uPD720201 (one version earlier) which is not listed.

The 10-port hub I'm using RSH-ST10C-6 is confirmed as 9 out of 10 ports working with uhubctl (by others). They are chained 4->4->4 so I'll need to do my own scripting to determine the virtual port to physical port mapping.

pt approved the Skadis HIL Farm guide so I'm printing out mounting hardware. More to come. What is the best way to reach you? I don't see you on discord or have your adafruit e-mail.

@HiFiPhile

Copy link
Copy Markdown
Collaborator

Seems my HIL VM with FL1100 card is glitchy

[874407.500599] {9}[Hardware Error]: Hardware error from APEI Generic Hardware Error Source: 514
[874407.501118] {9}[Hardware Error]: It has been corrected by h/w and requires no further action
[874407.501555] {9}[Hardware Error]: event severity: corrected
[874407.501991] {9}[Hardware Error]:  Error 0, type: corrected
[874407.502425] {9}[Hardware Error]:   section_type: PCIe error
[874407.502858] {9}[Hardware Error]:   port_type: 0, PCIe end point
[874407.503285] {9}[Hardware Error]:   version: 0.2
[874407.503706] {9}[Hardware Error]:   command: 0x0400, status: 0x0010
[874407.504127] {9}[Hardware Error]:   device_id: 0000:c1:00.0
[874407.504548] {9}[Hardware Error]:   slot: 0
[874407.504965] {9}[Hardware Error]:   secondary_bus: 0x00
[874407.505384] {9}[Hardware Error]:   vendor_id: 0x1b73, device_id: 0x1100
[874407.505807] {9}[Hardware Error]:   class_code: 0c0330
[874407.506227] {9}[Hardware Error]:   bridge: secondary_status: 0x0000, control: 0x0000
[874407.506654] {9}[Hardware Error]:   aer_cor_status: 0x00002000, aer_cor_mask: 0x00000000
[874407.507086] {9}[Hardware Error]:   aer_uncor_status: 0x00100000, aer_uncor_mask: 0x00100000
[874407.507522] {9}[Hardware Error]:   aer_uncor_severity: 0x000f6030
[874407.507956] {9}[Hardware Error]:   TLP Header: 00000000 00000000 00000000 00000000
[874407.508391] {9}[Hardware Error]:  Error 1, type: corrected
[874407.508821] {9}[Hardware Error]:   section_type: PCIe error
[874407.509245] {9}[Hardware Error]:   port_type: 0, PCIe end point
[874407.509667] {9}[Hardware Error]:   version: 0.2
[874407.510085] {9}[Hardware Error]:   command: 0x0400, status: 0x0010
[874407.510505] {9}[Hardware Error]:   device_id: 0000:c1:00.0
[874407.510919] {9}[Hardware Error]:   slot: 0
[874407.511327] {9}[Hardware Error]:   secondary_bus: 0x00
[874407.511734] {9}[Hardware Error]:   vendor_id: 0x1b73, device_id: 0x1100
[874407.512138] {9}[Hardware Error]:   class_code: 0c0330
[874407.512539] {9}[Hardware Error]:   bridge: secondary_status: 0x0000, control: 0x0000
[874407.512944] {9}[Hardware Error]:   aer_cor_status: 0x00002000, aer_cor_mask: 0x00000000
[874407.513352] {9}[Hardware Error]:   aer_uncor_status: 0x00100000, aer_uncor_mask: 0x00100000
[874407.513766] {9}[Hardware Error]:   aer_uncor_severity: 0x000f6030
[874407.514177] {9}[Hardware Error]:   TLP Header: 00000000 00000000 00000000 00000000
[874407.523138] vfio-pci 0000:c1:00.0: aer_status: 0x00002000, aer_mask: 0x00000000
[874407.523563] vfio-pci 0000:c1:00.0:    [13] NonFatalErr
[874407.524022] vfio-pci 0000:c1:00.0: aer_layer=Transaction Layer, aer_agent=Receiver ID
[874407.524491] vfio-pci 0000:c1:00.0: aer_status: 0x00002000, aer_mask: 0x00000000
[874407.524930] vfio-pci 0000:c1:00.0:    [13] NonFatalErr
[874407.525358] vfio-pci 0000:c1:00.0: aer_layer=Transaction Layer, aer_agent=Receiver ID

@hathach

hathach commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Seems my HIL VM with FL1100 card is glitchy

yeah, the new usbtest/testusb https://docs.tinyusb.org/en/latest/examples/device/usbtest.html is a really stresstest on both firmware and controller. It is kernel level test, kernel will spam controller with tons lots of URBs then cancel mid-flight, stall mid-flight, send random control etc... I throw away 4 x moschip card since it failed 2 of the tests due to silicon issue with frame index. Moschip is pure EHCI, I was trying to to get pass 32 device per xHCI renesas card. For renesas card, it needs to use latest firmware else It will also got "HC dead" https://github.com/hathach/tinyusb/blob/master/test/hil/hil_test.py#L171. FL1100 does not seems to have loadable firmware (ROM only) to fix any silicon issue. Have you tried to unplug the jlink on the lpc43, only that got the issue. The hil run does 30/30 on all board in initial test.

Due to command spamming from kernel, Renesas card can only carry 4 (USBTEST_PARALLEL) usbtest concurrently else its command buffer will overflow and got wedged as well. Maybe FL1100 have a shorter buffer, we can test with USBTEST_PARALLEL=1.

PS: @HiFiPhile now I also want to buy your card as well, that is all-in-one 360 cny card with pcie switch + 4 cards and only 1 power cable is super nice. I wish I know this sooner. Probalby just stack the on-order spliter + card in a drawer 🤣

I see uhubctl supports the Renesas uPD720202, but you have the uPD720201 (one version earlier) which is not listed.

uPD720201/2 are the same controller, 01 has 4 root port, 02 only has 2. Same 5 Gb up link. 01 is used when you want max speed on every ports.

The 10-port hub I'm using RSH-ST10C-6 is confirmed as 9 out of 10 ports working with uhubctl (by others). They are chained 4->4->4 so I'll need to do my own scripting to determine the virtual port to physical port mapping.

all ppps is super nice, easier to have per-board recovery 👍

pt approved the Skadis HIL Farm guide so I'm printing out mounting hardware. More to come. What is the best way to reach you? I don't see you on discord or have your adafruit e-mail.

I have a discord but not use that much, I think I register with personal emmail. Let me try to change that, you can reach me with thach@adafruit.com or thach@tinyusb.org

@HiFiPhile

Copy link
Copy Markdown
Collaborator

Yesterday I've soldered another Ch334x hub to separate target and flasher ports, the result is not good at all, even on manual run without usbtest it fails randomly. It seems something is off, I've a uPD720201 in my PC, will try to swap in to see if it helps.

@hathach

hathach commented Jul 20, 2026

Copy link
Copy Markdown
Owner

You may want to use the latest firmware for renesas card. Let me try to replicate my driver setting on your rig

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants