Shop OBEX P1 Docs P2 Docs Learn Events
USB TTL-Serial using cheap CP2102 - problems with baud settings — Parallax Forums

USB TTL-Serial using cheap CP2102 - problems with baud settings

Cluso99Cluso99 Posts: 18,069
edited 2021-04-03 01:15 in Propeller 2

I have been using these 6-pin CP2102 versions for many years on P1 and recently with the P2. I have the transistor reset circuit as an option on my P1 and P2 boards.

There are reset problems but that is for another time.

Recently we've had problems using CP2102 with my RetrBlade2 boards and the debugger built into pnut. It seemed that the problems were that the CP2102 could not run at the baud set by pnut when using debug. Testing showed that we needed to restrict the download baud and also the debug baud, and that a maximum baud of 921,600 baud was the maximum usable. It seemed to now work and I moved on, although I've been inactive since for other reasons.

Now I have found some strange things happening. I can no longer load/run my older code that worked reliably. Since the previous debug testing caused me to use a real FT232RL device, I suspected some strange interaction with the FT drivers and the standard CP drivers.

Today I took a deeper look. Since the previous working code, I've downloaded updates to FastSpin, LoadP2, pnut, and I've updated my .bat files I use to download/run my P2 programs. As part of this update, I've caused a problem that took some time to track down.

I changed the download to 921_600 baud (from 2_000_000 baud), because as I said above, we found 921_600 baud seemed to be the max we could use with the debug in pnut. This broke the download :(
I tried all the multiples of 115_200 down to 115_200. Guess what! Not sure where the problem is yet, but loadp2 and the CP2102 only works at 115_200 or 2_000_000 !!! Ive tried all the way back to FlexProp v2.0.8. FWIW this is my bat file (F531 is FlexSpin.exe v5.3.1 and L531 is LoadP2.exe v5.3.1)

del %1.binary
C:\P2\_RetroBlade2\f531 %1.spin2 -2 -l
C:\P2\_RetroBlade2\l531 %1.binary -b2000000 -t -SINGLE

So for the CP2102, loadp2 works with 2_000_000 downloads, but will not work with 921_600, or any multiple of 115_200 above 115_200.
pnut will not work reliably with 2_000_000 but will work with 921_600.

My thoughts are that I think we have a maths problem in calculating/setting the baud. Peter has a python version of loadp2 and I'm just waiting for this code so I can try and the various baud and see what does and doesn't work without other programs getting into the mix.

I'm open to any other suggestions though.

Comments

  • jmgjmg Posts: 15,148

    Single stage downloaders should be quite Baud agnostic, as they autobaud to whatever the USB-Bridge delivers.

    Bootloaders that are two-stage need to be sure what the USB-Bridge was asked for, is what it actually set to, so P2 can match that.

    Here are some CP2102 vs CP2102N tests I did from another thread

    • CP2012N follows Baud = 24M/N snap rule, (as too does EFM8UB3 in P2D2)
    • The older CP2102 is more baud-coarse, (roughly 24M/4*N?)

    Valid values I hit on old CP2102 are 921600 (24M/26), 1.2M, (24M/20) 1.5M (24M/16)
    SiLabs driver allows you to ask for up to 2.181818M, but never delivers above 1.50M (24M/16)
    CP2012N is the newer and preferred part. However, Asian cheap boards may use the older CP2102

  • Cluso99Cluso99 Posts: 18,069
    edited 2021-04-03 06:55

    @jmg
    CP2102 cheapie eBay, not CP2102N, not programmable

    LoadP2 works when specifying 2,000,000 baud but not 921,600 (or 230,400, etc)
    pnut debug works with 921,600 but not 2,000,000 _ postedit:_ or 1_000_000

    Something is definitely amiss here!!!

  • jmgjmg Posts: 15,148

    @Cluso99 said:

    pnut debug works with 921,600 but not 2,000,000.

    Did you try pnut debug at 1.2M and 1.5M ?
    It makes sense it fails at 2M, given the table above.

  • FYI Retroblade2 + CP2102with my custom loader.

    921600 Ok
    1M fails
    1.2M Ok
    1.5M Ok
    2M fails

  • also

    115200 Ok (depends on download size)
    230400 Ok
    460800 Ok

    Be aware that the ROM loader has a 60 second serial window.
    If your download exceeds this time the download will fail.

  • Cluso99Cluso99 Posts: 18,069
    edited 2021-04-03 07:01

    Yes, 1M fails - I did a table on the pnut35L thread.

    But the problem appears to me now that different programs are setting the baud differently or incorrectly.

    As I said above, 921,600 works and doesn't work. 2,000,000 works and doesn't work. All depends on the program. Same hardware, same PC, same Windoze drivers, different programs. Totally repeatable.

    Brian, what language is your custom loader in?

  • jmgjmg Posts: 15,148
    edited 2021-04-03 08:25

    @ozpropdev said:
    Be aware that the ROM loader has a 60 second serial window.
    If your download exceeds this time the download will fail.

    Hmm, so that's an absolute time, not a time-since-last-char ?
    That could explain reports of issues with large files at low bauds, ie they simply exceed that 60 sec

    @ozpropdev said:
    also

    115200 Ok (depends on download size)
    230400 Ok
    460800 Ok

    To check how granular the CP2102 is at lower rates these are my test results, & show just 2 other valid numbers between 115200 and 230400. (at 127660 & 153846 )
    Seems stranger than I remember, with steps of 20,32,52 (all /4), and note does not snap mid-error-band either.

    24M/115200 = 208.333
    Ask for 115200 (24M/208 = 115385)
    Get 57.733k*2 = 115466

    1-(24M/208)/(57.733k*2) = 704ppm

    Ask for 24M/204 = 117647
    Get (63.870k*2) = 127740
    was actually /188 = 127660

    1-(24M/188)/(63.870k*2) = 629ppm

    Ask for 24M/184 = 130434
    Get (76.975k*2) = 153950
    was actually /156 = 153846

    1-(24M/156)/(76.975k*2) = 674ppm

    Ask for 24M/150 = 160000
    Get 115371.8*2 = 230743.6
    Was actually /104 = 230769

    1-(24M/104)/(115371.9*2) = 110ppm

  • jmgjmg Posts: 15,148

    @Cluso99 said:
    But the problem appears to me now that different programs are setting the baud differently or incorrectly.

    You do need to select a baudvalue that CP2102 actually supports, to be compatible with all types of loader.

  • @Cluso99 said:
    Brian, what language is your custom loader in?

    Visual Basic Pro 2015

  • @jmg said:

    @ozpropdev said:
    Be aware that the ROM loader has a 60 second serial window.
    If your download exceeds this time the download will fail.

    Hmm, so that's an absolute time, not a time-since-last-char ?
    That could explain reports of issues with large files at low bauds, ie they simply exceed that 60 sec

    Yes

    To check how granular the CP2102 is at lower rates these are my test results, & show just 2 other valid numbers between 115200 and 230400. (at 127660 & 153846 )
    Seems stranger than I remember, with steps of 20,32,52 (all /4), and note does not snap mid-error-band either.

    127660 & 153846 work fine too.

Sign In or Register to comment.