pio_claim_free_sm_and_add_program_for_gpio_range does not clean up claimed state machines#2792
pio_claim_free_sm_and_add_program_for_gpio_range does not clean up claimed state machines#2792qqqlab wants to merge 1 commit intoraspberrypi:developfrom
Conversation
|
We will need some test code to demonstrate this issue if it's really a problem |
|
Time permitting I'll add some sample code. I have this issue in https://github.com/qqqlab/madflight Just looking at the current source code it is clear that on pass==1 the unclaim section which is commented with This PR moves the unclaim section out of if() statement, so that it is really always executed. |
|
Sample program added in updated PR description |
|
Maybe use error codes from error.h instead of hardwiring them to |
It'll be easier for us to test this if you just create your example using standard pico-sdk features, rather than making use of the Arduino extensions. Thanks. |
Sorry, I don't have the standard toolchain installed, nor do I have a great desire to do so.
For me the code is clearer with 0 and -1. The rc variable is used locally only, it is not returned by the function. |
| if (sm_index[num_claimed] < 0) break; | ||
| } | ||
| if (num_claimed && (!pass || num_claimed == NUM_PIO_STATE_MACHINES)) { | ||
| int rc = num_claimed && (!pass || num_claimed == NUM_PIO_STATE_MACHINES) ? 0 : -1; |
There was a problem hiding this comment.
we should probably simplify this to either (num_claimed == pass ? 1 : NUM_PIO_STATE_MACHINES) ? 0 : -1 or even (int) (num_claimed - pass ? 1 : NUM_PIO_STATE_MACHINES)
The RP2350B requires the use of gpio_base to shift the pins for a PIO. The pio_claim_free_sm_and_add_program_for_gpio_range function handles this incorrectly, and forgets to unclaim unused state machines. This PR fixes that.
Steps to reproduce
Execute this program on a RP2350B
Result:
I.e. 3 additional SMs are claimed with the second pio_claim_free_sm_and_add_program_for_gpio_range() call