sipeed / TangPrimer-25K-example

TangPrimer-25K-example project
31 stars 14 forks source link

UART example not working #14

Open 0x8008135 opened 5 months ago

0x8008135 commented 5 months ago

Hello,

I cannot make the uart example work despite my efforts.

Did anyone succeed?

According to my understanding an output should be seen on the uart (I assume USB1), but there is nothing.... (a small description is welcomed as well for beginners)

Please advice

Plaque-fcc commented 4 months ago
Hello,

Seems like this is happening because the BL616 chip (which provides this interface over USB) has a firmware with dividers calculated for 48MHz (as in FT2232), while having a 26MHz crystal oscillator instead, therefore its timings are off by factor of ≈3.70 or even 4.

Of course, if Sipeed releases updated firmware for the BL616 (USB Debug JTAG+UART chip on the Tang Primer 25K Dock board) SoC with corrected constants, the problem will be solved. But I don't even know how to contact them and ask if they already did.

Plaque-fcc commented 4 months ago

More specifically, here is a table of its speeds we managed to measure (expected vs real):

   9600 =    2400
  19200 =    4800
  38400 =    9602
  57600 =   14397
 115200 =   28826
 230400 =   57530
 460800 =  115562
 500000 =  125000
 576000 =  143678
 921600 =  230061
1000000 =  250000
1152000 =  288832
1500000 =  376884
2000000 =  500000
2500000 =  634697
3000000 =  742574
3500000 =  896414
4000000 = 1000000

We can see in UART/src/uart_top.v: parameter UART_FRE = 115200;//Mhz This means, you need to configure a serial interface on your PC to 115200×4 == 460800.

That way this example could start working.

nanoant commented 4 months ago

We can see in UART/src/uart_top.v: parameter UART_FRE = 115200;//Mhz This means, you need to configure a serial interface on your PC to 115200×4 == 460800. That way this example could start working.

Unfortunately this trick does not work for me.

@Zepan can you please have a look why this example is not working on Primer 25K? I also can't get usb_hid_host printing anything on Primer 25K. I receive absolutely no UART. This is really frustrating as without UART any CPU emulation is simply pointless on this FPGA board.

Plaque-fcc commented 4 months ago

I receive absolutely no UART.

This is weird. As I can see, the BL616 on the Dock Board provides two interfaces: one JTAG and one UART. Are you sure your problem is the same as ours?

nanoant commented 4 months ago

Okay the problem is trivial, UART example has RX and TX pins swapped - C3 is TX not RX:

image

After swapping pins I get proper output in Windows 11 with python serial using 115200, so no tricks are necessary.

image

It looks nobody absolutely tried this example when adapting for Primer25K which is bad.

Also unfortunately I cannot get UART working fine on my Mac which is my primary (and favorite) platform. With same python serial as on Windows I get garbage output. The rate of characters is ok (group of chars per 1s).

image

Looks like BL616 is not emulating FT2232 good enough here. This is a bummer because I managed to use Gowin IDE under Wine on macOS and then program with openFPGAloader, but the UART is producing garbage on macOS.

Final note. If I burn UART example into flash, then I can't access the COM port on Windows at all. It looks BL616 gets broken if FPGA is sending stuff from the very beginning.

Altogether I have very mixed feeling about this. Primer25K is not first FPGA from Sipeed/Gowin, but it is far from polished.

nanoant commented 4 months ago

Update: I have connected UART example to RX=L11, TX=K5 PMOD and used separate FT232R USB dongle with genuine FTDI chip and this example works perfectly. Everything is super stable.

So long story short I think BL616 firmware is broken and UART pass-through is completely unreliable. I managed to make it work only on Windows, and it also breaks as soon as I reconnect few times. This example is also broken with RX and TX pins swapped, and will only lead to frustration when using Sipeed/Gowin products.

Is anyone from Sipeed (@DouerGan or @Zepan) reading this? Functional UART is crucial for any debugging work.

image
Plaque-fcc commented 4 months ago

Well, I asked Sipeed technical support about it, and they said everything is working fine on their end. Whatever that means.

0x8008135 commented 4 months ago

Hey, Thank you for the feedbacks. I actually remembered trying to change TX and RX without success, but anyways....

I just installed a fresh version of GoWin Education (v.1.9.9.03) on Windows, selected the device (GW5A) image

And it complains about the "clk" constraint but it should work as written here:

image

Running placement......
ERROR  (PR2028) : The constrained location is useless in current package
ERROR  (PR2017) : 'clk' cannot be placed according to constraint, for the location is a dedicated pin (CPU/SSPI)

Just to make it clear, what version did you use ?

0x8008135 commented 4 months ago

OK I need to change Use CPU as regular IO in Configuration > Place & route > Dual-purpose pin

0x8008135 commented 4 months ago

@nanoant I have exactly the same configuration as you, except I am using the educational edition which has support for model GW5A-LV25MG121NC1/I0 instead of the GW5A-LV25MG121NES that you have.

What version of the IDE/programmer are you using ?

nanoant commented 4 months ago

@0x8008135 Don't bother with EDU version of Gowin IDE, GW5A-LV25MG121NES is not supported there and trying to map it to different NC even it is same GW5A is waste of time - didn't work for me - probably due to completely different pinouts. I switched to standard non-EDU version and license server according to https://wiki.sipeed.com/hardware/en/tang/Tang-Nano-Doc/install-the-ide.html#About-the-license Sipeed instructions.

Downside is that they see your IP every-time you start IDE and maybe they collect some data about you.

On non-EDU all projects work fine out of the box. Sometimes .gprj have some absolute paths hard-coded that you need to adjust. Also IDE works absolutely fine with WINE on macOS. Then I use openFPGALoader on .fs file produced by gw-ide.exe.

Unfortunately all instruction provided at Sipeed WIKI are misleading letting you think EDU should work with Primer 25K, but it doesn't. It is pretty clear that Primer 25K instructions were based on non-EDU version look at screenshot there https://wiki.sipeed.com/hardware/en/tang/tang-primer-25k/primer-25k.html#No-Response-or-Incorrect-Pin-Phenomenon-After-Burning.

0x8008135 commented 4 months ago

Ok, I will give it a shot using the normal version.

I really hope that Sipeed will make a clear statement about this, or at least, update their website to avoid people losing their time !

Thank you for the troubleshooting and time on this matter, I will let you know if I succeed with the normal version.

HexColors60 commented 4 months ago

TX is the C3, RX is the B3. We need to change the example UART cst file. Set the CPU, READY, DONE pin to the dual purpose pins. In Standard edition IDE, after load the gprj file, it will find the GW5A-LV25MG121NES correctly. In Educational edition IDE, I need to config it to GW5A-LV25MG121NC1/I0 and version A. The two windows IDE both work for me. I just build the small CPU and BIOS on it. https://github.com/HexColors60/hex60_tang_primer_25k/blob/main/litex_on_tang_primer_25k.txt