I cannot understand of how the XCHG PRU instruction works (or cannot make it working as expected).
I expect that “XCHG 10, r1, 4” should exchange the contents of r1 with the scratch pad bank0.r1, 4 bytes: put r1 contents there, and get S-pad data, simultaneously.
However I see the XCHG behaviour exactly the same as the XIN instruction, that is scratchpad is being read OK, but nothing is written to the scratchpad.
mov r1, 0x01
XOUT 10, r1, 4 // init the S-pad to value of 0x01
mov r1, 0x02
XCHG 10, r1, 4 // Make S-pad=0x02, r1 = 0x01
SBCO r1, C24, 0x00, 4 // r1 → RAM<0…3>, and I see the RAM0 = 0x01 - OK
mov r1, 0x03
XCHG 10, r1, 4 // Make S-pad=0x03, r1 = 0x02
SBCO r1, C24, 0x04, 4 // r1 → RAM<4…7>, but I see the RAM4 = 0x01 - BAD! Should be 0x02
Could somebody please confirm that XCHG instruction works, or does not work, or how to make it exchanging the data reg<->scratchpad?
(no register shifting used: PRUCFG.SPP=0)