Change voltage. Refine docs

This commit is contained in:
Scott Shawcroft 2023-04-19 17:04:54 -07:00
parent bfba1e4100
commit e2ab7a4751
No known key found for this signature in database
GPG Key ID: 0DFD512649C052DA
4 changed files with 27 additions and 3 deletions

View File

@ -59,6 +59,7 @@ void common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self,
freq != 720 && freq != 816 && freq != 912 && freq != 960 && freq != 1008) {
mp_raise_ValueError(translate("Frequency must be 24, 150, 396, 450, 528, 600, 720, 816, 912, 960 or 1008 Mhz"));
}
SystemCoreClock = setarmclock(frequency);
}

View File

@ -129,6 +129,7 @@ INC += \
-isystem sdk/src/rp2_common/hardware_sync/include/ \
-isystem sdk/src/rp2_common/hardware_timer/include/ \
-isystem sdk/src/rp2_common/hardware_uart/include/ \
-isystem sdk/src/rp2_common/hardware_vreg/include/ \
-isystem sdk/src/rp2_common/hardware_watchdog/include/ \
-isystem sdk/src/rp2_common/hardware_xosc/include/ \
-isystem sdk/src/rp2_common/pico_multicore/include/ \
@ -216,6 +217,7 @@ SRC_SDK := \
src/rp2_common/hardware_sync/sync.c \
src/rp2_common/hardware_timer/timer.c \
src/rp2_common/hardware_uart/uart.c \
src/rp2_common/hardware_vreg/vreg.c \
src/rp2_common/hardware_watchdog/watchdog.c \
src/rp2_common/hardware_xosc/xosc.c \
src/rp2_common/pico_bootrom/bootrom.c \

View File

@ -32,10 +32,12 @@
#include "common-hal/microcontroller/Processor.h"
#include "shared-bindings/microcontroller/Processor.h"
#include "shared-bindings/microcontroller/ResetReason.h"
#include "shared-bindings/time/__init__.h"
#include "pico/stdlib.h"
#include "src/rp2_common/hardware_adc/include/hardware/adc.h"
#include "src/rp2_common/hardware_clocks/include/hardware/clocks.h"
#include "src/rp2_common/hardware_vreg/include/hardware/vreg.h"
#include "src/rp2040/hardware_regs/include/hardware/regs/vreg_and_chip_reset.h"
#include "src/rp2040/hardware_regs/include/hardware/regs/watchdog.h"
@ -62,9 +64,24 @@ uint32_t common_hal_mcu_processor_get_frequency(void) {
}
void common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self, uint32_t frequency) {
if (!set_sys_clock_khz(frequency / 1000, false)) {
uint vco, postdiv1, postdiv2;
uint32_t freq_khz = frequency / 1000;
if (!check_sys_clock_khz(freq_khz, &vco, &postdiv1, &postdiv2)) {
mp_arg_error_invalid(MP_QSTR_frequency);
}
// These voltages are approximate based on the PicoDVI examples.
enum vreg_voltage voltage = VREG_VOLTAGE_1_10;
if (freq_khz >= 400000) {
voltage = VREG_VOLTAGE_1_30;
} else if (freq_khz >= 300000) {
voltage = VREG_VOLTAGE_1_20;
} else if (freq_khz > 133000) {
voltage = VREG_VOLTAGE_1_20;
}
vreg_set_voltage(voltage);
// Wait for a stable voltage
common_hal_time_delay_ms(10);
set_sys_clock_khz(freq_khz, false);
}
void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) {

View File

@ -70,8 +70,12 @@
//| **Limitations:** On most boards, ``frequency`` is read-only. Setting
//| the ``frequency`` is possible on RP2040 boards and some i.MX boards.
//|
//| .. warning:: On RP2040 boards changing the frequency may cause issues
//| with other subsystems, such as USB, PWM, and PIO.
//| .. warning:: Overclocking likely voids your warranties and may reduce
//| the lifetime of the chip.
//|
//| .. warning:: Changing the frequency may cause issues with other
//| subsystems, such as USB, PWM, and PIO. To minimize issues, set the CPU
//| frequency before initializing other systems.
//| """
#if CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY