Skip to content

Commit 9d0762a

Browse files
decsnykartben
authored andcommitted
spi_nxp_lpspi: Fix word size > 8
Fix calculations for larger than 8 bit word sizes Signed-off-by: Declan Snyder <[email protected]>
1 parent d54d63d commit 9d0762a

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

drivers/spi/spi_nxp_lpspi/spi_nxp_lpspi.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static inline void lpspi_rx_word_write_bytes(const struct device *dev, size_t of
3333
struct lpspi_data *data = dev->data;
3434
struct lpspi_driver_data *lpspi_data = (struct lpspi_driver_data *)data->driver_data;
3535
struct spi_context *ctx = &data->ctx;
36-
uint8_t num_bytes = MIN(lpspi_data->word_size_bytes, ctx->rx_len);
36+
uint8_t num_bytes = lpspi_data->word_size_bytes;
3737
uint8_t *buf = ctx->rx_buf + offset;
3838
uint32_t word = base->RDR;
3939

@@ -53,7 +53,7 @@ static inline size_t lpspi_rx_buf_write_words(const struct device *dev, uint8_t
5353
struct lpspi_data *data = dev->data;
5454
struct lpspi_driver_data *lpspi_data = (struct lpspi_driver_data *)data->driver_data;
5555
struct spi_context *ctx = &data->ctx;
56-
size_t buf_len = DIV_ROUND_UP(ctx->rx_len, lpspi_data->word_size_bytes);
56+
size_t buf_len = ctx->rx_len;
5757
uint8_t words_read = 0;
5858
size_t offset = 0;
5959

@@ -156,9 +156,7 @@ static void lpspi_next_tx_fill(const struct device *dev)
156156
size_t fill_len;
157157
size_t actual_filled = 0;
158158

159-
/* Convert bytes to words for this xfer */
160-
fill_len = DIV_ROUND_UP(spi_context_tx_len_left(ctx), lpspi_data->word_size_bytes);
161-
fill_len = MIN(fill_len, config->tx_fifo_size);
159+
fill_len = MIN(ctx->tx_len, config->tx_fifo_size);
162160

163161
const struct spi_buf *current_buf = ctx->current_tx;
164162
const uint8_t *cur_buf_pos = ctx->tx_buf;

0 commit comments

Comments
 (0)