Skip to content

Commit e086678

Browse files
PetervdPerk-NXPkartben
authored andcommitted
spi_nxp_lpspi: Fix ISR handler filling TX
Fixes wait for completion problems where the ISR was not sending out TX NOP's when needed causing the transfer to timeout Signed-off-by: Peter van der Perk <[email protected]>
1 parent 092367c commit e086678

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

drivers/spi/spi_nxp_lpspi/spi_nxp_lpspi.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ static inline uint8_t tx_fifo_cur_len(LPSPI_Type *base)
2626
return (base->FSR & LPSPI_FSR_TXCOUNT_MASK) >> LPSPI_FSR_TXCOUNT_SHIFT;
2727
}
2828

29-
3029
/* Reads a word from the RX fifo and handles writing it into the RX spi buf */
3130
static inline void lpspi_rx_word_write_bytes(const struct device *dev, size_t offset)
3231
{
@@ -201,9 +200,7 @@ static void lpspi_isr(const struct device *dev)
201200
return;
202201
}
203202

204-
if (spi_context_rx_len_left(ctx) == 1) {
205-
base->TCR &= ~LPSPI_TCR_CONT_MASK;
206-
} else if (spi_context_rx_on(ctx)) {
203+
if (spi_context_rx_on(ctx)) {
207204
size_t rx_fifo_len = rx_fifo_cur_len(base);
208205
size_t expected_rx_left = rx_fifo_len < ctx->rx_len ? ctx->rx_len - rx_fifo_len : 0;
209206
size_t max_fill = MIN(expected_rx_left, config->rx_fifo_size);
@@ -213,7 +210,11 @@ static void lpspi_isr(const struct device *dev)
213210
max_fill - tx_current_fifo_len : 0;
214211

215212
lpspi_fill_tx_fifo_nop(dev);
216-
} else {
213+
}
214+
215+
if (spi_context_rx_len_left(ctx) == 1) {
216+
base->TCR &= ~LPSPI_TCR_CONT_MASK;
217+
} else if (spi_context_rx_len_left(ctx) == 0) {
217218
spi_context_complete(ctx, dev, 0);
218219
NVIC_ClearPendingIRQ(config->irqn);
219220
base->TCR &= ~LPSPI_TCR_CONT_MASK;
@@ -270,7 +271,10 @@ static int transceive(const struct device *dev, const struct spi_config *spi_cfg
270271
LPSPI_EnableInterrupts(base, (uint32_t)kLPSPI_TxInterruptEnable |
271272
(uint32_t)kLPSPI_RxInterruptEnable);
272273

273-
return spi_context_wait_for_completion(ctx);
274+
ret = spi_context_wait_for_completion(ctx);
275+
if (ret >= 0) {
276+
return ret;
277+
}
274278

275279
error:
276280
spi_context_release(ctx, ret);

0 commit comments

Comments
 (0)