Skip to content

Commit e62cd02

Browse files
Powman fix (#2499)
* Fix powman_timer_use_gpio Fixes #2471 * Fix docs for clock_gpio_init etc for RP2350 You can also use gpios 13 and 15 on RP2350 * macro-ify the mapping from GPI to ext_time_ref_source - note i kept this private for now, as it's a bit murky --------- Co-authored-by: graham sanderson <[email protected]>
1 parent c1981f5 commit e62cd02

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

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

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,18 @@ void clocks_enable_resus(resus_callback_t resus_callback);
399399
/*! \brief Output an optionally divided clock to the specified gpio pin.
400400
* \ingroup hardware_clocks
401401
*
402-
* \param gpio The GPIO pin to output the clock to. Valid GPIOs are: 21, 23, 24, 25. These GPIOs are connected to the GPOUT0-3 clock generators.
402+
* \if rp2040_specific
403+
* On RP2040 valid GPIOs are 21, 23, 24, 25.
404+
* These GPIOs are connected to the GPOUT0-3 clock generators.
405+
* \endif
406+
* \if rp2350_specific
407+
* On RP2350 valid GPIOs are 13, 15, 21, 23, 24, 25.
408+
* GPIOs 13 and 21 are connected to the GPOUT0 clock generator.
409+
* GPIOs 15 and 23 are connected to the GPOUT1 clock generator.
410+
* GPIOs 24 and 25 are connected to the GPOUT2-3 clock generators.
411+
* \endif
412+
*
413+
* \param gpio The GPIO pin to output the clock to.
403414
* \param src The source clock. See the register field CLOCKS_CLK_GPOUT0_CTRL_AUXSRC for a full list. The list is the same for each GPOUT clock generator.
404415
* \param div_int The integer part of the value to divide the source clock by. This is useful to not overwhelm the GPIO pin with a fast clock. This is in range of 1..2^24-1 on RP2040
405416
* and 1..2^16-1 on RP2350
@@ -410,7 +421,18 @@ void clock_gpio_init_int_frac16(uint gpio, uint src, uint32_t div_int, uint16_t
410421
/*! \brief Output an optionally divided clock to the specified gpio pin.
411422
* \ingroup hardware_clocks
412423
*
413-
* \param gpio The GPIO pin to output the clock to. Valid GPIOs are: 21, 23, 24, 25. These GPIOs are connected to the GPOUT0-3 clock generators.
424+
* * \if rp2040_specific
425+
* On RP2040 valid GPIOs are 21, 23, 24, 25.
426+
* These GPIOs are connected to the GPOUT0-3 clock generators.
427+
* \endif
428+
* \if rp2350_specific
429+
* On RP2350 valid GPIOs are 13, 15, 21, 23, 24, 25.
430+
* GPIOs 13 and 21 are connected to the GPOUT0 clock generator.
431+
* GPIOs 15 and 23 are connected to the GPOUT1 clock generator.
432+
* GPIOs 24 and 25 are connected to the GPOUT2-3 clock generators.
433+
* \endif
434+
*
435+
* \param gpio The GPIO pin to output the clock to.
414436
* \param src The source clock. See the register field CLOCKS_CLK_GPOUT0_CTRL_AUXSRC for a full list. The list is the same for each GPOUT clock generator.
415437
* \param div_int The integer part of the value to divide the source clock by. This is useful to not overwhelm the GPIO pin with a fast clock. This is in range of 1..2^24-1 on RP2040
416438
* and 1..2^16-1 on RP2350
@@ -428,7 +450,18 @@ static inline void clock_gpio_init_int_frac(uint gpio, uint src, uint32_t div_in
428450
/*! \brief Output an optionally divided clock to the specified gpio pin.
429451
* \ingroup hardware_clocks
430452
*
431-
* \param gpio The GPIO pin to output the clock to. Valid GPIOs are: 21, 23, 24, 25. These GPIOs are connected to the GPOUT0-3 clock generators.
453+
* \if rp2040_specific
454+
* On RP2040 valid GPIOs are 21, 23, 24, 25.
455+
* These GPIOs are connected to the GPOUT0-3 clock generators.
456+
* \endif
457+
* \if rp2350_specific
458+
* On RP2350 valid GPIOs are 13, 15, 21, 23, 24, 25.
459+
* GPIOs 13 and 21 are connected to the GPOUT0 clock generator.
460+
* GPIOs 15 and 23 are connected to the GPOUT1 clock generator.
461+
* GPIOs 24 and 25 are connected to the GPOUT2-3 clock generators.
462+
* \endif
463+
*
464+
* \param gpio The GPIO pin to output the clock to.
432465
* \param src The source clock. See the register field CLOCKS_CLK_GPOUT0_CTRL_AUXSRC for a full list. The list is the same for each GPOUT clock generator.
433466
* \param div The float amount to divide the source clock by. This is useful to not overwhelm the GPIO pin with a fast clock.
434467
*/

src/rp2_common/hardware_powman/powman.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,25 @@ void powman_timer_set_1khz_tick_source_xosc_with_hz(uint32_t xosc_freq_hz) {
9797
}
9898
}
9999

100+
#ifndef GPIO_TO_POWMAN_EXT_TIME_REF_SOURCE
101+
#define GPIO_TO_POWMAN_EXT_TIME_REF_SOURCE(gpio, default_ext_time_ref_source) \
102+
((gpio) == 12 ? 0 : \
103+
((gpio) == 20 ? 1 : \
104+
((gpio) == 14 ? 2 : \
105+
((gpio) == 22 ? 3 : \
106+
(default_ext_time_ref_source)))))
107+
#endif
108+
109+
static inline uint32_t gpio_to_powman_ext_time_ref_source(uint gpio, uint32_t default_ext_time_ref_source) {
110+
return GPIO_TO_POWMAN_EXT_TIME_REF_SOURCE(gpio, ({invalid_params_if(HARDWARE_POWMAN, true); default_ext_time_ref_source;}));
111+
}
112+
100113
static void powman_timer_use_gpio(uint32_t gpio, uint32_t use, uint32_t using) {
101114
bool was_running = powman_timer_is_running();
102115
if (was_running) powman_timer_stop();
103-
invalid_params_if(HARDWARE_POWMAN, !((gpio == 12) || (gpio == 14) || (gpio == 20) || (gpio == 22)));
116+
uint32_t source = gpio_to_powman_ext_time_ref_source(gpio, 0);
104117
gpio_set_input_enabled(gpio, true);
105-
powman_write(&powman_hw->ext_time_ref, gpio);
118+
powman_write(&powman_hw->ext_time_ref, source);
106119
powman_set_bits(&powman_hw->timer, use);
107120
if (was_running) {
108121
powman_timer_start();

0 commit comments

Comments
 (0)