Author Topic: How to design UART peripherals IP?  (Read 3270 times)

0 Members and 1 Guest are viewing this topic.

Offline antercreeperTopic starter

  • Contributor
  • Posts: 41
  • Country: cn
How to design UART peripherals IP?
« on: April 10, 2024, 08:17:48 am »
(I have read some method of oversampling, but well, I hate this methodology......)(I am very unhappy about these async things(mismatching over baud rates, clock jitter, etc...:palm:) )...... I would rather does with I2C or SPI. :(
So how to achieve clock synchronizing over UART?(like the serdes's clock data recovery?)
maybe need some analog things ::)(achieve some phase moving?) instead of RTL? (means that you need to pay some $ while making ASICs instead of working over FPGAs)
« Last Edit: April 10, 2024, 08:21:22 am by antercreeper »
 

Offline mtwieg

  • Regular Contributor
  • *
  • Posts: 187
  • Country: us
Re: How to design UART peripherals IP?
« Reply #1 on: April 10, 2024, 12:08:01 pm »
UART is fundamentally asynchronous. Adding clock recovery wouldn't make it a better UART, but something else entirely, and I would not expect it to work any better with "standard" UART devices. If both sides are FPGAs which you have control over, then by all means do something fancy like adding NRZ or 8b/10b encoding. But if both sides were FPGAs then I doubt you would be stuck with UART to begin with.

Besides, UART is generally as reliable synchronous interfaces like I2C/SPI so long as the baud rates of the two devices are well-matched. Baud rate will likely be slower than SPI though. But sometimes the application calls for a true full-duplex connection.
 
The following users thanked this post: antercreeper

Offline ejeffrey

  • Super Contributor
  • ***
  • Posts: 3797
  • Country: us
Re: How to design UART peripherals IP?
« Reply #2 on: April 10, 2024, 03:08:59 pm »
(I have read some method of oversampling, but well, I hate this methodology......)(I am very unhappy about these async things

Honestly I suggest you just try to get over that.  Oversampling is not the only way to implement a UART receiver but it's almost always the best.  Or you can design a synchronous protocol but then it's not UART and can't communicate with a UART peripheral.

Note that in some implementations SPI slave peripherals especially in FPGAs use oversampling as well.  They don't clock their internal logic with the SPI clock but instead treat it as data input to a higher speed state machine.

 

Offline BrianHG

  • Super Contributor
  • ***
  • Posts: 7858
  • Country: ca
Re: How to design UART peripherals IP?
« Reply #3 on: April 10, 2024, 03:52:05 pm »
Example Verilog UART.
Runs on 1 system clock.
Oversamples.
Also generates synchronizing TX output for high speed PC full duplex com.
Read and see documentation.

See here: https://www.eevblog.com/forum/fpga/verilog-rs232-uart-and-rs232-debugger-source-code-and-educational-tutorial/

(Skip the debugger part, you don't need that..)
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 4546
  • Country: dk
Re: How to design UART peripherals IP?
« Reply #4 on: April 10, 2024, 04:31:00 pm »
the over sampling in a regular uart does effectively do clock (phase) recovery, it is just rather coarse with only 16x/8x because no more is needed.
Classic full speed USB usually does it with 4x oversampling
 
The following users thanked this post: Someone

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14907
  • Country: fr
Re: How to design UART peripherals IP?
« Reply #5 on: April 10, 2024, 08:31:24 pm »
Yes. Oversampling also takes care of resynchronizing clock domains (unless it's done very, very poorly), which is a must.

The one thing to understand when dealing with asynchronous communication and HDLs is clock domain crossing in general. If you don't even understand what this means, then designing a UART RX is almost certain to be a failure.
 
The following users thanked this post: langwadt, BrianHG, antercreeper

Offline BrianHG

  • Super Contributor
  • ***
  • Posts: 7858
  • Country: ca
Re: How to design UART peripherals IP?
« Reply #6 on: April 10, 2024, 08:47:32 pm »
Just copy my code.
It auto over-samples to your system clock speed.
Adding a baud input control is easy enough by replacing the 'parameter' with a input port.

Only adding error support for 7bit even/odd parity will require an additional translation from the RXD byte and again for the outgoing TXD byte, but nothing else should change.

Also, adding hardware handshaking will require an additional gated input and output control por.
« Last Edit: April 10, 2024, 08:49:41 pm by BrianHG »
 
The following users thanked this post: antercreeper

Offline PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 1684
  • Country: au
Re: How to design UART peripherals IP?
« Reply #7 on: April 11, 2024, 02:37:20 am »
(I have read some method of oversampling, but well, I hate this methodology......)(I am very unhappy about these async things(mismatching over baud rates, clock jitter, etc...:palm:) )...... I would rather does with I2C or SPI. :(
So how to achieve clock synchronizing over UART?(like the serdes's clock data recovery?)
maybe need some analog things ::)(achieve some phase moving?) instead of RTL? (means that you need to pay some $ while making ASICs instead of working over FPGAs)

It's unclear what you are actually trying to do here ?  What does 'achieve clock synchronizing' mean ?

A UART peripheral is normally designed to talk to UARTS, that's implicit in its name.
It is time proven, and simple, but has some compromises.

UART oversampling used to be 16x, but these days you can find x8 and x4 designs, as vendors want to support higher Baud and lower sysclks.

Better UART peripherals allow fractional baud, giving more freedom on sysclk and baud choices, and expanding that higher bauds at lower clocks.
A common example these days is allowing 9600 Baud from 32.768kHz RTC clocks.  N = 3.413333333 here.

Some uart peripherals include Autobaud ability, to help insulate users form baud settings.

If you hope to create a x1 UART that 'locks' sampling with a x1 UART clock, such a design becomes very fragile, as not all UARTS have fixed stop bit quanta.
Better ones are gap-less and jitter-less, but I've measured many with fractional bit creep and jitter. 

Another UART does not care, but some fancy clock extraction design will need to tolerate that, which brings you back to xN oversampling. Simple and proven.
 
 
The following users thanked this post: BrianHG, antercreeper

Offline antercreeperTopic starter

  • Contributor
  • Posts: 41
  • Country: cn
Re: How to design UART peripherals IP?
« Reply #8 on: April 11, 2024, 03:26:19 am »
Yes!!

so it is why i hate it. ::) And i would need a CPU running programs to send asciis over that.(Use RTL to handle those complicated FSM and exceptions is insane.)
My hole system is synchronized, only has some clock divider in the IO IPs. (If your design is very big, you still need to deal with it between different big IPs, however is under control.)
but I have to face this fact. :'(
« Last Edit: April 11, 2024, 03:28:22 am by antercreeper »
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 4546
  • Country: dk
Re: How to design UART peripherals IP?
« Reply #9 on: April 11, 2024, 07:57:28 am »
Yes!!

so it is why i hate it. ::) And i would need a CPU running programs to send asciis over that.(Use RTL to handle those complicated FSM and exceptions is insane.)
My hole system is synchronized, only has some clock divider in the IO IPs. (If your design is very big, you still need to deal with it between different big IPs, however is under control.)
but I have to face this fact. :'(

you seems to be missing some very fundamental understanding of how a UART works and how it is impelemented
 
The following users thanked this post: antercreeper

Offline antercreeperTopic starter

  • Contributor
  • Posts: 41
  • Country: cn
Re: How to design UART peripherals IP?
« Reply #10 on: April 11, 2024, 08:56:19 am »
i agree with you. :'(
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14907
  • Country: fr
Re: How to design UART peripherals IP?
« Reply #11 on: April 12, 2024, 09:13:38 pm »
I don't know if your question was more a general one out of interest, or specific to the audio FPGA board you designed? I mean, is it this board that triggered your interest in FPGAs and HDLs, or is it a more general interest of yours?

Saying that, because for this audio board, purely using a beefy MCU (like the NXP iMXRT series) would probably get you way enough power for audio processing (unless you implement very intensive processing in the FPGA fabric as some coprocessor, that would otherwise not run as software) and wouldn't require all this knowledge about FPGAs and logic design, even for the most "basic" stuff like UARTs.
 

Offline antercreeperTopic starter

  • Contributor
  • Posts: 41
  • Country: cn
Re: How to design UART peripherals IP?
« Reply #12 on: April 13, 2024, 01:18:18 pm »
yes, a more general one, really because for a long time, i cannot understand the UART. :'(
for that audio board, it is a platform designed to implement my RTLs ;)(for study purpose, or just for fun), instead of just finish some audio tasks, or be sold as a good on the shelf ::)(Of course I have raspberrypi, which can very easily finish those things.)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf