You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ESP32 pin mask template breaking some SPI devices #1040
I've run into a strange issue where setting the clock pin of any SPI LED chipset to any GPIO < 32 crashes my SPI ethernet when calling FastLED.show(). Setting clock pin >= 32 or using clockless LEDs works fine.
I have a W5500 ethernet adapter on the VSPI bus, using Paul Stroffregen's standard Ethernet library. When I set the clock pin to any GPIO < 32, the link status of the W5500 phy goes haywire (false negatives and false positives). This happens regardless of what speed I set the SPI LEDs to, 1-24mhz. If I comment out FastLed.Show() in the main task I don't get the issue.
This issue occurs using the standard RMT driver, @hpwit's I2S driver, or @samguyer's brand new clockless driver with IRAM. Forcing software SPI doesn't fix the issue.
Modifying line 32 of fastpin_esp32.h to exclude the specific GPIO < 32 I have the clock on fixes the issue with my ethernet, but breaks the LED's functionality:
@fifthclassdesigns That's very strange. I'm not aware of any specific issues with pins less than 32. On the ESP32, you should be careful using pins 34-39 because they are designated by the hardware as input-only.
@samguyer There's actually no crash/backtrace log, the ethernet phy just goes nuts when the APA clock pin is set to < 32 and show() is called--it pings back and forth between thinking the ethernet link is connected/disconnected. If I remove show() from my code, the ethernet behaves normally.
The ethernet also works normally when clock pin = 32 or pin = 33, and when using clockless LEDs. Makes sense on 34-39, I'm not using them. I can post a scope trace if that's helpful?
Hmmm. When the situation occurs on different kinds of strips and different
drivers, my inclination is to look at what the *other* library is doing.
Another thing you could try is pushing FastLED show to the other core. Do
you know how to do that?
Thanks for your help Sam--I've tried running FastLED show on both 0 and 1, and unfortunately there's no difference. The example code I linked above has ethernet handling on 0 and FastLED on 1. To clarify, the situation occurs no matter which FastLED driver I use, with any SPI LED chipset.
Does it make sense that FastLED's different handling of bit masking for pins < 32 vs pins >= 32 could contribute to this? The bitwise operations happening in fastpin_esp32.h are above my pay grade, but given that modifying the one on line 32 to exclude the clock pin I'm using fixes the ethernet (albiet breaking the LEDs), it seems related?
For reference, the ethernet library I'm using is the standard Arduino ethernet library (v2). The link status handling code in the library is pretty straightforward. It starts an SPI transaction, reads a register, ends the SPI transaction, and returns the phy status.
At the moment, when clock pin < 32 and FastLED.show() is called, the link status flips back and forth between LINK_ON and LINK_OFF roughly every second because the register bit call (readPHYCFGR_W5500()) returns 000000 once every 100ish calls when it shouldn't. So I think FastLED.show() is potentially interrupting the call to the register and causing it to erroneously return 000000? This doesn't happen when I set clock pin to 32 or 33.
Here's the relevant code from that library with my comments added:
SPI.beginTransaction(20000000, MSBFIRST, SPI_MODE0); // start SPI transaction at 20MHz, CPOL = 0 & CPHA = 0
phystatus = readPHYCFGR_W5500(); // read PHY Configuration register, default: 10111XXX. Returns 100000 when not connected, 11111111 when connected
SPI.endTransaction(); // end SPI transaction
if (phystatus & 0x01) return LINK_ON;
return LINK_OFF;
I'd recommend posting a question on the FastLED Subreddit to see if anyone else has input or advice. If it's a standard library, I'm guessing that others have used it successfully. Maybe there's some special trick to get them to work together.
Hello I have had a look at it couple of weeks ago and what bothers me is the TOGGLE function linked with the ‘clock’ when using ´spi’ on the esp32. Which is not really SPI ;) I will try to free sometime to look at it with the scope
Thanks @samguyer. I posted there a few weeks ago and Yves mentioned that pins < 32 were handled differently than >= 32 on the ESP32, which is how I got started on this.
@hpwit, that makes sense given that modifying the if statement in the toggle function in the fastpin file to include the clock pin I'm using fixes the issue with the ethernet PHY (but breaks the LEDs). Let me know how I can help, happy to post scope traces of the line etc.
@fifthclassdesigns and @hpwit The toggle function could be an issue for clocked strips, but not for clockless strips. The RMT driver, for example, just loads up the buffer and the RMT peripheral does all the signal generation on the pins.
@samguyer Ok, makes sense. This situation only occurs when using clocked strips, so that seems to track.
I see that toggle is being used to avoid adjacent write opcodes to the same register, is possible the CLOCK_HI_DELAY/CLOCK_LOW_DELAY timing might be handled differently internally by GPIO.out vs GPIO.out1?
Ok, I reverted the relevant section of bitbang header file to this code and the issue is fixed for me.
@samguyer I realize this is a pretty niche issue, but is there any documentation you know of on FastLED's use of toggle to make sure the compiler isn't optimizing out two consecutive high calls to the same register? I see a commit adding it, but nothing else.
Activity
samguyer commentedon Jun 15, 2020
@fifthclassdesigns That's very strange. I'm not aware of any specific issues with pins less than 32. On the ESP32, you should be careful using pins 34-39 because they are designated by the hardware as input-only.
Can you give me a backtrace for the crash?
fifthclassdesigns commentedon Jun 15, 2020
@samguyer There's actually no crash/backtrace log, the ethernet phy just goes nuts when the APA clock pin is set to < 32 and show() is called--it pings back and forth between thinking the ethernet link is connected/disconnected. If I remove show() from my code, the ethernet behaves normally.
The ethernet also works normally when clock pin = 32 or pin = 33, and when using clockless LEDs. Makes sense on 34-39, I'm not using them. I can post a scope trace if that's helpful?
samguyer commentedon Jun 15, 2020
fifthclassdesigns commentedon Jun 15, 2020
Thanks for your help Sam--I've tried running FastLED show on both 0 and 1, and unfortunately there's no difference. The example code I linked above has ethernet handling on 0 and FastLED on 1. To clarify, the situation occurs no matter which FastLED driver I use, with any SPI LED chipset.
Does it make sense that FastLED's different handling of bit masking for pins < 32 vs pins >= 32 could contribute to this? The bitwise operations happening in fastpin_esp32.h are above my pay grade, but given that modifying the one on line 32 to exclude the clock pin I'm using fixes the ethernet (albiet breaking the LEDs), it seems related?
For reference, the ethernet library I'm using is the standard Arduino ethernet library (v2). The link status handling code in the library is pretty straightforward. It starts an SPI transaction, reads a register, ends the SPI transaction, and returns the phy status.
At the moment, when clock pin < 32 and FastLED.show() is called, the link status flips back and forth between LINK_ON and LINK_OFF roughly every second because the register bit call (readPHYCFGR_W5500()) returns 000000 once every 100ish calls when it shouldn't. So I think FastLED.show() is potentially interrupting the call to the register and causing it to erroneously return 000000? This doesn't happen when I set clock pin to 32 or 33.
Here's the relevant code from that library with my comments added:
samguyer commentedon Jun 15, 2020
I'd recommend posting a question on the FastLED Subreddit to see if anyone else has input or advice. If it's a standard library, I'm guessing that others have used it successfully. Maybe there's some special trick to get them to work together.
hpwit commentedon Jun 16, 2020
Hello I have had a look at it couple of weeks ago and what bothers me is the TOGGLE function linked with the ‘clock’ when using ´spi’ on the esp32. Which is not really SPI ;) I will try to free sometime to look at it with the scope
fifthclassdesigns commentedon Jun 16, 2020
Thanks @samguyer. I posted there a few weeks ago and Yves mentioned that pins < 32 were handled differently than >= 32 on the ESP32, which is how I got started on this.
@hpwit, that makes sense given that modifying the if statement in the toggle function in the fastpin file to include the clock pin I'm using fixes the issue with the ethernet PHY (but breaks the LEDs). Let me know how I can help, happy to post scope traces of the line etc.
samguyer commentedon Jun 16, 2020
@fifthclassdesigns and @hpwit The toggle function could be an issue for clocked strips, but not for clockless strips. The RMT driver, for example, just loads up the buffer and the RMT peripheral does all the signal generation on the pins.
fifthclassdesigns commentedon Jun 16, 2020
@samguyer Ok, makes sense. This situation only occurs when using clocked strips, so that seems to track.
I see that toggle is being used to avoid adjacent write opcodes to the same register, is possible the CLOCK_HI_DELAY/CLOCK_LOW_DELAY timing might be handled differently internally by GPIO.out vs GPIO.out1?
fifthclassdesigns commentedon Jun 16, 2020
It seems the waveform generated is different with clock on pin 2 vs pin 32/33
And it looks like when clock pin < 32 my ethernet CS pin is dropping data (?)
No issues on pin 32 or 33
fifthclassdesigns commentedon Jun 18, 2020
Ok, I reverted the relevant section of bitbang header file to this code and the issue is fixed for me.
@samguyer I realize this is a pretty niche issue, but is there any documentation you know of on FastLED's use of toggle to make sure the compiler isn't optimizing out two consecutive high calls to the same register? I see a commit adding it, but nothing else.