Problem with trace utility in I-CUBE-LRWAN
Hello,
I'm currently working on an application that integrates the LoRaWAN stack (version 2.1.0), and has to use USART2 to send/receive data. USART2 is already used by the trace utility, to send trace messages. I activated RX on interruption by calling UTIL_ADV_TRACE_StartRxProcess().
While performing some tests, I discovered a problem: if a byte is received while HAL_UART_Transmit_DMA() is being executed, the RX interrupt service code sees the USART's data as being locked and returns without re-enabling RX interrupt. Consequence: the USART can't receive bytes anymore.
I just corrected this by disabling USART interrupts when a DMA TX operation is initialized:
UTIL_ADV_TRACE_Status_t vcom_Trace_DMA(uint8_t *p_data, uint16_t size)
{
// Disable USART interrupts while starting the DMA TX otherwise an RX
// interrupt could happen while USART's data is locked, and RXNEIE would
// be left reset.
HAL_NVIC_DisableIRQ(USARTx_IRQn);
HAL_UART_Transmit_DMA(&huart2, p_data, size);
HAL_NVIC_EnableIRQ(USARTx_IRQn);
return UTIL_ADV_TRACE_OK;
}This works. But I wonder whether this is the best solution. Any thoughts?
The place where the interrupt service code fails to re-enable RX interruption:
- when a byte is received, UART_RxISR_8BIT() is called
- UART_RxISR_8BIT() calls HAL_UART_RxCpltCallback() (in usart_if.c)
- HAL_UART_RxCpltCallback() calls HAL_UART_Receive_IT()
- HAL_UART_Receive_IT() calls __HAL_LOCK(huart)
- as DMA transmission request has just locked huart, __HAL_LOCK(huart) performs a return
- consequence: UART_Start_Receive_IT() is not called
