tabemann/zeptoforth

Change the RPi Pico UART baud rate

extrowerk opened this issue · 2 comments

Hi,

I'd like to use a dumb terminal to interact with Zeptoforth on Rpi Pico, but this terminal supports only 9600 baud. AFAIK Rpi uses 115200 baud UART in default, so I'd like to change tthat. I am looking around in the sources, and found this 2 occurances:

[ 42000000 115200 2 / + 115200 / ] literal USART2_BRR !

and

115200 1 uart-baud!

Could you please confirm, which one is the correct place to modify the UART baud rate?

For this I assume I would have to rebuild zeptoforth, is there any way to modify (and store!) the default UART speed in the Rpi Pico Zeptoforth console?

Thank You very much!

The best way to set the initial baud rate for a UART on the RP040 is with uart::uart-baud! in an initializer routine, like in:

compile-to-flash

: init-my-baud ( -- )
  9600 0 uart::uart-baud!
;

initializer init-my-baud

Compile this to flash, as mentioned, not to RAM, so the next time you boot up the baud rate for RP2040 will be initialized to 9600 for UART0. (If you compile this to RAM, your baud rate will change immediately, which will cause problems if you are in the process of uploading code.)

Doing things this will not require you to do rebuild of zeptoforth; you will be able to continue using your preexisting zeptoforth image.

If you want to set the baud rate to 9600 for UART1 do 9600 1 uart::uart-baud! instead or in addition.

Note that if you are using a full_usb build of zeptoforth, you will need to switch the console to UART0 with int-io::serial-console. You may want to include this in the initializer routine mentioned above, after setting the baud rate.

BTW, ignore zeptoforth/src/rp2040/forth/clock.fs ─ that is old, unused code that I have now deleted and should have deleted a while ago.

Travis

Hi Travis,

thank you for your detailed explanation, it is a great help!

Keep up the great work!