Skip to content

Commit bfba1e4

Browse files
committed
Change common_hal_mcu_processor_set_frequency to void
* Add warning about setting RP2040 frequency
1 parent a84a885 commit bfba1e4

File tree

4 files changed

+10
-13
lines changed

4 files changed

+10
-13
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,13 @@ float common_hal_mcu_processor_get_temperature(void) {
5252
return temp;
5353
}
5454

55-
uint32_t common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self,
55+
void common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self,
5656
uint32_t frequency) {
5757
uint32_t freq = frequency / 1000000;
5858
if (freq != 24 && freq != 150 && freq != 396 && freq != 450 && freq != 528 && freq != 600 &&
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);
63-
return SystemCoreClock;
6462
}
6563

6664

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,10 @@ uint32_t common_hal_mcu_processor_get_frequency(void) {
6161
return clock_get_hz(clk_sys);
6262
}
6363

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"));
64+
void common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self, uint32_t frequency) {
65+
if (!set_sys_clock_khz(frequency / 1000, false)) {
66+
mp_arg_error_invalid(MP_QSTR_frequency);
7067
}
71-
return clock_get_hz(clk_sys);
7268
}
7369

7470
void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) {

shared-bindings/microcontroller/Processor.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@
6767
//| frequency: int
6868
//| """The CPU operating frequency in Hertz.
6969
//|
70-
//| **Limitations:** Setting the ``frequency`` is possible on RP2040 boards and some i.MX boards.
71-
//| On most boards, ``frequency`` is read-only.
70+
//| **Limitations:** On most boards, ``frequency`` is read-only. Setting
71+
//| the ``frequency`` is possible on RP2040 boards and some i.MX boards.
72+
//|
73+
//| .. warning:: On RP2040 boards changing the frequency may cause issues
74+
//| with other subsystems, such as USB, PWM, and PIO.
7275
//| """
7376

7477
#if CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY

shared-bindings/microcontroller/Processor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void);
3939
float common_hal_mcu_processor_get_temperature(void);
4040
void common_hal_mcu_processor_get_uid(uint8_t raw_id[]);
4141
float common_hal_mcu_processor_get_voltage(void);
42-
uint32_t common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self, uint32_t frequency);
42+
void common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self, uint32_t frequency);
4343

4444
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_MICROCONTROLLER_PROCESSOR_H

0 commit comments

Comments
 (0)