diff --git a/cpu/rpx0xx/clock.c b/cpu/rpx0xx/clock.c index 424632b263..3af4252951 100644 --- a/cpu/rpx0xx/clock.c +++ b/cpu/rpx0xx/clock.c @@ -177,3 +177,17 @@ void clock_gpout3_configure(uint32_t f_in, uint32_t f_out, CLOCKS_CLK_GPOUT3_CTR io_reg_atomic_set(&PADS_BANK0->GPIO25, 1U << PADS_BANK0_GPIO25_IE_Pos); gpio_set_function_select(25, FUNCTION_SELECT_CLOCK); } + +void clock_adc_configure(CLOCKS_CLK_ADC_CTRL_AUXSRC_Enum aux) +{ + /* Stop the clock generator */ + io_reg_atomic_clear(&CLOCKS->CLK_ADC_CTRL, + (1u << CLOCKS_CLK_ADC_CTRL_ENABLE_Pos)); + /* Selects the new auxiliary clock source */ + io_reg_write_dont_corrupt(&CLOCKS->CLK_ADC_CTRL, + aux << CLOCKS_CLK_ADC_CTRL_AUXSRC_Pos, + CLOCKS_CLK_ADC_CTRL_AUXSRC_Msk); + /* Restart the clock generator */ + io_reg_atomic_set(&CLOCKS->CLK_ADC_CTRL, + (1u << CLOCKS_CLK_ADC_CTRL_ENABLE_Pos)); +} diff --git a/cpu/rpx0xx/cpu.c b/cpu/rpx0xx/cpu.c index 61fd73f773..6fa88532d5 100644 --- a/cpu/rpx0xx/cpu.c +++ b/cpu/rpx0xx/cpu.c @@ -41,6 +41,7 @@ static void _cpu_reset(void) | RESETS_RESET_pll_usb_Msk | RESETS_RESET_pll_sys_Msk | RESETS_RESET_pads_qspi_Msk + | RESETS_RESET_pads_bank0_Msk | RESETS_RESET_io_qspi_Msk); periph_reset(rst); /* Assert that reset has completed except for those components which @@ -78,6 +79,13 @@ static void _cpu_reset(void) clock_gpout0_configure(CLOCK_XOSC, CLOCK_XOSC, CLOCKS_CLK_GPOUT0_CTRL_AUXSRC_clk_ref); } + + /* Configure USB PLL to deliver 48MHz needed by ADC */ + if (IS_USED(MODULE_PERIPH_ADC)) { + pll_start_usb(PLL_USB_REF_DIV, PLL_USB_VCO_FEEDBACK_SCALE, + PLL_USB_POSTDIV1, PLL_USB_POSTDIV2); + clock_adc_configure(CLOCKS_CLK_ADC_CTRL_AUXSRC_clksrc_pll_usb); + } } void cpu_init(void) diff --git a/cpu/rpx0xx/include/periph_cpu.h b/cpu/rpx0xx/include/periph_cpu.h index a0d7e0584d..0d137f9add 100644 --- a/cpu/rpx0xx/include/periph_cpu.h +++ b/cpu/rpx0xx/include/periph_cpu.h @@ -613,6 +613,13 @@ void clock_gpout2_configure(uint32_t f_in, uint32_t f_out, CLOCKS_CLK_GPOUT2_CTR */ void clock_gpout3_configure(uint32_t f_in, uint32_t f_out, CLOCKS_CLK_GPOUT3_CTRL_AUXSRC_Enum aux); +/** + * @brief Configure the ADC clock to run from a dedicated auxiliary + * clock source + * + * @param aux Auxiliary clock source + */ +void clock_adc_configure(CLOCKS_CLK_ADC_CTRL_AUXSRC_Enum aux); /** @} */ /**