Stopping ULP & ULP Lockup

User avatar
RalimTEk
Posts: 9
Joined: Wed Oct 10, 2018 12:40 am

Stopping ULP & ULP Lockup

Postby RalimTEk » Mon Feb 18, 2019 4:31 am

Hi,

I have been running into a strange issue on some of my esp32 units (all rev1).
I use a small ULP task to read two ADC inputs, and also to control some LED indicators.

Sometimes after an esp_reset() call, the ULP keeps running (which in itself might be okay), however when the code starts up and tries to reload the code into the ULP (RTC Slow mem), sometimes the ULP doesn't start running at all even when the timer is started. Also had some cases where the ULP does keep running, but it appears to be running really slow (blinking a light goes at half speed).

The code flow is :

  • Move led state by 1 and decode to on/off state
  • Take 2 adc measurements
  • store adc measurements to ram
  • halt
I cannot find any way to turn OFF the timer that runs the ULP, so I cannot stop it before a restart.
Also I have not found any reliable method to recover from a "crashed" ULP / one that is running slow. calling esp_reset repeatedly sometimes unsticks it after a few iterations but sometimes it never unsticks.

What are methods to recover from this situation?
I have tried hacks such as zero'ing out the slow ram before loading the ulp code, but this doesnt seem to improve things.

Power cycling the esp is not an option at this point, so I am open to any software methods to reset the ULP block / unstick this unit.
--//--
Ralimtek.com

boarchuz
Posts: 376
Joined: Tue Aug 21, 2018 5:28 am

Re: Stopping ULP & ULP Lockup

Postby boarchuz » Mon Feb 18, 2019 6:14 am

At the end of https://docs.espressif.com/projects/esp ... s/ulp.html :
To disable the timer (effectively preventing the ULP program from running again), clear the RTC_CNTL_ULP_CP_SLP_TIMER_EN bit in the RTC_CNTL_STATE0_REG register. This can be done both from ULP code and from the main program.
Give that a shot. Another option, if your preference was to preserve the ULP running on reset, might be to have the ULP program 'flag' that it's still running. eg. ULP sets global variable to 0 every loop; meanwhile, when main processor boots, this global variable is set to 1, then waits for it to be set back to 0 by ULP if running; if it times out waiting for the flip, assume ULP isn't running->start ULP. (I'd definitely be using the proper way over this hack though.)

User avatar
RalimTEk
Posts: 9
Joined: Wed Oct 10, 2018 12:40 am

Re: Stopping ULP & ULP Lockup

Postby RalimTEk » Mon Feb 18, 2019 10:06 pm

boarchuz wrote:
Mon Feb 18, 2019 6:14 am
At the end of https://docs.espressif.com/projects/esp ... s/ulp.html :
To disable the timer (effectively preventing the ULP program from running again), clear the RTC_CNTL_ULP_CP_SLP_TIMER_EN bit in the RTC_CNTL_STATE0_REG register. This can be done both from ULP code and from the main program.
Give that a shot. Another option, if your preference was to preserve the ULP running on reset, might be to have the ULP program 'flag' that it's still running. eg. ULP sets global variable to 0 every loop; meanwhile, when main processor boots, this global variable is set to 1, then waits for it to be set back to 0 by ULP if running; if it times out waiting for the flip, assume ULP isn't running->start ULP. (I'd definitely be using the proper way over this hack though.)
My problem is that the ULP is still Running but simultaneously not. Disabling and re-enabling the timer does not clear the issue, and even repeatedly doing this with delays in between (100ms), the ULP never starts running again.

I have already been trying this without any improvement to the failure modes. Also forcing RTC domain power down (and then delay and release) also does not unstick this issue.

Edit: I do not want the ULP to keep running over reboots, but it does, and the esp_reset does not appear to stop it.
--//--
Ralimtek.com

colman
Posts: 33
Joined: Mon May 30, 2016 7:41 am

Re: Stopping ULP & ULP Lockup

Postby colman » Fri Mar 01, 2019 6:16 am

I have the same issue, I want to know how to stop a running ULP.

Colman

elshnkhll
Posts: 1
Joined: Thu Feb 18, 2021 2:22 pm

Re: Stopping ULP & ULP Lockup

Postby elshnkhll » Thu Feb 18, 2021 2:28 pm

:idea: I think I will try giving it HALT command as a fist instruction and calling ulp_run() again, when I got a spare time. Let me know if someone have already tried it.

boarchuz
Posts: 376
Joined: Tue Aug 21, 2018 5:28 am

Re: Stopping ULP & ULP Lockup

Postby boarchuz » Thu Feb 18, 2021 4:52 pm

I ended up running into this too when I implemented OTA (with the ULP running) and the subsequent esp_reset() left all RTC peripherals (including ULP) in an undefined and possibly unrecoverable state.

I think this is a pretty serious flaw with the soft reset that should at least carry a clear warning. And hopefully all IDF initialisation does not assume registers are in default states on "reset".

After giving up on an elegant fix I decided to add a little check to the bootloader to catch any reset causes that might avoid the RTC domain, and trigger an immediate RTC_WDT to ensure everything is completely reset to defaults.

Who is online

Users browsing this forum: Google [Bot], Pedrojdi and 40 guests