PIO - Barrel shift #14150
-
When I use out(null,2) or similar I have barrel shift in the OSR, is that a bug? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 13 replies
-
See RP2040 data sheet, chapter 3.2.3.1 about the OSR. |
Beta Was this translation helpful? Give feedback.
-
this is my rgb332 to rgb565 converter that i feed with the dma. I use the PIO system instead of hardware SPI.
CONVERTER -START- WE WORK WITH REVERSED 8bit COLOURS. RRRGGGBB are BBGGGRRR
CONVERTER -END- 10 cmds used
TRANSFER 16 bits to one pin ##
|
Beta Was this translation helpful? Give feedback.
-
To more convincingly clarify the question of barrel shift or cyclic/rotary shift with a from time import sleep_ms
from rp2 import PIO, StateMachine, asm_pio
@asm_pio(pull_thresh=32, push_thresh=32, out_init=[PIO.OUT_LOW], in_shiftdir=PIO.SHIFT_LEFT, out_shiftdir=PIO.SHIFT_RIGHT)
def sm_gen():
pull(block)
# out(null,4)
# out(null,4)
# out(null,4)
# out(null,4)
# out(null,4)
# out(null,4)
# out(null,4)
# out(null,4)
in_(osr,4)
out(null,4)
in_(osr,4)
out(null,4)
in_(osr,4)
out(null,4)
in_(osr,4)
out(null,4)
in_(osr,4)
out(null,4)
in_(osr,4)
out(null,4)
in_(osr,4)
out(null,4)
in_(osr,4)
push(block)
sm = StateMachine(0, sm_gen, freq=2000)
x_put = 0b01111001011011010110100111101001
sm.put(x_put)
sm.active(1)
sleep_ms(50)
x_get = sm.get()
print(f'{x_put:8x}, {x_get:8x}')
sm.put(x_put)
x_get = sm.get()
print(f'{x_put:8x}, {x_get:8x}') Running it with the 8
but when de-commenting the 8
so the OSR is cleared (completely shifted out to nirvana:-) ) by those instructions. Given this is not possible then it remains an interesting question why your rgb332 to rgb565 converter still works as expected. |
Beta Was this translation helpful? Give feedback.
-
Hii, here's a clean code doing the barrel shifting.
|
Beta Was this translation helpful? Give feedback.
It still isn't rotating. And it will never rotate because it isn't designed to rotate!
Your single-byte DMA transfer somehow replicates itself to bit positions [31: 24] [23,16] [15:8] [7:0]
Thus you're seeing a (previously unnoticed) side-effect. (data shifting to the right from [15:8]).
Will check the reference manual whether this is intended or not.
EDIT:
Already found it. Page 92.
The DMA performs standard byte lane replication on narrow writes, so byte data
is available in all 4 bytes of the databus, and halfword data in both halfwords.