Browse Source

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.
pull/9534/head
robert-hh 2 years ago
committed by Damien George
parent
commit
5af54ad61f
  1. 17
      ports/samd/modmachine.c

17
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

Loading…
Cancel
Save