I have a question regarding my ESP32S3 FSM ULP program. This one here works, when I periodically read out address 130 in the Arduino code I can see the counter increasing
Code: Select all
const ulp_insn_t ulp_prog[] = {
M_LABEL(0),
I_MOVI(R1, 130),
I_LD(R0, R1, 0),
I_ADDI(R0, R0, 1),
I_ST(R0, R1, 0),
M_BX(0)
};
Code: Select all
const ulp_insn_t ulp_prog[] = {
M_LABEL(0),
I_MOVI(R1, 130),
I_LD(R0, R1, 0),
I_ADDI(R0, R0, 1),
I_ST(R0, R1, 0),
I_BL(3, 100),
M_LABEL(3),
M_BX(3),
M_BX(0)
};
For reference, here's the entire Arduino code:
Code: Select all
#include "esp32s3/ulp.h"
#include "ulp_common.h"
// Define the ULP program
const ulp_insn_t ulp_prog[] = {
M_LABEL(0),
I_MOVI(R1, 130),
I_LD(R0, R1, 0),
I_ADDI(R0, R0, 1),
I_ST(R0, R1, 0),
I_BL(3, 100),
M_LABEL(3),
M_BX(3),
M_BX(0)
};
void setup() {
Serial.begin(115200);
// Initialize ULP
size_t prog_size = sizeof(ulp_prog) / sizeof(ulp_insn_t);
ESP_ERROR_CHECK(ulp_process_macros_and_load(0, ulp_prog, &prog_size));
// Start ULP program
ESP_ERROR_CHECK(ulp_run(0));
// Initialize counter to 0
RTC_SLOW_MEM[130] = 0;
}
void loop() {
// Read counter value
uint32_t counter = RTC_SLOW_MEM[130];
Serial.printf("Counter value: %ld\n", counter);
delay(1000); // Wait for 1 second before next read
}
dmy