Skip to content

Commit e2ab7a4

Browse files
committed
Change voltage. Refine docs
1 parent bfba1e4 commit e2ab7a4

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

ports/mimxrt10xx/common-hal/microcontroller/Processor.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ void common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self,
5959
freq != 720 && freq != 816 && freq != 912 && freq != 960 && freq != 1008) {
6060
mp_raise_ValueError(translate("Frequency must be 24, 150, 396, 450, 528, 600, 720, 816, 912, 960 or 1008 Mhz"));
6161
}
62+
SystemCoreClock = setarmclock(frequency);
6263
}
6364

6465

ports/raspberrypi/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ INC += \
129129
-isystem sdk/src/rp2_common/hardware_sync/include/ \
130130
-isystem sdk/src/rp2_common/hardware_timer/include/ \
131131
-isystem sdk/src/rp2_common/hardware_uart/include/ \
132+
-isystem sdk/src/rp2_common/hardware_vreg/include/ \
132133
-isystem sdk/src/rp2_common/hardware_watchdog/include/ \
133134
-isystem sdk/src/rp2_common/hardware_xosc/include/ \
134135
-isystem sdk/src/rp2_common/pico_multicore/include/ \
@@ -216,6 +217,7 @@ SRC_SDK := \
216217
src/rp2_common/hardware_sync/sync.c \
217218
src/rp2_common/hardware_timer/timer.c \
218219
src/rp2_common/hardware_uart/uart.c \
220+
src/rp2_common/hardware_vreg/vreg.c \
219221
src/rp2_common/hardware_watchdog/watchdog.c \
220222
src/rp2_common/hardware_xosc/xosc.c \
221223
src/rp2_common/pico_bootrom/bootrom.c \

ports/raspberrypi/common-hal/microcontroller/Processor.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@
3232
#include "common-hal/microcontroller/Processor.h"
3333
#include "shared-bindings/microcontroller/Processor.h"
3434
#include "shared-bindings/microcontroller/ResetReason.h"
35+
#include "shared-bindings/time/__init__.h"
3536

3637
#include "pico/stdlib.h"
3738
#include "src/rp2_common/hardware_adc/include/hardware/adc.h"
3839
#include "src/rp2_common/hardware_clocks/include/hardware/clocks.h"
40+
#include "src/rp2_common/hardware_vreg/include/hardware/vreg.h"
3941

4042
#include "src/rp2040/hardware_regs/include/hardware/regs/vreg_and_chip_reset.h"
4143
#include "src/rp2040/hardware_regs/include/hardware/regs/watchdog.h"
@@ -62,9 +64,24 @@ uint32_t common_hal_mcu_processor_get_frequency(void) {
6264
}
6365

6466
void common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self, uint32_t frequency) {
65-
if (!set_sys_clock_khz(frequency / 1000, false)) {
67+
uint vco, postdiv1, postdiv2;
68+
uint32_t freq_khz = frequency / 1000;
69+
if (!check_sys_clock_khz(freq_khz, &vco, &postdiv1, &postdiv2)) {
6670
mp_arg_error_invalid(MP_QSTR_frequency);
6771
}
72+
// These voltages are approximate based on the PicoDVI examples.
73+
enum vreg_voltage voltage = VREG_VOLTAGE_1_10;
74+
if (freq_khz >= 400000) {
75+
voltage = VREG_VOLTAGE_1_30;
76+
} else if (freq_khz >= 300000) {
77+
voltage = VREG_VOLTAGE_1_20;
78+
} else if (freq_khz > 133000) {
79+
voltage = VREG_VOLTAGE_1_20;
80+
}
81+
vreg_set_voltage(voltage);
82+
// Wait for a stable voltage
83+
common_hal_time_delay_ms(10);
84+
set_sys_clock_khz(freq_khz, false);
6885
}
6986

7087
void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) {

shared-bindings/microcontroller/Processor.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,12 @@
7070
//| **Limitations:** On most boards, ``frequency`` is read-only. Setting
7171
//| the ``frequency`` is possible on RP2040 boards and some i.MX boards.
7272
//|
73-
//| .. warning:: On RP2040 boards changing the frequency may cause issues
74-
//| with other subsystems, such as USB, PWM, and PIO.
73+
//| .. warning:: Overclocking likely voids your warranties and may reduce
74+
//| the lifetime of the chip.
75+
//|
76+
//| .. warning:: Changing the frequency may cause issues with other
77+
//| subsystems, such as USB, PWM, and PIO. To minimize issues, set the CPU
78+
//| frequency before initializing other systems.
7579
//| """
7680

7781
#if CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY

0 commit comments

Comments
 (0)