Skip to content

Commit 7fb245f

Browse files
superna9999nashif
authored andcommitted
spi: spi_ll_stm32: fix slave frame shifting
In the current form of the code, the slave frame shifting leaves the TX full and will shift out some unwanted bytes out on the next transaction. Signed-off-by: Neil Armstrong <[email protected]>
1 parent 8c8ddb8 commit 7fb245f

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

drivers/spi/spi_ll_stm32.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,36 +118,30 @@ static void spi_stm32_shift_m(SPI_TypeDef *spi, struct spi_stm32_data *data)
118118
/* Shift a SPI frame as slave. */
119119
static void spi_stm32_shift_s(SPI_TypeDef *spi, struct spi_stm32_data *data)
120120
{
121-
u16_t tx_frame;
122-
u16_t rx_frame;
121+
if (LL_SPI_IsActiveFlag_TXE(spi) && spi_context_tx_on(&data->ctx)) {
122+
u16_t tx_frame = spi_stm32_next_tx(data);
123123

124-
tx_frame = spi_stm32_next_tx(data);
125-
if (LL_SPI_IsActiveFlag_TXE(spi)) {
126124
if (SPI_WORD_SIZE_GET(data->ctx.config->operation) == 8) {
127125
LL_SPI_TransmitData8(spi, tx_frame);
128-
/* The update is ignored if TX is off. */
129126
spi_context_update_tx(&data->ctx, 1, 1);
130127
} else {
131128
LL_SPI_TransmitData16(spi, tx_frame);
132-
/* The update is ignored if TX is off. */
133129
spi_context_update_tx(&data->ctx, 2, 1);
134130
}
131+
} else {
132+
LL_SPI_DisableIT_TXE(spi);
135133
}
136134

137-
if (LL_SPI_IsActiveFlag_RXNE(spi)) {
135+
if (LL_SPI_IsActiveFlag_RXNE(spi) && spi_context_rx_buf_on(&data->ctx)) {
136+
u16_t rx_frame;
137+
138138
if (SPI_WORD_SIZE_GET(data->ctx.config->operation) == 8) {
139139
rx_frame = LL_SPI_ReceiveData8(spi);
140-
if (spi_context_rx_buf_on(&data->ctx)) {
141-
UNALIGNED_PUT(rx_frame,
142-
(u8_t *)data->ctx.rx_buf);
143-
}
140+
UNALIGNED_PUT(rx_frame, (u8_t *)data->ctx.rx_buf);
144141
spi_context_update_rx(&data->ctx, 1, 1);
145142
} else {
146143
rx_frame = LL_SPI_ReceiveData16(spi);
147-
if (spi_context_rx_buf_on(&data->ctx)) {
148-
UNALIGNED_PUT(rx_frame,
149-
(u16_t *)data->ctx.rx_buf);
150-
}
144+
UNALIGNED_PUT(rx_frame, (u16_t *)data->ctx.rx_buf);
151145
spi_context_update_rx(&data->ctx, 2, 1);
152146
}
153147
}

0 commit comments

Comments
 (0)