Skip to content

Commit a84a885

Browse files
committed
Add frequency setting for RP2040 boards.
1 parent 037bfb3 commit a84a885

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

ports/raspberrypi/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ SRC_SDK := \
229229
src/rp2_common/pico_printf/printf.c \
230230
src/rp2_common/pico_runtime/runtime.c \
231231
src/rp2_common/pico_stdio/stdio.c \
232+
src/rp2_common/pico_stdlib/stdlib.c \
232233
src/rp2_common/pico_unique_id/unique_id.c \
233234
$(SRC_SDK_CYW43) \
234235

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@
2828
#include <string.h>
2929

3030
#include "py/mphal.h"
31+
#include "py/runtime.h"
3132
#include "common-hal/microcontroller/Processor.h"
3233
#include "shared-bindings/microcontroller/Processor.h"
3334
#include "shared-bindings/microcontroller/ResetReason.h"
3435

36+
#include "pico/stdlib.h"
3537
#include "src/rp2_common/hardware_adc/include/hardware/adc.h"
3638
#include "src/rp2_common/hardware_clocks/include/hardware/clocks.h"
3739

@@ -59,6 +61,16 @@ uint32_t common_hal_mcu_processor_get_frequency(void) {
5961
return clock_get_hz(clk_sys);
6062
}
6163

64+
uint32_t common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self,
65+
uint32_t frequency) {
66+
uint32_t freq = frequency / 1000;
67+
68+
if (!set_sys_clock_khz(freq, false)) {
69+
mp_raise_ValueError(translate("Invalid frequency supplied"));
70+
}
71+
return clock_get_hz(clk_sys);
72+
}
73+
6274
void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) {
6375
pico_unique_board_id_t retrieved_id;
6476
pico_get_unique_board_id(&retrieved_id);

ports/raspberrypi/mpconfigport.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ CIRCUITPY_BUILD_EXTENSIONS ?= uf2
4848
USB_NUM_ENDPOINT_PAIRS = 8
4949

5050
INTERNAL_FLASH_FILESYSTEM = 1
51+
CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY = 1

shared-bindings/microcontroller/Processor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
//| frequency: int
6868
//| """The CPU operating frequency in Hertz.
6969
//|
70-
//| **Limitations:** Setting the ``frequency`` is possible only on some i.MX boards.
70+
//| **Limitations:** Setting the ``frequency`` is possible on RP2040 boards and some i.MX boards.
7171
//| On most boards, ``frequency`` is read-only.
7272
//| """
7373

0 commit comments

Comments
 (0)