Commit f6a9a1f3 authored by Declan Snyder's avatar Declan Snyder Committed by Anas Nashif
Browse files

spi_nxp_lpspi: Fix unit of buf_len in fill_tx_fifo



The buf_len parameter of lpspi_fill_tx_fifo is supposed to be bytes, so
we do not need to convert it. This could cause an issue if the end of
the buffer is less bytes than the word size.

Signed-off-by: default avatarDeclan Snyder <declan.snyder@nxp.com>
parent e9d964f6
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -112,17 +112,16 @@ static inline void lpspi_fill_tx_fifo(const struct device *dev, const uint8_t *b
	struct lpspi_data *data = dev->data;
	struct lpspi_driver_data *lpspi_data = (struct lpspi_driver_data *)data->driver_data;
	uint8_t word_size = lpspi_data->word_size_bytes;
	size_t buf_remaining_bytes = buf_len * word_size;
	size_t offset = 0;
	uint32_t next_word;
	uint32_t next_word_bytes;

	for (int word_count = 0; word_count < fill_len; word_count++) {
		next_word_bytes = MIN(word_size, buf_remaining_bytes);
		next_word_bytes = MIN(word_size, buf_len);
		next_word = lpspi_next_tx_word(dev, buf, offset, next_word_bytes);
		base->TDR = next_word;
		offset += word_size;
		buf_remaining_bytes -= word_size;
		buf_len -= word_size;
	}

	LOG_DBG("Filled TX FIFO to %d words (%d bytes)", fill_len, offset);