Skip to content

Commit b01cc96

Browse files
committed
Introduce TIMEOUT_1_BYTE
This makes the code more explicit about what is last parameter of HAL_SPI_Transmit/HAL_SPI_Receive functions.
1 parent 8c99bf3 commit b01cc96

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

targets/TARGET_STM/stm_spi_api.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
# define DEBUG_PRINTF(...) {}
6464
#endif
6565

66+
/* Consider 10ms as the default timeout for sending/receving 1 byte */
67+
#define TIMEOUT_1_BYTE 10
68+
6669
void init_spi(spi_t *obj)
6770
{
6871
struct spi_s *spiobj = SPI_S(obj);
@@ -367,7 +370,7 @@ int spi_master_write(spi_t *obj, int value)
367370
SPI_HandleTypeDef *handle = &(spiobj->handle);
368371

369372
if (handle->Init.Direction == SPI_DIRECTION_1LINE) {
370-
return HAL_SPI_Transmit(handle, (uint8_t*)&value, 1, 10);
373+
return HAL_SPI_Transmit(handle, (uint8_t*)&value, 1, TIMEOUT_1_BYTE);
371374
}
372375

373376
#if defined(LL_SPI_RX_FIFO_TH_HALF)
@@ -422,13 +425,13 @@ int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length,
422425
} else {
423426
/* In case of 1 WIRE only, first handle TX, then Rx */
424427
if (tx_length != 0) {
425-
if (HAL_OK != HAL_SPI_Transmit(handle, (uint8_t*)tx_buffer, tx_length, tx_length*10)) {
428+
if (HAL_OK != HAL_SPI_Transmit(handle, (uint8_t*)tx_buffer, tx_length, tx_length*TIMEOUT_1_BYTE)) {
426429
/* report an error */
427430
total = 0;
428431
}
429432
}
430433
if (rx_length != 0) {
431-
if (HAL_OK != HAL_SPI_Receive(handle, (uint8_t*)rx_buffer, rx_length, rx_length*10)) {
434+
if (HAL_OK != HAL_SPI_Receive(handle, (uint8_t*)rx_buffer, rx_length, rx_length*TIMEOUT_1_BYTE)) {
432435
/* report an error */
433436
total = 0;
434437
}

0 commit comments

Comments
 (0)