-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Arduino as IDF-Component: Serial.begin() mess up stdout if PM and DFS (Dynamic Frequency Scaling) is enabled #8122
Comments
Could you test it by adding a code line to your sketch: // Serial.flush();
esp_pm_configure(&cfg);
Serial.updateBaudRate(115200); // <<<======= it may help to set all to a correct state
ESP_LOGI( LOG_TAG, "do test in power save" );
|
Hi, I also tried changing delay() statements to vTaskDelay(pdMS_TO_TICKS()) but with no change as well. |
There is a potential bug with the Arduino serial library in combination with tickless sleep, i.e. automatic light sleep mode. see: espressif/arduino-esp32#8122
There is a potential bug with the Arduino serial library in combination with tickless sleep, i.e. automatic light sleep mode. see: espressif/arduino-esp32#8122
@LIFsCode - I have built and executed the suggested code and I got no issue. I have set the I used this code: #include <stdio.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <driver/gpio.h>
#include "sdkconfig.h"
#include <Arduino.h>
#include "esp_pm.h"
const char* LOG_TAG = "issue8122";
extern "C" void app_main()
{
// initialize arduino library before we start the tasks
initArduino();
// BUG-TRIGGER
//NOTE: if uncomment this, the serial output will get corrupted
Serial.begin(115200);
// BUG TRIGER END
ESP_LOGI( LOG_TAG, "Starting");
for (int i=0; i< 2; i++) {
ESP_LOGE( LOG_TAG, "Error:%d", 100 );
ESP_LOGW( LOG_TAG, "Warning:%d", 200 );
ESP_LOGI( LOG_TAG, "Info:%d", 300 );
ESP_LOGD( LOG_TAG, "Debug:%d", 400 );
// for (int i=0;i<10;i++) Serial.println(i);
delay(5000);
ESP_LOGE( LOG_TAG, "Error:%d", 100 );
ESP_LOGW( LOG_TAG, "Warning:%d", 200 );
ESP_LOGI( LOG_TAG, "Info:%d", 300 );
// for (int i=0;i<10;i++) Serial.println(i);
}
Serial.println("\n-------\nbefore power saving\n------");
delay(1000);
ESP_LOGI( LOG_TAG, "Setting up power saving" );
esp_pm_config_esp32_t cfg = {
.max_freq_mhz = 80,
.min_freq_mhz = 40,
.light_sleep_enable = true
};
// Serial.flush();
esp_pm_configure(&cfg);
Serial.println("\n-------\nafter power saving\n------");
ESP_LOGI( LOG_TAG, "do test in power save" );
vTaskDelay(pdMS_TO_TICKS(1000));
ESP_LOGI( LOG_TAG, "testing..." );
for (int i=0; i< 2; i++) {
ESP_LOGE( LOG_TAG, "Error:%d", 100 );
ESP_LOGW( LOG_TAG, "Warning:%d", 200 );
ESP_LOGI( LOG_TAG, "Info:%d", 300 );
ESP_LOGD( LOG_TAG, "Debug:%d", 400 );
// for (int i=0;i<10;i++) Serial.println(i);
delay(5000);
ESP_LOGE( LOG_TAG, "Error:%d", 100 );
ESP_LOGW( LOG_TAG, "Warning:%d", 200 );
ESP_LOGI( LOG_TAG, "Info:%d", 300 );
// for (int i=0;i<10;i++) Serial.println(i);
}
Serial.println("\n-------\nAt the end of execution!\n------");
while(1) {
vTaskDelay(pdMS_TO_TICKS(5000));
}
}
Output:
|
What exactly are you trying to achieve with this code? esp_pm_config_esp32_t cfg = {
.max_freq_mhz = 80,
.min_freq_mhz = 40,
.light_sleep_enable = true
};
// Serial.flush();
esp_pm_configure(&cfg); I didn't get the message |
If the target is to lower the CPU Freq, you can use the Arduino call I tested this code snipet: Serial.println("\n-------\nbefore power saving\n------");
delay(1000);
ESP_LOGI( LOG_TAG, "Setting up power saving" );
esp_pm_config_esp32_t cfg = {
.max_freq_mhz = 80,
.min_freq_mhz = 40,
.light_sleep_enable = true
};
// Serial.flush();
esp_pm_configure(&cfg);
setCpuFrequencyMhz(40);
Serial.updateBaudRate(115200); // <<<======= it may help to set all to a correct state
Serial.println("\n-------\nafter power saving\n------");
ESP_LOGI( LOG_TAG, "do test in power save" );
vTaskDelay(pdMS_TO_TICKS(1000)); Output:
|
The intention is to activate tickless idle, i.e. the freeRTOS is entering light sleep during Idle task if all tasks are blocked or waiting. Did you turn on power management in sdkconfig? Sorry I just noticed I forgot to add my sdkconfig file. I can provide it to you. But I won't be at my place until monday. |
Please provide me the |
Maybe it's more related to DFS, with the wider range of CPU frequency: min=40, max=80 |
By default, Arduino Serial sets APB as clock source in arduino-esp32/cores/esp32/esp32-hal-uart.c Lines 202 to 210 in 8873adb
Change Line 207 and 208 to: uart_config.source_clk = UART_SCLK_REF_TICK; // ESP32, ESP32S2
//uart_config.baud_rate = _get_effective_baudrate(baudrate);
|
@LIFsCode - Please note that we won't "fix it" because Arduino needs a reliable UART source clock that can handle at least 2Mbps. |
For other peripheral issues with DFS, please check the documentation and Arduino Source code in order to adjust their source clock. |
@SuGlider here is the sdkconfig I used. I fully understand that Arduino has certain requirements for the UART baudrate and that this is not going to be changed. |
I think that PM feature is a very a particular case when a project uses IDF and PM. Not directly related to Arduino, but to IDF users. In such a case, we consider that the user shall know what is doing. ESP32 Arduino Core allows projects to mix IDF, HAL and LL, but this is a sort of "expert usage" which we leave for the user to handle. |
I agree and wouldn't recommend supporting PM in Arduino framework. I only recommend holding the respecive ESP_PM_APB_FREQ_MAX lock, within esp32-hal-uart.c |
This setting has effect only when CONFIG_PM_ENABLE is set in the sdkconfig file. |
There is a potential bug with the Arduino serial library in combination with tickless sleep, i.e. automatic light sleep mode. see: espressif/arduino-esp32#8122
There is a potential bug with the Arduino serial library in combination with tickless sleep, i.e. automatic light sleep mode. see: espressif/arduino-esp32#8122
Board
ESP32 Dev Board
Device Description
plain ESP32 Dev Borad connected via USB/UART
Hardware Configuration
plain ESP32 Dev Borad connected via USB/UART
Version
v2.0.7
IDE Name
PlatformIO
Operating System
Windows 10
Flash frequency
40 MHz
PSRAM enabled
no
Upload speed
115200
Description
Running Arduino as IDF component with a IDF app_main
Once I call Serial.begin(115200); the output on the serial terminal will get messed up, once the device is entering light sleep mode.
Running this sdkconfig FreeRTOS config
Sketch
Debug Message
Other Steps to Reproduce
The rest of the code can be left unchanged. The behavior can be turned on and off with adding or removing this line:
Serial.begin(115200);
If Serial is kept running and the following code segment is removed, things work fine. So it seems do be definetly a problem with Serial in combination with light sleep mode.
esp_pm_configure(&cfg);
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: