Skip to content

Commit 4a9584b

Browse files
committed
Review fixup
Fixup for dividers 1.0-2.0 on RP2040 Improve docs
1 parent 6728e7e commit 4a9584b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/rp2_common/hardware_clocks/clocks.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ bool clock_configure_mhz(clock_handle_t clock, uint32_t src, uint32_t auxsrc, ui
130130
return false;
131131

132132
uint32_t div = (uint32_t)((((uint32_t) src_freq_mhz) << CLOCKS_CLK_GPOUT0_DIV_INT_LSB) / freq_mhz);
133+
#if PICO_RP2040
134+
// on RP2040 only clock divider of 1, or >= 2 are supported
135+
if (div < (2u << CLOCKS_CLK_GPOUT0_DIV_INT_LSB)) {
136+
div = (1u << CLOCKS_CLK_GPOUT0_DIV_INT_LSB);
137+
}
138+
#endif
133139
uint32_t actual_freq = (uint32_t) ((((uint32_t) src_freq_mhz) << CLOCKS_CLK_GPOUT0_DIV_INT_LSB) / div) * MHZ;
134140

135141
clock_configure_internal(clock, src, auxsrc, actual_freq, div);

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,17 @@ bool clock_configure(clock_handle_t clock, uint32_t src, uint32_t auxsrc, uint32
322322
* \ingroup hardware_clocks
323323
*
324324
* This function differs from clock_configure in that it does not configure the clocks as accurately,
325-
* but therefore doesn't need to bring in 64-bit division functions, reducing the code size.
325+
* but therefore doesn't need to bring in 64-bit division functions, reducing the code size if 64-bit
326+
* division is not otherwise used by the application.
326327
*
328+
* \if rp2350_specific
329+
* Note: The RP2350 clock hardware supports divisors from 1.0->65536.0 in steps of 1/65536
330+
*
331+
* \endif
332+
* \if rp2040_specific
333+
* Note: The RP2040 clock hardware only supports divisors of exactly 1.0 or 2.0->16777216.0 in steps of 1/256
334+
* \endif
335+
*
327336
* See the tables in the description for details on the possible values for clock sources.
328337
*
329338
* \param clock The clock to configure

0 commit comments

Comments
 (0)