mirror of
https://github.com/meshtastic/firmware.git
synced 2025-09-06 19:49:19 +00:00
set serial clock source to ref_tick for esp32 platform
This commit is contained in:
parent
050b967d5f
commit
ed27f91e94
@ -22,6 +22,7 @@
|
|||||||
#include "target_specific.h"
|
#include "target_specific.h"
|
||||||
#include <Preferences.h>
|
#include <Preferences.h>
|
||||||
#include <driver/rtc_io.h>
|
#include <driver/rtc_io.h>
|
||||||
|
#include <driver/uart.h>
|
||||||
#include <nvs.h>
|
#include <nvs.h>
|
||||||
#include <nvs_flash.h>
|
#include <nvs_flash.h>
|
||||||
|
|
||||||
@ -263,3 +264,51 @@ void cpuDeepSleep(uint32_t msecToWake)
|
|||||||
esp_sleep_enable_timer_wakeup(msecToWake * 1000ULL); // call expects usecs
|
esp_sleep_enable_timer_wakeup(msecToWake * 1000ULL); // call expects usecs
|
||||||
esp_deep_sleep_start(); // TBD mA sleep current (battery)
|
esp_deep_sleep_start(); // TBD mA sleep current (battery)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool setSerialClockToRefTick(int uart_num)
|
||||||
|
{
|
||||||
|
#if !SOC_UART_SUPPORT_REF_TICK
|
||||||
|
return false;
|
||||||
|
#else
|
||||||
|
uart_config_t uart_config;
|
||||||
|
uint32_t baudrate;
|
||||||
|
|
||||||
|
if (uart_get_baudrate(uart_num, &baudrate) != ESP_OK) {
|
||||||
|
LOG_ERROR("Unable to get UART baudrate");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uart_config.baud_rate = (int)baudrate;
|
||||||
|
|
||||||
|
if (uart_get_word_length(uart_num, &uart_config.data_bits) != ESP_OK) {
|
||||||
|
LOG_ERROR("Unable to get UART baudrate");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (uart_get_parity(uart_num, &uart_config.parity) != ESP_OK) {
|
||||||
|
LOG_ERROR("Unable to get UART baudrate");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (uart_get_stop_bits(uart_num, &uart_config.stop_bits) != ESP_OK) {
|
||||||
|
LOG_ERROR("Unable to get UART baudrate");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (uart_get_hw_flow_ctrl(uart_num, &uart_config.flow_ctrl) != ESP_OK) {
|
||||||
|
LOG_ERROR("Unable to get UART baudrate");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uart_config.flow_ctrl != UART_HW_FLOWCTRL_DISABLE) {
|
||||||
|
uart_config.rx_flow_ctrl_thresh = 122;
|
||||||
|
}
|
||||||
|
|
||||||
|
uart_config.source_clk = UART_SCLK_REF_TICK;
|
||||||
|
|
||||||
|
// Configure UART parameters
|
||||||
|
if (uart_param_config(uart_num, &uart_config) != ESP_OK) {
|
||||||
|
LOG_ERROR("Unable to get UART baudrate");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
@ -58,6 +58,9 @@ Observable<esp_sleep_wakeup_cause_t> notifyLightSleepEnd;
|
|||||||
esp_pm_lock_handle_t pmLightSleepLock;
|
esp_pm_lock_handle_t pmLightSleepLock;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// this are imported symbol with target-specific implementation
|
||||||
|
bool setSerialClockToRefTick(int uart_num);
|
||||||
|
|
||||||
// restores GPIO function after sleep
|
// restores GPIO function after sleep
|
||||||
void gpioReset(void);
|
void gpioReset(void);
|
||||||
// enables button wake-up interrupt
|
// enables button wake-up interrupt
|
||||||
@ -68,6 +71,9 @@ void enableLoraInterrupt(void);
|
|||||||
bool shouldLoraWake(uint32_t msecToWake);
|
bool shouldLoraWake(uint32_t msecToWake);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// this are imported symbol with target-specific implementation
|
||||||
|
void cpuDeepSleep(uint32_t msecToWake);
|
||||||
|
|
||||||
// deep sleep support
|
// deep sleep support
|
||||||
RTC_DATA_ATTR int bootCount = 0;
|
RTC_DATA_ATTR int bootCount = 0;
|
||||||
|
|
||||||
@ -427,6 +433,13 @@ void doLightSleep(uint32_t sleepMsec)
|
|||||||
void initLightSleep()
|
void initLightSleep()
|
||||||
{
|
{
|
||||||
esp_err_t res;
|
esp_err_t res;
|
||||||
|
bool dfsSupported = true;
|
||||||
|
|
||||||
|
#if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2)
|
||||||
|
if (dfsSupported) {
|
||||||
|
dfsSupported &= setSerialClockToRefTick(UART_NUM_0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAS_ESP32_PM_SUPPORT
|
#ifdef HAS_ESP32_PM_SUPPORT
|
||||||
res = esp_pm_lock_create(ESP_PM_NO_LIGHT_SLEEP, 0, "meshtastic", &pmLightSleepLock);
|
res = esp_pm_lock_create(ESP_PM_NO_LIGHT_SLEEP, 0, "meshtastic", &pmLightSleepLock);
|
||||||
@ -437,7 +450,7 @@ void initLightSleep()
|
|||||||
|
|
||||||
esp_pm_config_esp32_t pm_config;
|
esp_pm_config_esp32_t pm_config;
|
||||||
pm_config.max_freq_mhz = 80;
|
pm_config.max_freq_mhz = 80;
|
||||||
pm_config.min_freq_mhz = 20;
|
pm_config.min_freq_mhz = dfsSupported ? 20 : pm_config.max_freq_mhz;
|
||||||
#ifdef HAS_ESP32_DYNAMIC_LIGHT_SLEEP
|
#ifdef HAS_ESP32_DYNAMIC_LIGHT_SLEEP
|
||||||
pm_config.light_sleep_enable = true;
|
pm_config.light_sleep_enable = true;
|
||||||
#else
|
#else
|
||||||
|
@ -21,7 +21,7 @@ void doLightSleep(uint32_t msecToWake);
|
|||||||
|
|
||||||
// perform power on init that we do on each wake from deep sleep
|
// perform power on init that we do on each wake from deep sleep
|
||||||
void initDeepSleep();
|
void initDeepSleep();
|
||||||
void doDeepSleep(uint32_t msecToWake, bool skipPreflight, bool skipSaveNodeDb), cpuDeepSleep(uint32_t msecToWake);
|
void doDeepSleep(uint32_t msecToWake, bool skipPreflight, bool skipSaveNodeDb);
|
||||||
|
|
||||||
void setCPUFast(bool on);
|
void setCPUFast(bool on);
|
||||||
|
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
[env:heltec-v2_1]
|
[env:heltec-v2_1]
|
||||||
board_level = extra
|
board_level = extra
|
||||||
;build_type = debug ; to make it possible to step through our jtag debugger
|
;build_type = debug ; to make it possible to step through our jtag debugger
|
||||||
extends = esp32_base
|
extends = esp32_base
|
||||||
board = heltec_wifi_lora_32_V2
|
board = heltec_wifi_lora_32_V2
|
||||||
build_flags =
|
platform_packages =
|
||||||
|
platformio/framework-arduinoespressif32 @ https://github.com/m1nl/arduino-esp32/archive/refs/tags/2.0.17+7b9546f7.tar.gz ; optimize IRAM usage for ESP32 platform
|
||||||
|
build_flags =
|
||||||
${esp32_base.build_flags}
|
${esp32_base.build_flags}
|
||||||
-D HELTEC_V2_1
|
-D HELTEC_V2_1
|
||||||
-I variants/esp32/heltec_v2.1
|
-I variants/esp32/heltec_v2.1
|
||||||
|
Loading…
Reference in New Issue
Block a user