Starting The Ulp Program - Espressif ESP32-S2 Programming Manual

Table of Contents

Advertisement

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:

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 that"Enable Ultra Low Power (ULP) Coprocessor"option must be enabled in menuconfig to reserve memory
for the ULP. "RTC slow memory reserved for coprocessor"option 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[]
void start_ulp_program() {
ESP_ERROR_CHECK( ulp_load_binary(
0
/*
load address,
bin_start,
(bin_end
-
bin_start)
}
esp_err_t
ulp_load_binary(uint32_t load_addr, const uint8_t *program_binary, size_t pro-
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 doesn't 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
%d\n", ulp_last_measurement
asm("_binary_ulp_app_name_bin_end");
set
to
0
when using default linker scripts */,
/
sizeof(uint32_t)) );
gram_size)
1498
Submit Document Feedback
&
UINT16_MAX);
Release v4.4

Advertisement

Table of Contents
loading
Need help?

Need help?

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

Questions and answers

Table of Contents

Save PDF