28
28
#include <string.h>
29
29
30
30
#include "py/mphal.h"
31
+ #include "py/runtime.h"
31
32
#include "common-hal/microcontroller/Processor.h"
32
33
#include "shared-bindings/microcontroller/Processor.h"
33
34
#include "shared-bindings/microcontroller/ResetReason.h"
35
+ #include "shared-bindings/time/__init__.h"
34
36
37
+ #include "pico/stdlib.h"
35
38
#include "src/rp2_common/hardware_adc/include/hardware/adc.h"
36
39
#include "src/rp2_common/hardware_clocks/include/hardware/clocks.h"
40
+ #include "src/rp2_common/hardware_vreg/include/hardware/vreg.h"
37
41
#include "src/rp2_common/hardware_watchdog/include/hardware/watchdog.h"
38
42
39
43
#include "src/rp2040/hardware_regs/include/hardware/regs/vreg_and_chip_reset.h"
@@ -60,6 +64,27 @@ uint32_t common_hal_mcu_processor_get_frequency(void) {
60
64
return clock_get_hz (clk_sys );
61
65
}
62
66
67
+ void common_hal_mcu_processor_set_frequency (mcu_processor_obj_t * self , uint32_t frequency ) {
68
+ uint vco , postdiv1 , postdiv2 ;
69
+ uint32_t freq_khz = frequency / 1000 ;
70
+ if (!check_sys_clock_khz (freq_khz , & vco , & postdiv1 , & postdiv2 )) {
71
+ mp_arg_error_invalid (MP_QSTR_frequency );
72
+ }
73
+ // These voltages are approximate based on the PicoDVI examples.
74
+ enum vreg_voltage voltage = VREG_VOLTAGE_1_10 ;
75
+ if (freq_khz >= 400000 ) {
76
+ voltage = VREG_VOLTAGE_1_30 ;
77
+ } else if (freq_khz >= 300000 ) {
78
+ voltage = VREG_VOLTAGE_1_20 ;
79
+ } else if (freq_khz > 133000 ) {
80
+ voltage = VREG_VOLTAGE_1_20 ;
81
+ }
82
+ vreg_set_voltage (voltage );
83
+ // Wait for a stable voltage
84
+ common_hal_time_delay_ms (10 );
85
+ set_sys_clock_khz (freq_khz , false);
86
+ }
87
+
63
88
void common_hal_mcu_processor_get_uid (uint8_t raw_id []) {
64
89
pico_unique_board_id_t retrieved_id ;
65
90
pico_get_unique_board_id (& retrieved_id );
0 commit comments