Skip to content

rp2/clocks_extra: Tidy up and re-sync.#19419

Open
Gadgetoid wants to merge 2 commits into
micropython:masterfrom
pimoroni:rp2-clocks-extra-sync-sdk230
Open

rp2/clocks_extra: Tidy up and re-sync.#19419
Gadgetoid wants to merge 2 commits into
micropython:masterfrom
pimoroni:rp2-clocks-extra-sync-sdk230

Conversation

@Gadgetoid

Copy link
Copy Markdown
Contributor

Note: based on SDK 2.3.0 bump commit, since this is a Pico SDK 2.3.0 bound tidyup.

Summary

Bring the port's runtime_init_clocks() in line with the pico-sdk 2.3.0 version, since it was originally derived from this function.

Testing

Verified the drop of 64bit for clocks_extra, which is useless because it's pulled in elsewhere, but is correct and matches upstream Pico SDK.

Verified the __weak SDK runtime_init_clocks is overriden by our version without the extra monkeying about. @projectgus original rationale for using linker wrap was to "avoid a code size increase" - see: 5dcffb5 - I don't think this still holds. Or ever did?? (in either case it's a small trampoline into the custom clocks init)

Trade-offs and Alternatives

Since this code was originally copied from the Pico SDK function, and says as much, I think it's prudent it be periodically updated to track it.

Nonetheless this is part change for change's sake and part a meaningful guard against future breakage. We flip to a more permissive HTSX check and drop the use of a deprecated macro (PLL_COMMON_REFDIV).

The swap from a __wrap to using the weak ref in particular is heavy-handed, but I'm in favour of not doing things that aren't necessary (keeps the huge CMakeLists.txt that little bit less huge), though it could be argued that the "explicit"ness of wrap is better than the implicit nature of overriding __weak symbols.

Regrettably we also lose a little history: // todo amy, what is this N1,2,4 meant to mean? 😆 (clue it's N = 1, 2 or 4)

Generative AI

I used generative AI tools when creating this PR, but a human has checked the
code and is responsible for the code and the description above.

Gadgetoid added 2 commits July 3, 2026 16:52
Required by the include-based linker script support that follows.

Signed-off-by: Phil Howard <github@gadgetoid.com>
Bring the port's runtime_init_clocks() in line with the pico-sdk
2.3.0 version, since it was originally derived from this function.

PLL_COMMON_REFDIV is deprecated in the SDK in favour of the separate
PLL_SYS_REFDIV and PLL_USB_REFDIV macros; use those so a board that
only sets the new per-PLL values is honoured, and so the port keeps
building if the deprecated macro is eventually removed.

Configure the divide-by-1 clocks (ref, sys, usb, adc, peri, hstx)
with clock_configure_undivided(), and clk_rtc with
clock_configure_int_divider(), as the SDK now does. Both avoid the
64-bit division that clock_configure() pulls in to compute a
fractional divider.

Drop the --wrap=runtime_init_clocks linker flag: the SDK declares
runtime_init_clocks() as __weak, so a plain strong definition in the
port overrides it, which makes the wrap redundant.

Also switch the HSTX guard to HAS_HSTX and take RTC_CLOCK_FREQ_HZ
from hardware/rtc.h, matching upstream. No functional change to the
clock configuration on existing boards.

Signed-off-by: Phil Howard <github@gadgetoid.com>
@Gadgetoid

Gadgetoid commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Note this change came off the back of investigating whether eliminating div64 by changing the clock functions would benefit anything. Sadly it's also used by:

machine_timer, mphalport, modtime, machine_pwm, machine_uart, rp2_dma, rp2_pio, modasyncio, modselect, vfs_lfs, mbedtls/bignum, pico_time/time.c, pico_util/datetime, pico_printf/printf, newlib_interface, mp_usbd_cdc.

So, no dice 😆 sadly because libgcc's __udivmoddi4 is 832b and hazard3 allegedly drags in ~3.3kb of 64bit mayhem. Yikes.

Edit, I have a strong suspicion that rp2: -740 -0.078% RPI_PICO_W[incl -424(bss)] is just the impact of the SDK 2.3.0 bump. The relevant change here should have no impact.

@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.51%. Comparing base (964803a) to head (2ced212).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #19419   +/-   ##
=======================================
  Coverage   98.51%   98.51%           
=======================================
  Files         177      177           
  Lines       22927    22927           
=======================================
  Hits        22586    22586           
  Misses        341      341           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Gadgetoid Gadgetoid changed the title rp2: Tidy up and re-sync clocks_extra.c rp2/clocks_extra: Tidy up and re-sync. Jul 3, 2026
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

Code size report:

Reference:  nrf: Restore interrupt-based I2C with nrfx v3. [964803a]
Comparison: rp2/clocks_extra: Sync clock init with pico-sdk 2.3.0. [merge of 2ced212]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
      esp32:    +0 +0.000% ESP32_GENERIC
     mimxrt:    +0 +0.000% TEENSY40
        rp2:  -740 -0.078% RPI_PICO_W[incl -424(bss)]
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant