Open Brandon-Hurst opened 6 months ago
The struct-based API for SPI describes the function of automatically padding the transaction with the appropriate bytes if if rxLen > txLen
We have two versions of the SPI drivers: "V1" (spi_reva1.c
) and "V2" (spi_reva2.c
).
"V1" requires you to pad the data manually as you've done above, whereas in "V2" the drivers handle the padding automatically. Right now the only devices that support "V2" are the MAX32572, MAX32690, and MAX78002.
The exact verbiage in the comment might be misleading. "These actions wil be performed..." doesn't apply to those sup-qualifiers on step 2. Those are requirements that must be done by the user.
("V1" header)
Understood, thanks. I would say the API's HTML documentation is what misled me here:
The highlighted portion is what I was looking at. It would suggest to me that this action is to be performed by the API, not the user. The above comment would most likely have misled me in a similar way. Additionally -- under proper configurations the SS line can be asserted and de-asserted by the API/SPI peripheral (preferable), not by the developer via manual GPIO. So that would mean different logic for the different sub-items above.
I'm assuming the same logic should be the case for operating as a slave/sub node -- is that correct?
Yes, the wording and implementation is misleading. Looks like the only time we actually do the automatic padding in "V1" is when txData
is NULL. (https://github.com/analogdevicesinc/msdk/blob/f2c2c8b03ffb8e92b01947a267c9fe6e18dd5ecc/Libraries/PeriphDrivers/Source/SPI/spi_reva1.c#L737)
In which case we re-use the RX buffer for the dummy bytes... I can see that being problematic... But yes, the same is done for slave transactions as well.
"V1" is generally a mess and we're porting the rest of the micros to "V2", though it's relatively slow going
Okay, thanks again for the input here, it's helpful in the short term. We can continue this dialog outside this issue as needed.
The struct-based API for SPI describes the function of automatically padding the transaction with the appropriate bytes if if rxLen > txLen.
On both MAX32670 and MAX78000 under the latest SDK, I have found that the SPIMasterTransaction function actually breaks my application by sending it into an infinite while loop whenever txLen != rxLen. I also noticed some strange issues when this was happening, such as the order of transmitted bytes being reversed, etc. Will share scope shots later today.
Example function:
Valid Read:
Invalid Read (failed auto-padding): In this case, an infinite while loop is reached.