Skip to content

Commit 93f13be

Browse files
decsnykartben
authored andcommitted
spi_nxp_lpspi: Fix S32 regressions
There are two bugs that caused regression for S32: First there is a silicon errata specifically for the mask version on this board that causes FIFO flush to not work as expected. The workaround is to do a module reset before each transfer. Second there was a division error for word size > 1 byte. The division should be rounded up, not down, otherwise there will be an infinite interrupt loop because the TX fifo will not be written to but the TDR interrupt enabled causes interrupt when TX fifo is empty. Signed-off-by: Declan Snyder <[email protected]>
1 parent de2d20f commit 93f13be

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

drivers/spi/spi_nxp_lpspi/spi_nxp_lpspi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static inline size_t lpspi_rx_buf_write_words(const struct device *dev, uint8_t
6262
struct spi_mcux_data *data = dev->data;
6363
struct lpspi_driver_data *lpspi_data = (struct lpspi_driver_data *)data->driver_data;
6464
struct spi_context *ctx = &data->ctx;
65-
size_t buf_len = ctx->rx_len / lpspi_data->word_size_bytes;
65+
size_t buf_len = DIV_ROUND_UP(ctx->rx_len, lpspi_data->word_size_bytes);
6666
uint8_t words_read = 0;
6767
size_t offset = 0;
6868

@@ -158,7 +158,7 @@ static void lpspi_next_tx_fill(const struct device *dev)
158158
size_t max_chunk;
159159

160160
/* Convert bytes to words for this xfer */
161-
max_chunk = ctx->tx_len / lpspi_data->word_size_bytes;
161+
max_chunk = DIV_ROUND_UP(ctx->tx_len, lpspi_data->word_size_bytes);
162162
max_chunk = MIN(max_chunk, config->tx_fifo_size);
163163
lpspi_data->fill_len = max_chunk;
164164

drivers/spi/spi_nxp_lpspi/spi_nxp_lpspi_common.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ int spi_mcux_configure(const struct device *dev, const struct spi_config *spi_cf
5757
return ret;
5858
}
5959

60+
base->CR |= LPSPI_CR_RST_MASK;
61+
base->CR |= LPSPI_CR_RRF_MASK | LPSPI_CR_RTF_MASK;
62+
base->CR = 0x00U;
63+
6064
if (data->ctx.config != NULL) {
6165
/* Setting the baud rate in LPSPI_MasterInit requires module to be disabled. Only
6266
* disable if already configured, otherwise the clock is not enabled and the

0 commit comments

Comments
 (0)