diff --git a/cpu/esp8266/include/user_config.h b/cpu/esp8266/include/user_config.h index 4a53d4e0f057002d1eed08eac38c4cca623cc121..94825891a0b042ef78b347023b7646ef3b826ef1 100644 --- a/cpu/esp8266/include/user_config.h +++ b/cpu/esp8266/include/user_config.h @@ -5,6 +5,13 @@ * General Public License v2.1. See the file LICENSE in the top level * directory for more details. */ +/** + * @ingroup cpu_esp8266 + * @brief Default configurations required by the SDK + * @author Gunar Schorcht <gunar@schorcht.net> + * @file + * @{ + */ #ifndef USER_CONFIG_H #define USER_CONFIG_H @@ -13,10 +20,17 @@ extern "C" { #endif -/* This file is just to satisfy SDK */ +/** + * @brief Default CPU frequency in MHz. + * Possible values are 80 and 160. + */ +#ifndef ESP8266_CPU_FREQUENCY +#define ESP8266_CPU_FREQUENCY 80 +#endif #ifdef __cplusplus } #endif #endif /* USER_CONFIG_H */ +/** @} */ diff --git a/cpu/esp8266/sdk/main.c b/cpu/esp8266/sdk/main.c index 8db72d07bbad4e3ac7ffe295c4640d80ebe563f3..f88a8150098a1b37f690816ccd4dd67916752512 100644 --- a/cpu/esp8266/sdk/main.c +++ b/cpu/esp8266/sdk/main.c @@ -129,6 +129,19 @@ void system_restart(void) __asm__ volatile (" call0 0x40000080 "); } +extern bool system_update_cpu_freq(uint8 freq) +{ + if (freq == 160) { + DPORT.CPU_CLOCK |= DPORT_CPU_CLOCK_X2; + ets_update_cpu_frequency(160); + } + else { + DPORT.CPU_CLOCK &= ~DPORT_CPU_CLOCK_X2; + ets_update_cpu_frequency(80); + } + return true; +} + /** * Following code is completly or at least partially from * https://github.com/pvvx/esp8266web diff --git a/cpu/esp8266/sdk/main.h b/cpu/esp8266/sdk/main.h index e87927e527adfbcb807bf74ef9e7f36bb1c36f72..c946101c31947ccabc4ddd454e5bb1176dfb6c87 100644 --- a/cpu/esp8266/sdk/main.h +++ b/cpu/esp8266/sdk/main.h @@ -42,13 +42,13 @@ extern "C" { #define system_get_time phy_get_mactime #define system_get_chip_id() (((DPORT.OTP_MAC1 & 0xffff) << 8) + ((DPORT.OTP_MAC0 >> 24) & 0xff)) #define system_get_cpu_freq ets_get_cpu_frequency -/* TODO #define system_update_cpu_freq ets_update_cpu_frequency */ extern int os_printf_plus (const char* format, ...); extern void system_deep_sleep (uint32_t time_in_us); extern uint8_t system_get_checksum(uint8_t *ptr, uint32_t len); extern void system_restart (void); +extern bool system_update_cpu_freq(uint8 freq); extern bool system_rtc_mem_read(uint32_t src_addr, void *des_addr, uint32_t save_size); extern bool system_rtc_mem_write(uint32_t src_addr, void *des_addr, uint32_t save_size); diff --git a/cpu/esp8266/startup.c b/cpu/esp8266/startup.c index f37ad180d5a11bccc0ff28b2b7b53924dfa9a653..d132d0bb8070976d014d5d596db51e442542b693 100644 --- a/cpu/esp8266/startup.c +++ b/cpu/esp8266/startup.c @@ -170,8 +170,8 @@ void IRAM user_init (void) syscalls_init (); thread_isr_stack_init (); - /* run system in high performance mode */ - system_update_cpu_freq(160); + /* set system frequency */ + system_update_cpu_freq(ESP8266_CPU_FREQUENCY); /* reinit system timer as microsecond timer */ system_timer_reinit (); @@ -191,6 +191,7 @@ void IRAM user_init (void) #include "esp/dport_regs.h" #include "esp/phy_info.h" #include "esp/spiflash.h" +#include "user_config.h" /** * @brief Defines the structure of the file header in SPI flash @@ -661,8 +662,8 @@ void __attribute__((noreturn)) IRAM cpu_user_start (void) /** }@ */ - /* run system in high performance mode */ - /* TODO system_update_cpu_freq(160); */ + /* set system frequency */ + system_update_cpu_freq(ESP8266_CPU_FREQUENCY); /* PHASE 3: start RIOT-OS kernel */