Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/rp2_common/hardware_clocks/clocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ bool clock_configure(clock_handle_t clock, uint32_t src, uint32_t auxsrc, uint32
return false;

uint32_t div = (uint32_t)((((uint64_t) src_freq) << CLOCKS_CLK_GPOUT0_DIV_INT_LSB) / freq);
// only clock divider of 1, or >= 2 are supported
#if PICO_RP2040
// on RP2040 only clock divider of 1, or >= 2 are supported
if (div < (2u << CLOCKS_CLK_GPOUT0_DIV_INT_LSB)) {
div = (1u << CLOCKS_CLK_GPOUT0_DIV_INT_LSB);
}
#endif
uint32_t actual_freq = (uint32_t) ((((uint64_t) src_freq) << CLOCKS_CLK_GPOUT0_DIV_INT_LSB) / div);

clock_configure_internal(clock, src, auxsrc, actual_freq, div);
Expand Down
10 changes: 8 additions & 2 deletions src/rp2_common/hardware_clocks/include/hardware/clocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,22 @@ typedef clock_num_t clock_handle_t;
* frequency to be specified, and will set the clock divider to achieve the exact or higher frequency
* achievable, with the maximum being the src_freq.
*
* Note: That the clock hardware only support divisors of exactly 1 or 2.0->65535.0
* \if rp2350_specific
* Note: That the RP2350 clock hardware supports divisors from 1.0->65535.0 in steps of 1/65536
*
* See the tables in the description for details on the possible values for clock sources.
* \endif
* \if rp2030_specific
* Note: That the RP2040 clock hardware only support divisors of exactly 1.0 or 2.0->65535.0 in steps of 1/256
* \endif
*
* See the tables in the description for details on the possible values for clock sources.
*
* \param clock The clock to configure
* \param src The main clock source, can be 0.
* \param auxsrc The auxiliary clock source, which depends on which clock is being set. Can be 0
* \param src_freq Frequency of the input clock source
* \param freq Requested frequency
* \return true if the clock is updated, false if freq > src_freq
*/
bool clock_configure(clock_handle_t clock, uint32_t src, uint32_t auxsrc, uint32_t src_freq, uint32_t freq);

Expand Down
Loading