Chapter 4. API Guides
Note: Because some of the instruction macros expand to inline function calls, defining such array in global scope
will cause the compiler to produce an"initializer element is not constant" error. To fix this error, move the definition
of instructions array into local scope.
Load and store instructions use addresses expressed in 32-bit words. Address 0 corresponds to the first word of
RTC_SLOW_MEM (which is address 0x50000000 as seen by the main CPUs).
To generate branch instructions, special M_ preprocessor defines are used. M_LABEL define can be used to define a
branch target. Label identifier is a 16-bit integer. M_Bxxx defines can be used to generate branch instructions with
target set to a particular label.
Implementation note: these M_ preprocessor defines will be translated into two ulp_insn_t values: one is a token
value which contains label number, and the other is the actual instruction. ulp_process_macros_and_load
function resolves the label number to the address, modifies the branch instruction to use the correct address, and
removes the the extra ulp_insn_t token which contains the label numer.
Here is an example of using labels and branches:
const ulp_insn_t program[]
I_MOVI(R0, 34),
M_LABEL(1),
I_MOVI(R1, 32),
I_LD(R1, R1, 0),
I_MOVI(R2, 33),
I_LD(R2, R2, 0),
I_SUBR(R3, R1, R2),
I_ST(R3, R0, 0),
I_ADDI(R0, R0, 1),
M_BL(1, 64),
I_HALT(),
};
RTC_SLOW_MEM[32]
=
42;
RTC_SLOW_MEM[33]
=
18;
size_t load_addr
=
0;
size_t size
=
sizeof(program)/sizeof(ulp_insn_t);
ulp_process_macros_and_load(load_addr, program, &size);
ulp_run(load_addr);
Application Example
Demonstration of entering into deep sleep mode and waking up using several wake up sources: system/deep_sleep.
API Reference
Header File
•
ulp/include/esp32s2/ulp.h
Functions
esp_err_t
ulp_process_macros_and_load(uint32_t load_addr, const ulp_insn_t *program, size_t
Resolve all macro references in a program and load it into RTC memory.
Return
• ESP_OK on success
• ESP_ERR_NO_MEM if auxiliary temporary structure can not be allocated
• one of ESP_ERR_ULP_xxx if program is not valid or can not be loaded
Parameters
Espressif Systems
=
{
//
R0
<-
34
//
label_1
//
R1
<-
32
//
R1
<-
RTC_SLOW_MEM[R1]
//
R2
<-
33
//
R2
<-
RTC_SLOW_MEM[R2]
//
R3
<-
R1
-
R2
//
R3
->
RTC_SLOW_MEM[R0
// R0++
//
if
(R0
<
64) goto label_1
*psize)
1492
Submit Document Feedback
+
0]
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?
Questions and answers