|
63 | 63 | # define DEBUG_PRINTF(...) {}
|
64 | 64 | #endif
|
65 | 65 |
|
| 66 | +/* Consider 10ms as the default timeout for sending/receving 1 byte */ |
| 67 | +#define TIMEOUT_1_BYTE 10 |
| 68 | + |
66 | 69 | void init_spi(spi_t *obj)
|
67 | 70 | {
|
68 | 71 | struct spi_s *spiobj = SPI_S(obj);
|
@@ -367,7 +370,7 @@ int spi_master_write(spi_t *obj, int value)
|
367 | 370 | SPI_HandleTypeDef *handle = &(spiobj->handle);
|
368 | 371 |
|
369 | 372 | 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); |
371 | 374 | }
|
372 | 375 |
|
373 | 376 | #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,
|
422 | 425 | } else {
|
423 | 426 | /* In case of 1 WIRE only, first handle TX, then Rx */
|
424 | 427 | 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)) { |
426 | 429 | /* report an error */
|
427 | 430 | total = 0;
|
428 | 431 | }
|
429 | 432 | }
|
430 | 433 | 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)) { |
432 | 435 | /* report an error */
|
433 | 436 | total = 0;
|
434 | 437 | }
|
|
0 commit comments