diff options
| author | robert-hh <robert@hammelrath.com> | 2022-06-04 17:00:32 +0200 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2022-10-06 22:34:42 +1100 |
| commit | 5af54ad61feb52f4c1367d6f9a8a60d972f02419 (patch) | |
| tree | 6bfd72b183fd1068fd11cdfd3fc6b5cd25e29000 | |
| parent | b4d29fd47a52526bc9626e5dc28794fa1d95dcf2 (diff) | |
samd/modmachine: Allow changing the CPU freq with machine.freq(f).
SAMD51 only. Accepted values are 48_000_000 to 200_000_000. The range
specified by Atmel is 96_000_000 to 120_000_000.
| -rw-r--r-- | ports/samd/modmachine.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/ports/samd/modmachine.c b/ports/samd/modmachine.c index 1b78b687e..99fccf5bf 100644 --- a/ports/samd/modmachine.c +++ b/ports/samd/modmachine.c @@ -59,10 +59,21 @@ STATIC mp_obj_t machine_bootloader(void) { } MP_DEFINE_CONST_FUN_OBJ_0(machine_bootloader_obj, machine_bootloader); -STATIC mp_obj_t machine_freq(void) { - return MP_OBJ_NEW_SMALL_INT(CPU_FREQ); +STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) { + if (n_args == 0) { + return MP_OBJ_NEW_SMALL_INT(get_cpu_freq()); + } else { + #if defined(MCU_SAMD51) + uint32_t freq = mp_obj_get_int(args[0]); + if (freq >= 48000000 && freq <= 200000000) { + set_cpu_freq(freq); + SysTick_Config(freq / 1000); + } + #endif + return mp_const_none; + } } -MP_DEFINE_CONST_FUN_OBJ_0(machine_freq_obj, machine_freq); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 1, machine_freq); STATIC mp_obj_t machine_unique_id(void) { // Each device has a unique 128-bit serial number which is a concatenation of four 32-bit |
