Setting and resetting pin state in ULP mode does not work
Posted: Mon Dec 05, 2022 12:20 pm
I am relatively new to programming the ESP32. Currently, I am trying to toggle GPIO pin number 25 in the ULP mode (RTC IO pin 6), but I am failing. It would help me a lot if someone pointed out my mistakes.
In the main program, I initialize the gpio pin 25 as an output pin and enter the ULP mode.
The cycle time of the ULP is 1 second.
The assembly code that runs in the ULP mode is given below.
Thank you for your time.
In the main program, I initialize the gpio pin 25 as an output pin and enter the ULP mode.
The cycle time of the ULP is 1 second.
The assembly code that runs in the ULP mode is given below.
Code: Select all
#include "soc/rtc_cntl_reg.h"
#include "soc/rtc_io_reg.h"
#include "soc/soc_ulp.h"
/* Define variables, which go into .bss section (zero-initialized data) */
.bss
.global pinState
pinState:
.long 0
/* Code goes into .text section */
.text
.global entry
entry:
/* Check current pin state */
move r2, pinState
ld r1, r2, 0
add r1, r1, 1
st r1, r2, 0
and r1, r1, 1
jump reset_pin, eq
jump set_pin
set_pin:
WRITE_RTC_REG(RTC_IO_PAD_DAC1_REG, RTC_IO_PDAC1_HOLD_S, 1, 0)
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG,RTC_GPIO_OUT_DATA_W1TS_S + 6, 1, 1)
WRITE_RTC_REG(RTC_IO_PAD_DAC1_REG, RTC_IO_PDAC1_HOLD_S, 1, 1)
jump wake_up
reset_pin:
WRITE_RTC_REG(RTC_IO_PAD_DAC1_REG, RTC_IO_PDAC1_HOLD_S, 1, 0)
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG,RTC_GPIO_OUT_DATA_W1TS_S + 6, 1, 0)
WRITE_RTC_REG(RTC_IO_PAD_DAC1_REG, RTC_IO_PDAC1_HOLD_S, 1, 1)
jump wake_up
wake_up:
/* Check if the system can be woken up */
READ_RTC_FIELD(RTC_CNTL_LOW_POWER_ST_REG, RTC_CNTL_RDY_FOR_WAKEUP)
and r0, r0, 1
jump wake_up, eq
/* Wake up the SoC, end program */
wake
halt