Change common_hal_mcu_processor_set_frequency to void

* Add warning about setting RP2040 frequency
This commit is contained in:
Colin B 2023-01-16 20:39:20 -08:00
parent a84a8855ed
commit bfba1e4100
4 changed files with 10 additions and 13 deletions

View File

@ -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;
}

View File

@ -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[]) {

View File

@ -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

View File

@ -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