Skip to content

clock_configure() will stop sysclock entirely if ROSC is not running #1589

@canique

Description

@canique

In https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/hardware_clocks/clocks.c the function clock_configure() contains this code snippet

// If switching a glitchless slice (ref or sys) to an aux source, switch
// away from aux *first* to avoid passing glitches when changing aux mux.
// Assume (!!!) glitchless source 0 is no faster than the aux source.
if (has_glitchless_mux(clk_index) && src == CLOCKS_CLK_SYS_CTRL_SRC_VALUE_CLKSRC_CLK_SYS_AUX) {
    hw_clear_bits(&clock->ctrl, CLOCKS_CLK_REF_CTRL_SRC_BITS);
    while (!(clock->selected & 1u))
        tight_loop_contents();
}

The bug is in:

hw_clear_bits(&clock->ctrl, CLOCKS_CLK_REF_CTRL_SRC_BITS);

If before running clock_configure(), ROSC has been disabled (by rosc_disable() or changing clocks_hw->wake_en0 bits respectively), then this line will switch the glitchless mux to ROSC. The result is a halted sysclock.

The line does not check whether ROSC is enabled at all or whether it would be better to use XOSC.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions