Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32 LittleFS build PWM GPIO : port#2 is out of range #4962

Closed
TommoT1 opened this issue Feb 4, 2024 · 20 comments · Fixed by #4963
Closed

ESP32 LittleFS build PWM GPIO : port#2 is out of range #4962

TommoT1 opened this issue Feb 4, 2024 · 20 comments · Fixed by #4963
Labels
Type: Bug Considered a bug

Comments

@TommoT1
Copy link

TommoT1 commented Feb 4, 2024

In preparation to move to the LittleFS builds on ESP32 just flashed an ESP32 with with the ESP_Easy_mega_20240202_normal_ESP32_4M316k_LittleFS.factory.bin build.
Then I restored the rules wich only PWM fade the blue GPIO2 led.
On the non LittleFS build this worked fine, now I got the Logmessage:

521118: ACT : PWM,2,40,1500
521129: GPIO : port#2 is out of range

522609: ACT : PWM,2,300,1500
522619: GPIO : port#2 is out of range

524118: ACT : PWM,2,40,1500
524128: GPIO : port#2 is out of range

And the led stays dark.
When I use GPIO,2,0 or GPIO,2,1 instead of PWM it works and the led blinks.....
Is this a bug or what did change regarding PWM?

@TD-er
Copy link
Member

TD-er commented Feb 4, 2024

Hmm I will have a look at it, looks like a bug

@TD-er TD-er added the Type: Bug Considered a bug label Feb 4, 2024
@TD-er
Copy link
Member

TD-er commented Feb 4, 2024

Hmm looks like this recent change may have broken the PWM functionality:
https://github.com/espressif/arduino-esp32/pull/9031/files

@TD-er
Copy link
Member

TD-er commented Feb 4, 2024

When this build has finished, you can test if it is also fixed on your node:
https://github.com/letscontrolit/ESPEasy/actions/runs/7775190734

@TommoT1
Copy link
Author

TommoT1 commented Feb 4, 2024

Incredible fast you are......
Sadly this build stalls my node, I can see it via serial for some seconds, looks as it does PWM again (two PWM Commands without errors) but then it stops talking (about 5 to 6 seconds after reboot)

@TD-er
Copy link
Member

TD-er commented Feb 4, 2024

Hmm I did see a potential bug in the Arduino code for reserving PWM channels.
I did do a quick fix on my end and later tried to revert it to see if it actually is a problem.
However with the original Arduino code I was not able to reproduce the bug as I thought would happen.
But I will try to make a pull request for it to the Arduino repo and try to let Jason2866 make a build for the platform code so we have a fix before it was even merged by the Arduino team.

@TommoT1
Copy link
Author

TommoT1 commented Feb 4, 2024

OK, just in case you need it, this ist the rule what stalls my node:

on System#Boot do LoopTimerSet_ms,1,1500

on Rules#Timer=1 do
if [int#1] = 0
PWM,2,0,1500
let,1,1
else
PWM,2,40,1500
let,1,0
endif
endon

@TD-er
Copy link
Member

TD-er commented Feb 4, 2024

Not 100% sure this will be done correctly, so maybe best to change this first rules line to this:

on System#Boot do 
  LoopTimerSet_ms,1,1500
endon

Anyway, the rest is I think asking for trouble as you try to constantly fade were it may try to update a running fade as the rules are triggered at the same offset (thus no drift) while the execution of the rules may sometimes be slightly delayed.

So in this specific use case, you might be better of not using the loop timer, but rather restart the timer at the end of the rules block:

on System#Boot do 
  TimerSet_ms,1,1500
endon


on Rules#Timer=1 do
  if [int#1] = 0
    PWM,2,0,1500
    let,1,1
  else
    PWM,2,40,1500
    let,1,0
  endif
  timerset_ms,1,2000
endon

And maybe a good idea to not let the fade during be exactly the same as the timer interval.

By the way, on older builds this was completely blocking as the fade command only ended when it was done.
So by running rules like you have, the ESP would not be able to do anything else.

@TommoT1
Copy link
Author

TommoT1 commented Feb 4, 2024

So may be I was just lucky it worked before, was only a fade test...
I'll change it like you showed me.
Thx

@TD-er
Copy link
Member

TD-er commented Feb 4, 2024

Since ESP-IDF5 there is a fade command which is not blocking and it allows to add a callback function.

So a fade loop like this could be done as a background running call, which we could trigger using a command like fadeloop in ESPEasy.

Would that be a desired command?

@TommoT1
Copy link
Author

TommoT1 commented Feb 4, 2024

I use those "breathing" fades sometimes to indicate "normal" operation. So I don't know how much work that is for just am gimmick in my case...
btw. with todays build it also stalls with your changes... :-(

@TD-er
Copy link
Member

TD-er commented Feb 4, 2024

Just to be sure, what is 'stall' ?
What no longer works?

@TommoT1
Copy link
Author

TommoT1 commented Feb 5, 2024

From what I can observe it stops completely.
WebUi not reachable anymore, the time when the other nodes saw it counts up till it gets removed from the list and serial logging stops. No serial commands are taken anymore.

@TommoT1
Copy link
Author

TommoT1 commented Feb 5, 2024

changed the rules, after the 40s timer 2 (to have the chance to get access and stop it from PWM) the node hangs completely
Build: ESP_Easy_mega_20240204_normal_ESP32_4M316k_LittleFS

on System#Boot do
 TimerSet,2,40
 Let,1,0
endon

on Rules#Timer=2 do 
   TimerSet,1,3
endon

on Rules#Timer=1 do 
 if [int#1] = 0
  PWM,2,300,2000
  let,1,1
 else 
  PWM,2,40,2000
  let,1,0
 endif 
 TimerSet,1,3
endon

@TD-er
Copy link
Member

TD-er commented Feb 5, 2024

OK, will check your rules later today as I'm not near a computer right now.

@TD-er
Copy link
Member

TD-er commented Feb 5, 2024

I ran it on an ESP32-C2 and it was running fine for a while.
Now I finally got time to run it on ESP32-classic and indeed it seems to stall completely.
No idea what is happening here.

@TD-er
Copy link
Member

TD-er commented Feb 5, 2024

Found the cause... and made an issue for it: espressif/arduino-esp32#9212

I also have got a work-around and will make a commit for it.

@TommoT1
Copy link
Author

TommoT1 commented Feb 5, 2024

Thank you!

@TD-er
Copy link
Member

TD-er commented Feb 5, 2024

There is still another potential bug in the Arduino code: espressif/arduino-esp32#9213
I tested with the suggested fix of that bug, but the test build doesn't have this.
So please let me know if you do experience issues with it.

Here is the test build (still running) https://github.com/letscontrolit/ESPEasy/actions/runs/7790177773

@TD-er
Copy link
Member

TD-er commented Feb 5, 2024

Hmm it looks like this problem will also cause issues for other use cases, so I will append those to the same pull request.

For example

  • servo functionality will cause issues if you start/stop a servo several times.
  • Switching PWM on the same pin can also cause these deadlocks.

@TommoT1
Copy link
Author

TommoT1 commented Feb 6, 2024

Good morning Gijs!
For me it's working again with your latest fix, the node is "breathing" again.
I'll keep you posted if I find anything.
Thank you!

TD-er added a commit that referenced this issue Feb 9, 2024
[PWM] Fix ESP32 LittleFS build PWM GPIO : port#2 is out of range (#4962)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Considered a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants