Skip to content

Commit c8e4511

Browse files
committed
rp2/modmachine.c: Allow to use the MCU clock for the peripherals.
By default, the peripheral clock for UART and SPI is set to 48 MHz and will not be affected by the MCU clock change. This can be changed by a second argument to machine.freq(freq, use_mcu_clk). If use_mcu_clck is present and True, the mcu_clock is used for UART and SPI. Note that UART and SPI baud rates may have to be re-configured after changing the MCU clock. The peripheral clock cannot be set to arbitrary values. So it follows either the USB clock of 48MHz or the MCU clock. Side change: Allow more than one argument for machine.freq(). Signed-off-by: robert-hh <robert@hammelrath.com>
1 parent 1ae441d commit c8e4511

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

docs/rp2/quickref.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ The :mod:`machine` module::
3636
import machine
3737

3838
machine.freq() # get the current frequency of the CPU
39-
machine.freq(240000000) # set the CPU frequency to 240 MHz
39+
machine.freq(240000000) # set the CPU frequency to 240 MHz and keep
40+
# the UART frequency at 48MHz
41+
machine.freq(125000000, True) # set the CPU and UART frequency to 125 MHz
4042

4143
The :mod:`rp2` module::
4244

extmod/modmachine.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
109109
return mp_const_none;
110110
}
111111
}
112-
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 1, machine_freq);
112+
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 4, machine_freq);
113113

114114
static mp_obj_t machine_lightsleep(size_t n_args, const mp_obj_t *args) {
115115
mp_machine_lightsleep(n_args, args);

ports/rp2/modmachine.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
9696
if (!set_sys_clock_khz(freq / 1000, false)) {
9797
mp_raise_ValueError(MP_ERROR_TEXT("cannot change frequency"));
9898
}
99+
if (n_args > 1 && mp_obj_get_int(args[1]) != 0) {
100+
clock_configure(clk_peri,
101+
0,
102+
CLOCKS_CLK_PERI_CTRL_AUXSRC_VALUE_CLKSRC_PLL_SYS,
103+
freq,
104+
freq);
105+
}
99106
#if MICROPY_HW_ENABLE_UART_REPL
100107
setup_default_uart();
101108
mp_uart_init();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy