Skip to content

Commit 84d2f7f

Browse files
decsnynashif
authored andcommitted
spi_nxp_lpspi: Fix extra byte sent on v1 lpspi
This stupid errata will not leave me alone, here is another bandaid to deal with an issue where an extra byte was being sent on version 1 LPSPIs due to the algorithm of filling NOPs when only RX is left was not expecting the situation where the LPSPI actually consumed everything from the fifo but is not sending it due to this ridiculous stalling errata. Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
1 parent f6a9a1f commit 84d2f7f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

drivers/spi/spi_nxp_lpspi/spi_nxp_lpspi.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,12 @@ static void lpspi_isr(const struct device *dev)
252252
return;
253253
}
254254

255+
/* the lpspi v1 has an errata where it doesn't clock the last bit
256+
* in continuous mode until you write the TCR
257+
*/
258+
bool likely_stalling_v1 = data->major_version < 2 &&
259+
(DIV_ROUND_UP(spi_context_rx_len_left(ctx, word_size_bytes), word_size_bytes) == 1);
260+
255261
if (spi_context_rx_on(ctx)) {
256262
/* capture these values because they could change during this code block */
257263
size_t rx_fifo_len = rx_fifo_cur_len(base);
@@ -279,6 +285,10 @@ static void lpspi_isr(const struct device *dev)
279285
size_t max_fifo_fill = MIN(tx_fifo_space_left, rx_fifo_space_left);
280286
size_t max_fill = MIN(max_fifo_fill, expected_rx_left);
281287

288+
if (likely_stalling_v1 && max_fill > 0) {
289+
max_fill -= 1;
290+
}
291+
282292
/* If we already have some words in the tx fifo, we should count those */
283293
if (max_fill > tx_fifo_len) {
284294
max_fill -= tx_fifo_len;
@@ -290,8 +300,7 @@ static void lpspi_isr(const struct device *dev)
290300
lpspi_fill_tx_fifo_nop(dev, max_fill);
291301
}
292302

293-
if ((DIV_ROUND_UP(spi_context_rx_len_left(ctx, word_size_bytes), word_size_bytes) == 1) &&
294-
(data->major_version < 2)) {
303+
if (likely_stalling_v1) {
295304
/* Due to stalling behavior on older LPSPI,
296305
* need to end xfer in order to get last bit clocked out on bus.
297306
*/

0 commit comments

Comments
 (0)