I would like to be able stop the ULP timer from within a ULP program just before I wake the system so as to prevent the ULP from running until I want to again start the ULP and go into deep sleep again.
I asked about this before and you referred me to ulp.c wherein is defined ulp_run(), ulp_load_binary() and ulp_set_wakeup_period(). Almost immediately after waking the system in a test program I have running, I call ulp_run() (as part of the sequence that restarts the ULP), which first disables the ULP sleep timer and then, as it's last call, re-enables the ULP sleep timer. This works great.
But as I said, I'd like to be able to disable the ULP timer after issuing the wake and halt ULP instructions so as to keep the ULP from running while doing a pile of work in system code before starting the ULP again.
I have tried using the "reg_wr 0x006, 24, 24, 0", which, according to all the docs I've read, should reset the RTC_CNTL_ULP_CP_SLE_TIMER_EN bit in the RTC_CNTL_STATE0_REG register. However, when I call that instruction, the ULP never causes the system to wake. It never goes through the system reset cycle as it should after the wake instruction.
Does "reg_wr 0x006, 24, 24, 0" target the that timer enable bit? If so, is there something illegal about killing the ULP timer from within a ULP program? If not, what instruction and parameters would stop the timer? And if it's illegal to stop the timer from within the ULP, what other instruction might I use to prevent the ULP from running after I issue the wake and halt instructions until I want to start the ULP from the system again?
Question about the WR_REG ULP instruction
Re: Question about the WR_REG ULP instruction
Do you do WAKE, REG_WR, HALT in that order? Did you try like this https://github.com/espressif/esp-iot-so ... #L234-L237
Don't post a new topic for everything just continue your old topics.
Don't post a new topic for everything just continue your old topics.
Re: Question about the WR_REG ULP instruction
OK, sorry for the new post for each question. This is an add on.
I did what you suggested, changing the order of the calls, and it worked. I then substituted in the instruction I'd first tried, "reg_wr 0x006, 24, 24, 0", at the new location, and it worked too. Thanks.
Another question: The code I'm using in my minimal test program to get in and out of the ULP is:
This mostly works. However, the expected 5 second delay does not occur after the ulp_run() call before ULP code starts executing. I know that the SENS_ULP_CP_SLEEP_CYC0_REG is correctly set because when I invoke a halt instruction within the ULP code, it delays for ~5 seconds nicely and restarts at the entry: label just as intended.
I am calling the ULP startup calls in exactly the same order as in the example "ulp_example_main.c", but organized a bit differently such that I halt the ULP and reset the RTC_CNTL_ULP_CP_SLP_TIMER_EN bit just after I "wake" and before I "halt" (as in my last post above.) I call ulp_run() every time I start the ULP, and the example calls it only once. I do it because I want that delay when i start the ULP.
I can work around this by issuing a halt instruction on entry to the ULP, but I'd like to understand what's going on here. Why am I not getting a delay based on the value in SENS_ULP_CP_SLEEP_CYC0_REG when I start the ULP?
I did what you suggested, changing the order of the calls, and it worked. I then substituted in the instruction I'd first tried, "reg_wr 0x006, 24, 24, 0", at the new location, and it worked too. Thanks.
Another question: The code I'm using in my minimal test program to get in and out of the ULP is:
- void InitializeULP()
- {
- ulp_load_binary(0, bin_start, (bin_end - bin_start) / sizeof(uint32_t));
- ulp_set_wakeup_period( 0, 5000000 ); // Set timer for 5 second delay
- }
- void StartULPandGoIntoDeepSleep()
- {
- ulp_run((&ulp_entry - RTC_SLOW_MEM) / sizeof(uint32_t));
- esp_sleep_enable_ulp_wakeup();
- esp_deep_sleep_start();
- }
- void app_main()
- {
- if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_ULP) // This block should run just once
- {
- InitializeULP();
- }
- StartULPandGoIntoDeepSleep();
- }
I am calling the ULP startup calls in exactly the same order as in the example "ulp_example_main.c", but organized a bit differently such that I halt the ULP and reset the RTC_CNTL_ULP_CP_SLP_TIMER_EN bit just after I "wake" and before I "halt" (as in my last post above.) I call ulp_run() every time I start the ULP, and the example calls it only once. I do it because I want that delay when i start the ULP.
I can work around this by issuing a halt instruction on entry to the ULP, but I'd like to understand what's going on here. Why am I not getting a delay based on the value in SENS_ULP_CP_SLEEP_CYC0_REG when I start the ULP?
Re: Question about the WR_REG ULP instruction
I don't know but I mentioned it here https://esp32.com/viewtopic.php?f=13&t=12523#p49980 It could be that the timer is not reset when it is enabled.
Re: Question about the WR_REG ULP instruction
Is there any documentation on the ULP assembler other than the instruction set that appears in both "Read The Docs" and the TRF? In particular, I'd like to know what assembler directives the assembler knows about. I was surprised to find that it it took the .macro directive and a few others that I found in the ULP examples. I've also found that .set, which I've used in other assemblers, works. What else is in there?
Who is online
Users browsing this forum: Bing [Bot] and 127 guests