diff --git a/ports/mimxrt10xx/common-hal/microcontroller/Processor.c b/ports/mimxrt10xx/common-hal/microcontroller/Processor.c index 17ced78910..34400e3f41 100644 --- a/ports/mimxrt10xx/common-hal/microcontroller/Processor.c +++ b/ports/mimxrt10xx/common-hal/microcontroller/Processor.c @@ -52,15 +52,13 @@ float common_hal_mcu_processor_get_temperature(void) { return temp; } -uint32_t common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self, +void common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self, uint32_t frequency) { uint32_t freq = frequency / 1000000; if (freq != 24 && freq != 150 && freq != 396 && freq != 450 && freq != 528 && freq != 600 && 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); - return SystemCoreClock; } diff --git a/ports/raspberrypi/common-hal/microcontroller/Processor.c b/ports/raspberrypi/common-hal/microcontroller/Processor.c index 08e6495d26..66083a357d 100644 --- a/ports/raspberrypi/common-hal/microcontroller/Processor.c +++ b/ports/raspberrypi/common-hal/microcontroller/Processor.c @@ -61,14 +61,10 @@ uint32_t common_hal_mcu_processor_get_frequency(void) { return clock_get_hz(clk_sys); } -uint32_t common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self, - uint32_t frequency) { - uint32_t freq = frequency / 1000; - - if (!set_sys_clock_khz(freq, false)) { - mp_raise_ValueError(translate("Invalid frequency supplied")); +void common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self, uint32_t frequency) { + if (!set_sys_clock_khz(frequency / 1000, false)) { + mp_arg_error_invalid(MP_QSTR_frequency); } - return clock_get_hz(clk_sys); } void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { diff --git a/shared-bindings/microcontroller/Processor.c b/shared-bindings/microcontroller/Processor.c index f5190d36ef..6ae0212a6a 100644 --- a/shared-bindings/microcontroller/Processor.c +++ b/shared-bindings/microcontroller/Processor.c @@ -67,8 +67,11 @@ //| frequency: int //| """The CPU operating frequency in Hertz. //| -//| **Limitations:** Setting the ``frequency`` is possible on RP2040 boards and some i.MX boards. -//| On most boards, ``frequency`` is read-only. +//| **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. //| """ #if CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY diff --git a/shared-bindings/microcontroller/Processor.h b/shared-bindings/microcontroller/Processor.h index 9a2f22b245..473f25cbc6 100644 --- a/shared-bindings/microcontroller/Processor.h +++ b/shared-bindings/microcontroller/Processor.h @@ -39,6 +39,6 @@ mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void); float common_hal_mcu_processor_get_temperature(void); void common_hal_mcu_processor_get_uid(uint8_t raw_id[]); float common_hal_mcu_processor_get_voltage(void); -uint32_t common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self, uint32_t frequency); +void common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self, uint32_t frequency); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_MICROCONTROLLER_PROCESSOR_H