Skip to content

Commit 3887880

Browse files
committed
fix up again to support max dividers
1 parent d3420a7 commit 3887880

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/rp2_common/hardware_clocks/clocks.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,22 @@ bool clock_configure(clock_handle_t clock, uint32_t src, uint32_t auxsrc, uint32
101101
if (freq > src_freq)
102102
return false;
103103

104-
uint32_t div = (uint32_t)((((uint64_t) src_freq) << CLOCKS_CLK_GPOUT0_DIV_INT_LSB) / freq);
104+
uint64_t div64 =((((uint64_t) src_freq) << CLOCKS_CLK_GPOUT0_DIV_INT_LSB) / freq);
105+
uint32_t div, actual_freq;
106+
if (div64 >> 32) {
107+
// set div to 0 for maximum clock divider
108+
div = 0;
109+
actual_freq = src_freq >> (32 - CLOCKS_CLK_GPOUT0_DIV_INT_LSB);
110+
} else {
111+
div = div64;
105112
#if PICO_RP2040
106-
// on RP2040 only clock divider of 1, or >= 2 are supported
107-
if (div < (2u << CLOCKS_CLK_GPOUT0_DIV_INT_LSB)) {
108-
div = (1u << CLOCKS_CLK_GPOUT0_DIV_INT_LSB);
109-
}
113+
// on RP2040 only clock divider of 1, or >= 2 are supported
114+
if (div < (2u << CLOCKS_CLK_GPOUT0_DIV_INT_LSB)) {
115+
div = (1u << CLOCKS_CLK_GPOUT0_DIV_INT_LSB);
116+
}
110117
#endif
111-
uint32_t actual_freq = (uint32_t) ((((uint64_t) src_freq) << CLOCKS_CLK_GPOUT0_DIV_INT_LSB) / div);
118+
actual_freq = (uint32_t) ((((uint64_t) src_freq) << CLOCKS_CLK_GPOUT0_DIV_INT_LSB) / div);
119+
}
112120

113121
clock_configure_internal(clock, src, auxsrc, actual_freq, div);
114122
// Store the configured frequency

src/rp2_common/hardware_clocks/include/hardware/clocks.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,11 @@ typedef clock_num_t clock_handle_t;
270270
* achievable, with the maximum being the src_freq.
271271
*
272272
* \if rp2350_specific
273-
* Note: That the RP2350 clock hardware supports divisors from 1.0->65535.0 in steps of 1/65536
273+
* Note: The RP2350 clock hardware supports divisors from 1.0->65536.0 in steps of 1/65536
274274
*
275275
* \endif
276276
* \if rp2030_specific
277-
* Note: That the RP2040 clock hardware only support divisors of exactly 1.0 or 2.0->65535.0 in steps of 1/256
277+
* Note: The RP2040 clock hardware only supports divisors of exactly 1.0 or 2.0->16777216.0 in steps of 1/256
278278
* \endif
279279
*
280280
* See the tables in the description for details on the possible values for clock sources.

0 commit comments

Comments
 (0)