EasyManuals Logo

Espressif ESP32-S2 User Manual

Espressif ESP32-S2
1695 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #1509 background imageLoading...
Page #1509 background image
Chapter 4. API Guides
Note that the ULP program can only use lower 16 bits of each 32-bit word in RTC memory, because the registers
are 16-bit, and there is no instruction to load from the high part of the word.
Likewise, the ULP store instruction writes register value into the lower 16 bits part of the 32-bit word. The upper
16 bits are written with a value which depends on the address of the store instruction, thus when reading variables
written by the ULP, the main application needs to mask the upper 16 bits, e.g.:
printf("Last measurement value: %d\n", ulp_last_measurement & UINT16_MAX);
4.28.6 Starting the ULP Program
To run a ULP program, the main application needs to load the ULP program into RTC memory using the
ulp_load_binary function, and then start it using the ulp_run function.
Note thatEnable Ultra Low Power (ULP) Coprocessoroption must be enabled in menuconfig to reserve memory
for the ULP. RTC slow memory reserved for coprocessoroption must be set to a value sufficient to store ULP
code and data. If the application components contain multiple ULP programs, then the size of the RTC memory
must be sufficient to hold the largest one.
Each ULP program is embedded into the ESP-IDF application as a binary blob. The application can reference this
blob and load it in the following way (suppose ULP_APP_NAME was defined to ulp_app_name):
extern const uint8_t bin_start[] asm("_binary_ulp_app_name_bin_start");
extern const uint8_t bin_end[] asm("_binary_ulp_app_name_bin_end");
void start_ulp_program() {
ESP_ERROR_CHECK( ulp_load_binary(
0 /* load address, set to 0 when using default linker scripts */,
bin_start,
(bin_end - bin_start) / sizeof(uint32_t)) );
}
esp_err_t ulp_load_binary(uint32_t load_addr, const uint8_t *program_binary, size_t pro-
gram_size)
Load ULP program binary into RTC memory.
ULP program binary should have the following format (all values little-endian):
1. MAGIC, (value 0x00706c75, 4 bytes)
2. TEXT_OFFSET, offset of .text section from binary start (2 bytes)
3. TEXT_SIZE, size of .text section (2 bytes)
4. DATA_SIZE, size of .data section (2 bytes)
5. BSS_SIZE, size of .bss section (2 bytes)
6. (TEXT_OFFSET - 12) bytes of arbitrary data (will not be loaded into RTC memory)
7. .text section
8. .data section
Linker script in components/ulp/ld/esp32.ulp.ld produces ELF files which correspond to this format. This
linker script produces binaries with load_addr == 0.
Return
ESP_OK on success
ESP_ERR_INVALID_ARG if load_addr is out of range
ESP_ERR_INVALID_SIZE if program_size doesnt match (TEXT_OFFSET + TEXT_SIZE +
DATA_SIZE)
ESP_ERR_NOT_SUPPORTED if the magic number is incorrect
Parameters
load_addr: address where the program should be loaded, expressed in 32-bit words
program_binary: pointer to program binary
program_size: size of the program binary
Espressif Systems 1498
Submit Document Feedback
Release v4.4

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Espressif ESP32-S2 and is the answer not in the manual?

Espressif ESP32-S2 Specifications

General IconGeneral
BrandEspressif
ModelESP32-S2
CategorySingle board computers
LanguageEnglish