Skip to content

Commit 492fd5c

Browse files
atxpfalcon
authored andcommitted
esp8266: Enable setting CPU frequency to 160MHz
1 parent a16715a commit 492fd5c

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

esp8266/esp_mphal.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,3 @@ void HAL_Delay(uint32_t Delay) {
9393
void mp_hal_set_interrupt_char(int c) {
9494
// TODO
9595
}
96-
97-
uint32_t mp_hal_get_cpu_freq(void) {
98-
return ets_get_cpu_frequency();
99-
}

esp8266/etshal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ void ets_isr_unmask();
55
void ets_install_putc1();
66
void ets_isr_attach();
77
void uart_div_modify();
8-
uint32_t ets_get_cpu_frequency();
98

109
#endif // _INCLUDED_ETSHAL_H_

esp8266/modpyb.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,16 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_info_obj, 0, 1, pyb_info);
8181
STATIC mp_obj_t pyb_freq(mp_uint_t n_args, const mp_obj_t *args) {
8282
if (n_args == 0) {
8383
// get
84-
return mp_obj_new_int(mp_hal_get_cpu_freq() * 1000000);
84+
return mp_obj_new_int(system_get_cpu_freq() * 1000000);
8585
} else {
8686
// set
87-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "can't change freq"));
87+
mp_int_t freq = mp_obj_get_int(args[0]) / 1000000;
88+
if (freq != 80 && freq != 160) {
89+
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
90+
"frequency can only be either 80Mhz or 160MHz"));
91+
}
92+
system_update_cpu_freq(freq);
93+
return mp_const_none;
8894
}
8995
}
9096
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_freq_obj, 0, 1, pyb_freq);

0 commit comments

Comments
 (0)