Skip to content

Commit 7f07c8a

Browse files
committed
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 e2393a0 commit 7f07c8a

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
@@ -112,36 +112,30 @@ static void spi_stm32_shift_m(SPI_TypeDef *spi, struct spi_stm32_data *data)
112112
/* Shift a SPI frame as slave. */
113113
static void spi_stm32_shift_s(SPI_TypeDef *spi, struct spi_stm32_data *data)
114114
{
115-
u16_t tx_frame;
116-
u16_t rx_frame;
115+
if (LL_SPI_IsActiveFlag_TXE(spi) && spi_context_tx_on(&data->ctx)) {
116+
u16_t tx_frame = spi_stm32_next_tx(data);
117117

118-
tx_frame = spi_stm32_next_tx(data);
119-
if (LL_SPI_IsActiveFlag_TXE(spi)) {
120118
if (SPI_WORD_SIZE_GET(data->ctx.config->operation) == 8) {
121119
LL_SPI_TransmitData8(spi, tx_frame);
122-
/* The update is ignored if TX is off. */
123120
spi_context_update_tx(&data->ctx, 1, 1);
124121
} else {
125122
LL_SPI_TransmitData16(spi, tx_frame);
126-
/* The update is ignored if TX is off. */
127123
spi_context_update_tx(&data->ctx, 2, 1);
128124
}
125+
} else {
126+
LL_SPI_DisableIT_TXE(spi);
129127
}
130128

131-
if (LL_SPI_IsActiveFlag_RXNE(spi)) {
129+
if (LL_SPI_IsActiveFlag_RXNE(spi) && spi_context_rx_buf_on(&data->ctx)) {
130+
u16_t rx_frame;
131+
132132
if (SPI_WORD_SIZE_GET(data->ctx.config->operation) == 8) {
133133
rx_frame = LL_SPI_ReceiveData8(spi);
134-
if (spi_context_rx_buf_on(&data->ctx)) {
135-
UNALIGNED_PUT(rx_frame,
136-
(u8_t *)data->ctx.rx_buf);
137-
}
134+
UNALIGNED_PUT(rx_frame, (u8_t *)data->ctx.rx_buf);
138135
spi_context_update_rx(&data->ctx, 1, 1);
139136
} else {
140137
rx_frame = LL_SPI_ReceiveData16(spi);
141-
if (spi_context_rx_buf_on(&data->ctx)) {
142-
UNALIGNED_PUT(rx_frame,
143-
(u16_t *)data->ctx.rx_buf);
144-
}
138+
UNALIGNED_PUT(rx_frame, (u16_t *)data->ctx.rx_buf);
145139
spi_context_update_rx(&data->ctx, 2, 1);
146140
}
147141
}

0 commit comments

Comments
 (0)