Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve some issues with the UART applet's auto-baud detection. #260

Closed
wants to merge 2 commits into from

Conversation

attie
Copy link
Member

@attie attie commented Jan 7, 2021

When receiving a single frame that is at a faster baudrate than is currently configured, it is possible that you won't see a frame or
parity error, especially if no parity is selected. This is because the line idles high, which looks identical to a stop bit.

Even if you have parity enabled, there is a non-zero chance you'll see the high line state, and consider it to be a "valid" parity bit, when in fact it is the idle state.

When receiving a stream of frames in quick succession, there is a higher probability that you will look for a stop bit in the next frame, and will thus see a frame error (or parity error).

This PR also addresses the resulting extra / unwanted announcements to minor adjustments of the baudrate, as well as a mistake in the nMigen update of the UART gateware.

When receiving a single frame that is at a faster baudrate than is
currently configured, it is possible that you won't see a frame or
parity error, especially if no parity is selected. This is because the
line idles high, which looks identical to a stop bit.

Even if you have parity enabled, there is a non-zero chance you'll see
the high line state, and consider it to be a "valid" parity bit, when in
fact it is the idle state.

When receiving a stream of frames in quick succession, there is a higher
probability that you will look for a stop bit in the next frame, and
will thus see a frame error (or parity error).
… window

Because we are now updating the bit time whenever it changes, it is
possible to get a lot of "switched to __ baud" messages, even if the
change is minor and well within tolerance.

This patch will only report baudrate changes when they exceed a +/- 5%
window vs the previously reported baudrate.
Copy link
Member

@electroniceel electroniceel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I went to bed from your stream yesterday, my brain didn't, but came up with this issue instead:

You now always change the baudrate when you determine a new bit-length, not only when you saw a frame or parity error.

So consider the auto-baud being was locked to the right baudrate. No change in the baudrate at the sender side. But now the sender sends many bytes that don't have a single bit set, for example a 0xCC, so you can't measure single bit pulses on the line.

The hardware will now erroneously change to a slower baudrate, even if the one we detected is correct.

So maybe require a frame or parity error when changing to a slower baudrate, and only change to a faster baudrate without frame or parity error?

Another idea would be to run a second uart decoder with a baudrate under consideration for some time when a new bittime is detected. Only actually change the baudrate when the baudrate under consideration checked out without frame or pairty errors for some time. But that complicates the design of course.

@attie
Copy link
Member Author

attie commented Jan 7, 2021

Yes, good point... I was a little uneasy about this and came to the same conclusion...

Consider the following frames (8N1):
wavedrom

When receiving a series of 16x 0x00 frames (32x edges), it would change the baud rate all the way out to ~11.1% of the current baud rate (e.g: 115,200 -> 12,800).

Most of these are non-print characters (0x30, 0x1C, 0x00 being the exception), but I'm not sure how relevant this is.

Are we content with the auto-baud feature requiring a burst of data to automatically raise the baudrate?
... and if so, perhaps this should be made clear in the help?


If parity is enabled, then it's possible that the prevelance of this issue is reduced, as the data and parity bit would need to work together, but I've nof drawn out any frames to think about it harder yet...


Wavedrom source:

{signal: [
  {name: 'Frame',  wave: 'h43333333351', data: [ 'Start', 0, 1, 2, 3, 4, 5, 6, 7, 'Stop']},
  {name: '1/2 (0xE6)',  wave: 'hl.h.l.h....'},
  {name: '1/2 (0xCC)',  wave: 'hl..h.l.h...'},
  {name: '1/2 (0x98)',  wave: 'hl...h.l.h..'},
  {name: '1/2 (0x30)',  wave: 'hl....h.l.h.'},
  {name: '1/3 (0x1C)',  wave: 'hl..h..l..h.'},
  {name: '1/4 (0xF8)',  wave: 'hl...h......'},
  {name: '1/5 (0xF0)',  wave: 'hl....h.....'},
  {name: '1/6 (0xE0)',  wave: 'hl.....h....'},
  {name: '1/7 (0xC0)',  wave: 'hl......h...'},
  {name: '1/8 (0x80)',  wave: 'hl.......h..'},
  {name: '1/9 (0x00)',  wave: 'hl........h.'},
]}

@attie
Copy link
Member Author

attie commented Jan 7, 2021

I've moved the parity fix into a separate PR - #261.

Base automatically changed from master to main February 27, 2021 09:59
@whitequark
Copy link
Member

Are we content with the auto-baud feature requiring a burst of data to automatically raise the baudrate?

That's how autobaud generally works. I don't think it's possible to make a different implementation because of the ambiguity inherent in the UART framing.

@whitequark
Copy link
Member

So maybe require a frame or parity error when changing to a slower baudrate, and only change to a faster baudrate without frame or parity error?

This works reasonably well but it's very non-tolerant of glitches. I think the status quo is a reasonable tradeoff. We should probably document it though...

@attie
Copy link
Member Author

attie commented Feb 7, 2023

I don't think it's possible to make a different implementation because of the ambiguity inherent in the UART framing.

Agreed, I think that's where I left things too.

We should probably document it though...

I'll see if I can address that.

@whitequark
Copy link
Member

I'll see if I can address that.

Thanks much! Are you on IRC at all these days?

@attie
Copy link
Member Author

attie commented Feb 7, 2023

Are you on IRC at all these days?

I'll see messages in #glasgow / #amaranth via the 1b2 bridge, but I've never really got on with IRC unfortunately...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants