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

Issue 4237 - Changed initial setting in program_struct #4405

Merged
merged 4 commits into from
Mar 16, 2021
Merged

Issue 4237 - Changed initial setting in program_struct #4405

merged 4 commits into from
Mar 16, 2021

Conversation

DavePutz
Copy link
Collaborator

Although I cannot find it documented anywhere; looking at _pio_find_offset_for_program() in sdk/src/rp2_common/hardware_pio/pio.c, it is checking if the program origin is >= 0 and, if so, using that origin to look for space. As a result, with the default origin of 0 then pio_can_add_program() will fail on the second attempt to add a program. This limits CP to only adding one program per PIO. This was the cause of issue #4237, where the third call to rp2pio.StateMachine() would fail. The fix simply changes the default from 0 to -1.

@ladyada
Copy link
Member

ladyada commented Mar 14, 2021

@kevinjwalters please test/review!

@kevinjwalters
Copy link

I've not used the C SDK. The documentation does not state what -1 would do: https://raspberrypi.github.io/pico-sdk-doxygen/group__hardware__pio.html#ga3571e3c7c6e645e92b8d438203a911b9 & https://raspberrypi.github.io/pico-sdk-doxygen/structpio__program.html (this is the matching data structure even though it's missing the _t suffix, the quantity is signed making -1 a legal value).

The actual source code can be viewed, I don't know if this matches the SDK in use but it does appear to do some searching for a negative origin value so this looks plausible as a fix: https://github.com/raspberrypi/pico-sdk/blob/786be7524aa3c7c5467faebc54fd7c4db077ae2e/src/rp2_common/hardware_pio/pio.c#L56-L72

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.

Great find! Thanks @DavePutz

@tannewt tannewt merged commit f7a988b into adafruit:main Mar 16, 2021
@DavePutz DavePutz deleted the issue_4237 branch March 16, 2021 17:17
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.

5 participants