Skip to content

Commit 1ad2bc0

Browse files
khoatranyjkartben
authored andcommitted
drivers: spi: Correct condition for continuing data transfer
When performing polling-based data transfer without enabling interrupts, the current implementation stops transferring as soon as either the TX or RX buffer becomes NULL. This causes the transfer to stop prematurely, even if the other direction still has data to send or receive. This commit fixes the condition so that data transfer continues as long as one direction (TX or RX) still has data remaining. Signed-off-by: Khoa Tran <[email protected]>
1 parent 184a0e0 commit 1ad2bc0

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

drivers/spi/spi_b_renesas_ra8.c

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,7 @@ static int ra_spi_b_configure(const struct device *dev, const struct spi_config
161161

162162
static bool ra_spi_b_transfer_ongoing(struct ra_spi_data *data)
163163
{
164-
#if defined(CONFIG_SPI_B_INTERRUPT)
165164
return (spi_context_tx_on(&data->ctx) || spi_context_rx_on(&data->ctx));
166-
#else
167-
if (spi_context_total_tx_len(&data->ctx) < spi_context_total_rx_len(&data->ctx)) {
168-
return (spi_context_tx_on(&data->ctx) || spi_context_rx_on(&data->ctx));
169-
} else {
170-
return (spi_context_tx_on(&data->ctx) && spi_context_rx_on(&data->ctx));
171-
}
172-
#endif
173165
}
174166

175167
#ifndef CONFIG_SPI_B_INTERRUPT
@@ -241,26 +233,28 @@ static int ra_spi_b_transceive_master(struct ra_spi_data *data)
241233

242234
while (!p_spi_reg->SPSR_b.SPTEF) {
243235
}
244-
245236
p_spi_reg->SPDR = tx;
246237

247238
/* Clear Transmit Empty flag */
248239
p_spi_reg->SPSRC = R_SPI_B0_SPSRC_SPTEFC_Msk;
249240
spi_context_update_tx(&data->ctx, data->dfs, 1);
250241

251-
/* Rx receive */
252-
if (spi_context_rx_on(&data->ctx)) {
242+
if (p_spi_reg->SPCR_b.TXMD == 0x0) {
253243
while (!p_spi_reg->SPSR_b.SPRF) {
254244
}
255245
rx = p_spi_reg->SPDR;
256246
/* Clear Receive Full flag */
257247
p_spi_reg->SPSRC = R_SPI_B0_SPSRC_SPRFC_Msk;
258-
if (data->dfs > 2) {
259-
UNALIGNED_PUT(rx, (uint32_t *)data->ctx.rx_buf);
260-
} else if (data->dfs > 1) {
261-
UNALIGNED_PUT(rx, (uint16_t *)data->ctx.rx_buf);
262-
} else {
263-
UNALIGNED_PUT(rx, (uint8_t *)data->ctx.rx_buf);
248+
249+
/* Rx receive */
250+
if (spi_context_rx_buf_on(&data->ctx)) {
251+
if (data->dfs > 2) {
252+
UNALIGNED_PUT(rx, (uint32_t *)data->ctx.rx_buf);
253+
} else if (data->dfs > 1) {
254+
UNALIGNED_PUT(rx, (uint16_t *)data->ctx.rx_buf);
255+
} else {
256+
UNALIGNED_PUT(rx, (uint8_t *)data->ctx.rx_buf);
257+
}
264258
}
265259
spi_context_update_rx(&data->ctx, data->dfs, 1);
266260
}
@@ -349,9 +343,6 @@ static int transceive(const struct device *dev, const struct spi_config *config,
349343

350344
#else
351345
p_spi_reg->SPCR_b.TXMD = 0x0; /* tx - rx*/
352-
if (!spi_context_tx_on(&data->ctx)) {
353-
p_spi_reg->SPCR_b.TXMD = 0x2; /* rx only */
354-
}
355346
if (!spi_context_rx_on(&data->ctx)) {
356347
p_spi_reg->SPCR_b.TXMD = 0x1; /* tx only */
357348
}

0 commit comments

Comments
 (0)