STM32F1 Getting SD_BREAK_DETECTED even if LIN is disabled

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
l0ud
Posts: 2
Joined: Thu Nov 30, 2017 12:55 am

STM32F1 Getting SD_BREAK_DETECTED even if LIN is disabled

Postby l0ud » Thu Nov 30, 2017 1:24 am

Hi. I'm using serial driver and so far I'm pretty happy with it. However there is one thing that confuses me.
I'm communicating with BT module that requires reset during initialization. After triggering RESET, it holds TX line low for some time, which I think is interpreted as LIN break. After that I'm getting SD_BREAK_DETECTED event and I have to use chIQResetI(&SD2.iqueue) to clear that error. If I won't, I will not getting any events with CHN_INPUT_AVAILABLE flag anymore.

From I can read from stm32f1 reference manual:
If the LIN mode is disabled (LINEN=0), the receiver continues working as normal USART,
without taking into account the break detection.
If the LIN mode is enabled (LINEN=1), as soon as a framing error occurs (i.e. stop bit
detected at ‘0’, which will be the case for any break frame), the receiver stops until the break
detection circuit receives either a ‘1’, if the break word was not complete, or a delimiter
character if a break has been detected.


Without LINEN flag receiver should continue without any special action. So I've changed default configuration to disable that flag:

Code: Select all

const SerialConfig serialConf =
{
  SERIAL_DEFAULT_BITRATE,
  0,
  USART_CR2_STOP1_BITS,
  0
};

....

sdStart(&SD2, &serialConf);



However, the behaviour is still the same (SD_BREAK_DETECTED handling is required). Is this a correct behaviour? Why?
Thanks

User avatar
Giovanni
Site Admin
Posts: 10341
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 231 times
Been thanked: 205 times
Contact:

Re: STM32F1 Getting SD_BREAK_DETECTED even if LIN is disabled

Postby Giovanni » Thu Nov 30, 2017 7:43 am

Hi,

I think you need chIQResetI() because the queue has been filled with garbage, the event is only generated when the queue goes from empty to non-empty. Do you see other error flags in addition to a full queue?

About the LIN break, this is strange, have you checked if there is an errata related to this? F1 is pretty old.

Giovanni

l0ud
Posts: 2
Joined: Thu Nov 30, 2017 12:55 am

Re: STM32F1 Getting SD_BREAK_DETECTED even if LIN is disabled

Postby l0ud » Thu Nov 30, 2017 11:31 pm

Well, I'm not getting any event after SD_BREAK_DETECTED. I said I needed to use chIQResetI() because it was the only method to recover from serial error I've managed to find on forum, I cannot find anything in the doccumentation either - maybe there is some more elegant way?

If I force my bt driver to serial write to module even when it doesn't receive "ready" message after restart, I can see that command on the logic analyzer and the bt module is responding (so TX part is working correctly). However, CHN_INPUT_AVAILABLE is not seen, instead there are multiple events with SD_OVERRUN_ERROR flag.

I've not found anything about LIN in errata sheet. But as far as I can see, reference manual doesn't claim that LBD bit in SR will remain cleared when LIN is disabled, so driver can still trigger SD_BREAK_DETECTED in interrupt (not sure why that interrupt is generated though - maybe it's for other usart event?).

User avatar
Giovanni
Site Admin
Posts: 10341
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 231 times
Been thanked: 205 times
Contact:

Re: STM32F1 Getting SD_BREAK_DETECTED even if LIN is disabled

Postby Giovanni » Fri Dec 01, 2017 8:40 am

Hi,

In order to get CHN_INPUT_AVAILABLE you need to empty the queue because it is only generated by an empty->non_empty transition.

Note that the initial CHN_INPUT_AVAILABLE is lost if at the time it happens there is no listener associated to the event source, those flags are stored inside the listener object.

It looks like you get garbage at start and that then prevents CHN_INPUT_AVAILABLE from occurring, resetting the queue or reading until it is empty is the right thing to do.

Giovanni


Return to “ChibiOS/HAL”

Who is online

Users browsing this forum: No registered users and 1 guest