diff --git a/libraries/AP_HAL_ChibiOS/UARTDriver.cpp b/libraries/AP_HAL_ChibiOS/UARTDriver.cpp index a04537fdbd..23a7390c64 100644 --- a/libraries/AP_HAL_ChibiOS/UARTDriver.cpp +++ b/libraries/AP_HAL_ChibiOS/UARTDriver.cpp @@ -877,6 +877,9 @@ void UARTDriver::write_pending_bytes_DMA(uint32_t n) STM32_DMA_CR_MINC | STM32_DMA_CR_TCIE); dmaStreamEnable(txdma); uint32_t timeout_us = ((1000000UL * (tx_len+2) * 10) / _baudrate) + 500; + // prevent very long timeouts at low baudrates which could cause another thread + // using begin() to block + timeout_us = MIN(timeout_us, 100000UL); chSysUnlock(); // wait for the completion or timeout handlers to signal that we are done eventmask_t mask = chEvtWaitAnyTimeout(EVT_TRANSMIT_DMA_COMPLETE, chTimeUS2I(timeout_us));