Skip to content

Commit 13719c5

Browse files
krischikJeremyGrosser
authored andcommitted
Fix PWM slice calculation for RP2350 in RP.PWM.To_PWM
The function performed Shift_Right (Pin, 1) but then ignored the shifted value and overwrote Slice with "Pin and 2#111#". The fix now correctly uses the already shifted value for the mask operation (Slice and 2#111#). This matches the RP2350 datasheet and resolves incorrect slice assignments (e.g. GPIO14 was mapped to slice 6 instead of 7), which caused missing or flickering PWM outputs when pins shared a slice on the Pico 2.
1 parent a87af34 commit 13719c5

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/devices/rp2350/rp-pwm.adb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ package body RP.PWM is
160160
Slice : UInt32 := Shift_Right (Pin, 1);
161161
begin
162162
if Pin < 32 then
163-
Slice := Pin and 2#111#;
163+
Slice := Slice and 2#111#;
164164
else
165-
Slice := 8 + (Pin and 2#11#);
165+
Slice := 8 + (Slice and 2#11#);
166166
end if;
167167
return PWM_Point'
168168
(Slice => PWM_Slice (Slice),

0 commit comments

Comments
 (0)