Chapter 4. API Guides
Improving Startup Time In addition to the overall performance improvements shown above, the following options
can be tweaked to specifically reduce startup time:
• Minimizing the CONFIG_LOG_DEFAULT_LEVEL and CONFIG_BOOTLOADER_LOG_LEVEL has a
large impact on startup time. To enable more logging after the app starts up, set the CON-
FIG_LOG_MAXIMUM_LEVEL as well and then call esp_log_set_level() to restore higher level logs.
The system/startup_time main function shows how to do this.
• If using deep sleep, setting CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP allows a faster
wake from sleep. Note that if using Secure Boot this represents a security compromise, as Secure Boot vali-
dation will not be performed on wake.
• Setting CONFIG_BOOTLOADER_SKIP_VALIDATE_ON_POWER_ON will skip verifying the binary on every
boot from power-on reset. How much time this saves depends on the binary size and the flash settings. Note
that this setting carries some risk if the flash becomes corrupt unexpectedly. Read the help text of the config
item for an explanation and recommendations if using this option.
• It’s possible to save a small amount of time during boot by disabling RTC slow clock calibration. To do so,
set CONFIG_ESP32S2_RTC_CLK_CAL_CYCLES to 0. Any part of the firmware that uses RTC slow clock as
a timing source will be less accurate as a result.
The example project system/startup_time is pre-configured to optimize startup time. The files sys-
tem/startup_time/sdkconfig.defaults and system/startup_time/sdkconfig.defaults.esp32s2 contain all of these settings.
You can append these to the end of your project’s own sdkconfig file to merge the settings, but please read the
documentation for each setting first.
Task Priorities As ESP-IDF FreeRTOS is a real-time operating system, it’s necessary to ensure that high
throughput or low latency tasks are granted a high priority in order to run immediately. Priority is set when calling
xTaskCreate() or xTaskCreatePinnedToCore() and can be changed at runtime by calling vTaskPri-
oritySet().
It’s also necessary to ensure that tasks yield CPU (by calling vTaskDelay(), sleep(), or by blocking on
semaphores, queues, task notifications, etc) in order to not starve lower priority tasks and cause problems for the
overall system. The Task Watchdog Timer provides a mechanism to automatically detect if task starvation happens,
however note that a Task WDT timeout does not always indicate a problem (sometimes the correct operation of the
firmware requires some long-running computation). In these cases tweaking the Task WDT timeout or even disabling
the Task WDT may be necessary.
Built-In Task Priorities ESP-IDF starts a number of system tasks at fixed priority levels. Some are automatically
started during the boot process, some are started only if the application firmware initializes a particular feature. To
optimize performance, structure application task priorities so that they are not delayed by system tasks, while also
not starving system tasks and impacting other functions of the system.
This may require splitting up a particular task. For example, perform a time-critical operation in a high priority task
or an interrupt handler and do the non-time-critical part in a lower priority task.
Header components/esp_system/include/esp_task.h contains macros for the priority levels used for built-in ESP-IDF
tasks system.
Common priorities are:
• Main task that executes app_main function has minimum priority (1).
• High Resolution Timer system task to manage timer events and execute callbacks has high priority (22,
ESP_TASK_TIMER_PRIO)
• FreeRTOS Timer Task to handle FreeRTOS timer callbacks is created when the scheduler initializes and has
minimum task priority (1, configurable).
• Event Handling system task to manage the default system event loop and execute callbacks has high
priority (20, ESP_TASK_EVENT_PRIO). This configuration is only used if the application calls
esp_event_loop_create_default(), it’s possible to call esp_event_loop_create() with
a custom task configuration instead.
• lwIP TCP/IP task has high priority (18, ESP_TASK_TCPIP_PRIO).
• Wi-Fi Driver task has high priority (23).
Espressif Systems 1442
Submit Document Feedback
Release v4.4