cancel
Showing results for 
Search instead for 
Did you mean: 

Implementing Interrupt driven Stream UART Rx Handling with STM32CubeMX drivers

Kent Swan
Senior
Posted on January 09, 2018 at 17:38

The original post was too long to process during our migration. Please click on the attachment to read the original post.
22 REPLIES 22
anonymous.8
Senior II

Hello,

Thanks! Stream UART code looks very useful. Could you please clarify one more thing? If I understood correctly, this approach requires special actions to close receive stream before transmitting data? Like in UART_RxISR_8BIT:

/* Disable the UART Parity Error Interrupt and RXNE interrupts */

   CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));

   /* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */

   CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);

   /* Rx process is completed, restore huart->RxState to Ready */

   huart->RxState = HAL_UART_STATE_READY;

   /* Clear RxISR function pointer */

   huart->RxISR = NULL;

#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)

   /*Call registered Rx complete callback*/

   huart->RxCpltCallback(huart);

#else

   /*Call legacy weak Rx complete callback*/

   HAL_UART_RxCpltCallback(huart);

#endif /* USE_HAL_UART_REGISTER_CALLBACKS */

ranran
Senior II

Hello,

Is it that this solution is only for L4 ? or can it be used with F4 too ?

Another thing, I find in code USART_CR1_FIFOEN. Can't it be used for solving the same problem ?

Thanks!

Kent Swan
Senior
The various root libraries for the different mainline processor series have fairly similar standard peripheral silicon. Don't get me wrong, the evolution of processors and their capabilities mandate that changes will occur but within a processor series the changes are much less traumatic relative to the library code. That being said, the need to implement high level api peripheral compatibility makes the underlying libraries similar. This means that you could implement the changes in the current F libraries by following the guidelines that I detailed in the post and attached pdf. In actual fact the changes to the libraries themselves are rather minimal and the rest of the non library dispatch and callback code should remain mostly the same. It would be nicer if ST had implemented streaming interrupt uart drivers as a simple mode option like they have with the other methods of operation but, at this writing they haven't. I hope this helps.