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

rp2pio: Transfer up to 32 bytes before checking background tasks #4155

Merged
merged 1 commit into from
Feb 8, 2021

Conversation

jepler
Copy link
Member

@jepler jepler commented Feb 8, 2021

@jerryneedell noticed that this problem affected strips short enough to not use the DMA peripheral, thanks for the hot tip!

Instead of checking for background tasks after every byte transfer, try up to 32 transfers before attending to background tasks.

This fixes the problem I was seeing on my 5-pixel circuit.

Closes #4135.

I wrote this before seeing the simpler #4149. I think this MAY be a bit better than #4149, and here's why: Occasionally, background tasks and interrupts can immediately create new background tasks. This PR would ensure that up to 32 bytes were made available to the PIO peripheral before attending to them, while that one doesn't.

@jerryneedell noticed that this problem affected strips short enough
to not use the DMA peripheral, thanks for the hot tip!

Instead of checking for background tasks after every byte transfer,
try up to 32 transfers before attending to background tasks.

This fixes the problem I was seeing on my 5-pixel circuit.

Closes adafruit#4135.
@jerryneedell
Copy link
Collaborator

Thanks -- I'll try this later today -- Credit goes to @gamblor21 for finding the DMA link to this issue.

@ladyada
Copy link
Member

ladyada commented Feb 8, 2021

good teamwork - amazing!

@dhalbert dhalbert requested a review from tannewt February 8, 2021 16:22
@gamblor21
Copy link
Member

I agree yours is a better implementation. I did not want to remove the background tasks all together as I wasn't sure of any potential side effects.

@jerryneedell
Copy link
Collaborator

Sorry to report this still not working for me.

using a 7 pixel jewel:

dafruit CircuitPython 6.2.0-beta.1-128-g5423e4966 on 2021-02-08; Raspberry Pi Pico with rp2040

>>> from board import *
>>> import neopixel
>>> import time
>>>  
>>> pixpin = GP27
>>> numpix = 7
>>>  
>>> strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.3)
>>> strip.fill(0)
>>> strip.fill(0xff)
>>> strip.fill(0xff00)
>>> strip.fill(0xff0000)
>>> 
```  after the last write, pixel 0 is green -- all others are red....

@jerryneedell
Copy link
Collaborator

also ```Adafruit CircuitPython 6.2.0-beta.1-128-g5423e4966 on 2021-02-08; Raspberry Pi Pico with rp2040

from digitalio import *
from board import *
import neopixel
import time

pixpin = GP27
numpix = 7

strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.3)
strip.fill(0)
strip[0]=0xff
strip[0]=0xff00
strip[1]=0xff00
strip[1]=0xff
strip[0]=0xff
strip[0]=0xff00

pixel 0 is not responding properly.

@jerryneedell
Copy link
Collaborator

hmm -- I had an "Airlift" connected to the Pi - it was not being used, but now that I have disconnected it, I am so far not able to reproduce the issues -- more testing to do....

@jerryneedell
Copy link
Collaborator

I have been unable to reproduce the issue with the Airlift disconnected....

@jerryneedell
Copy link
Collaborator

To be fair, I had more that just the Airlift connected.
I had the following connected:
ARILIFT -- lots of pins near the pin used for the neopixel
10Kpullups on SDA.SCL (GP0,GP1) - were for a previous test
pushbutton from RUN to GND -- to facilitate entering bootloader.

I have not determined which was the culprit...yet ... I just assumed it was the Airlift -- perhaps hastily.

With just the bare Pico -- my "jewel" is behaving very normally with this PR.

@jepler
Copy link
Member Author

jepler commented Feb 8, 2021

@jerryneedell let's talk about this in the discord meeting today

@dhalbert dhalbert mentioned this pull request Feb 8, 2021
@jerryneedell
Copy link
Collaborator

Tested with #4160 -- both are working for me.

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested by @jerryneedell and @gamblor21.

@dhalbert dhalbert merged commit b0ed258 into adafruit:main Feb 8, 2021
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One suggestion to simplify things. (I realize I'm a bit late. Thanks for fixing this!)

--rx_remaining;
did_transfer = true;
}
if (!did_transfer) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be clearer if you replaced the original if statements with while loops. That way you'd load up the 4 or 8 entry FIFO and then move on. 32 seems arbitrary and I'm skeptical you'd ever hit that many due to the FIFO size.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose 32 because it was the DMA threshold. I didn't check the FIFO size at all! I'll open an issue suggesting the clean-up, but try to get to it next time I'm working in this code.

@jepler jepler deleted the rpi-pio-background branch November 3, 2021 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rp2040 -- neopixels not working properly
6 participants