ESP32S3 FSM ULP Code Question
Posted: Tue Feb 11, 2025 3:08 pm
Hi all,
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
However, if want to run the counter up to 100 and then enter an infinite loop the counter stops at 1. why?
Why doesn't it branch to M_BX(0) when R0 is less than 100, increment the counter by, repeat until R0 = 100 and then do an infinite loop M_LABEL(3), M_BX(3)?
For reference, here's the entire Arduino code:
Thanks a lot in advance!
dmy
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