Chapter 4. API Guides
6. Generate a list of global symbols (ulp_app_name.sym) in the ELF file using riscv32-esp-
elf-nm.
7. Create an LD export script and header file (ulp_app_name.ld and ulp_app_name.h) con-
taining the symbols from ulp_app_name.sym. This is done using the esp32ulp_mapgen.py
utility.
8. Add the generated binary to the list of binary files to be embedded into the application.
4.29.3 Accessing the ULP-RISC-V Program Variables
Global symbols defined in the ULP-RISC-V program may be used inside the main program.
For example, the ULP-RISC-V program may define a variable measurement_count which will define the num-
ber of ADC measurements the program needs to make before waking up the chip from deep sleep
volatile int measurement_count;
int some_function()
{
//read the measurement count for use it later.
int temp = measurement_count;
...do something.
}
The main program can access the global ULP-RISC-V program variables, the build system makes this possible
by generating the ${ULP_APP_NAME}.h and ${ULP_APP_NAME}.ld files which define the global symbols
present in the ULP program. Each global symbol defined in the ULP program is included in these files and are
prefixed with ulp_.
The header file contains the declaration of the symbol
extern uint32_t ulp_measurement_count;
Note that all symbols (variables, arrays, functions) are declared as uint32_t. For functions and arrays, take the
address of the symbol and cast it to the appropriate type.
The generated linker script file defines the locations of symbols in RTC_SLOW_MEM:
PROVIDE ( ulp_measurement_count = 0x50000060 );
To access the ULP-RISC-V program variables from the main program, the generated header file should be included
using an include statement. This will allow the ULP program variables to be accessed as regular variables
#include "ulp_app_name.h"
void init_ulp_vars() {
ulp_measurement_count = 64;
}
4.29.4 Starting the ULP-RISC-V Program
To run a ULP-RISC-V program, the main application needs to load the ULP program into RTC memory using the
ulp_riscv_load_binary() function, and then start it using the ulp_riscv_run() function.
Note that CONFIG_ESP32S2_ULP_COPROC_ENABLED and CONFIG_ESP32S2_ULP_COPROC_RISCV options
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-RISC-V program is embedded into the ESP-IDF application as a binary blob. The application can refer-
ence this blob and load it in the following way (suppose ULP_APP_NAME was defined to ulp_app_name)
Espressif Systems 1501
Submit Document Feedback
Release v4.4