hardware_xosc: Hardcoded frequency range in xosc_init() prevents using >15MHz crystals on RP2350 without modifying the SDK #3074

Closed
opened 2026-07-15 06:36:53 -05:00 by Vesek · 3 comments
Vesek commented 2026-07-15 06:36:53 -05:00 (Migrated from github.com)

When trying to configure pico-sdk to use a 32MHz crystal as the clock source for XOSC I found that xosc_init() in xosc.c hardcodes the XOSC CTRL register to XOSC_CTRL_FREQ_RANGE_VALUE_1_15MHZ. This cannot be overridden without modifying the SDK code.

It would be incredibly helpful if the frequency range in xosc_init() could be made configurable via a preprocessor definition, similar to other clock configurations in the SDK.

For example, introducing a define like:

#ifndef PICO_XOSC_FREQ_RANGE
#define PICO_XOSC_FREQ_RANGE XOSC_CTRL_FREQ_RANGE_VALUE_1_15MHZ
#endif

so developers can override this behavior in their board.h files.

When trying to configure pico-sdk to use a 32MHz crystal as the clock source for XOSC I found that `xosc_init()` in [xosc.c](https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/hardware_xosc/xosc.c#L29-L43) hardcodes the XOSC CTRL register to XOSC_CTRL_FREQ_RANGE_VALUE_1_15MHZ. This cannot be overridden without modifying the SDK code. It would be incredibly helpful if the frequency range in `xosc_init()` could be made configurable via a preprocessor definition, similar to other clock configurations in the SDK. For example, introducing a define like: ```c #ifndef PICO_XOSC_FREQ_RANGE #define PICO_XOSC_FREQ_RANGE XOSC_CTRL_FREQ_RANGE_VALUE_1_15MHZ #endif ``` so developers can override this behavior in their board.h files.
lurch commented 2026-07-15 10:10:42 -05:00 (Migrated from github.com)

As an aside, it looks like the // Assumes 1-15 MHz input, checked above. comment inside xosc_init() is also wrong! Seems like github.com/raspberrypi/pico-sdk@da476610e2 changed the "check above" from #if XOSC_MHZ < 1 || XOSC_MHZ > 15 to #if XOSC_MHZ < 1 || XOSC_MHZ > 50, but then forgot to update the comment inside xosc_init() to match.

RP2040 could only use crystals up to 15MHz, which is likely why this XOSC_CTRL_FREQ_RANGE_VALUE_1_15MHZ value was originally hardcoded, but then RP2350 upped the maximum crystal frequency to 50MHz.

As an aside, it looks like the `// Assumes 1-15 MHz input, checked above.` comment inside `xosc_init()` is also wrong! Seems like https://github.com/raspberrypi/pico-sdk/commit/da476610e2c534999ba2cd4e8e33591ff962de23 changed the "check above" from `#if XOSC_MHZ < 1 || XOSC_MHZ > 15` to `#if XOSC_MHZ < 1 || XOSC_MHZ > 50`, but then forgot to update the comment inside `xosc_init()` to match. RP2040 could only use crystals up to 15MHz, which is likely why this `XOSC_CTRL_FREQ_RANGE_VALUE_1_15MHZ` value was originally hardcoded, but then RP2350 upped the maximum crystal frequency to 50MHz.
will-v-pi commented 2026-08-21 04:57:59 -05:00 (Migrated from github.com)

I've PR'd #3152 to automatically configure it based on XOSC_HZ, does that work for your use case too? That PR also adds the ability to override the range if you don't want it configured based on XOSC_HZ.

I've PR'd #3152 to automatically configure it based on `XOSC_HZ`, does that work for your use case too? That PR also adds the ability to override the range if you don't want it configured based on `XOSC_HZ`.
kilograham commented 2026-08-21 16:04:44 -05:00 (Migrated from github.com)

fix merged into develop

fix merged into develop
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-raspberrypi/pico-sdk#3074
No description provided.