raspberrypi / pico-sdk

BSD 3-Clause "New" or "Revised" License
3.77k stars 944 forks source link

sm_config_set_in_pin_count() appears incorrect #1878

Closed arg08 closed 1 week ago

arg08 commented 2 months ago

This function is newly added for RP2350, and the implementation appears inconsistent with the datasheet.

Datasheet says:

Set the number of pins which are not masked to 0 when read by an IN PINS, WAIT PIN or MOV x, PINS instruction. For example, an IN_COUNT of 5 means that the 5 LSBs of the IN pin group are visible (bits 4:0), but the remaining 27 MSBs are masked to 0. A count of 32 is encoded with a field value of 0, so the default behaviour is to not perform any masking.

ie. the number in the register is the number of pins you are actually using, except that zero represents 32.

However, the code puts (in_count - 1).

https://github.com/raspberrypi/pico-sdk/blob/efe2103f9b28458a1615ff096054479743ade236/src/rp2_common/hardware_pio/include/hardware/pio.h#L393

Looks like it should be (in_count & 0x1f)

peterharperuk commented 2 months ago

@kilograham This does look wrong. Do you agree?

kilograham commented 2 months ago

i do - have made a PR

kilograham commented 1 week ago

merged into develop