STM32 LLD for UART with bus idle detection

Use this forum for requesting small changes in ChibiOS. Large changes should be discussed in the development forum. This forum is NOT for support.
Post Reply
michael_s
Posts: 4
Joined: Thu Dec 03, 2015 3:31 pm
Been thanked: 1 time

STM32 LLD for UART with bus idle detection

Post by michael_s »

Hello Giovanni,

I would like to upvote this feature also as we need free bus detection for our RS-485 implementation.

In addition to checking USART_SR_IDLE, it would be necessary to check the BUSY flag (bit 16) in USART_ISR register also, since USART_SR_IDLE is only set by hardware once an idle condition is present and is not cleared in case the bus becomes busy in the meantime. So, I would propose:

Code: Select all

/* Timeout interrupt source is only checked if enabled in CR1 and if BUSY flag is not set.*/
if ((sr & USART_ISR_IDLE) && (cr1 & USART_CR1_IDLEIE) && (sr & 0x10000U) {
  _uart_timeout_isr_code(uartp);
}


BUSY flag is hardcoded (0x10000U) since CMSIS header does not provide it.
What do you think?
User avatar
Korken
Posts: 270
Joined: Wed Apr 02, 2014 4:09 pm
Has thanked: 5 times
Been thanked: 6 times

Re: STM32 LLD for UART with bus idle detection

Post by Korken »

I also would very much like this feature.
neums
Posts: 137
Joined: Fri May 08, 2015 1:09 pm
Has thanked: 10 times
Been thanked: 5 times

Re: STM32 LLD for UART with bus idle detection

Post by neums »

Hi,
is this item on track? I whould appreciate this feature. :-)
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32 LLD for UART with bus idle detection

Post by Giovanni »

Necro thread...

The code in the idle detection is different now, is such a change still required?

Giovanni
michael_s
Posts: 4
Joined: Thu Dec 03, 2015 3:31 pm
Been thanked: 1 time

Re: STM32 LLD for UART with bus idle detection

Post by michael_s »

Giovanni wrote:The code in the idle detection is different now, is such a change still required?
Giovanni


Yes, I think also checking the BUSY-Bit in USART_ISR register is beneficial over just checking the IDLE-Bit in case the idle timeout shall be used to detect a "bus free" condition. By checking the BUSY-Bit, we can avoid to detect a non-idle line falsly as idle if a reception has just started and the first word is currently received.

However, as I understand, not all STM32 variants have the BUSY-Bit implemented.

Quote STM32F769 Reference Manual (page 1303):
BUSY: Busy flag
This bit is set and reset by hardware. It is active when a communication is ongoing on the
RX line (successful start bit detected). It is reset at the end of the reception (successful or
not).
0: USART is idle (no reception)
1: Reception on going
Post Reply