s-matyukevich / raspberry-pi-os

Learning operating system development using Linux kernel and Raspberry Pi
MIT License
13.16k stars 1.29k forks source link

Gibberish in terminal emulator on Lesson 1 #161

Open scdrumz opened 4 years ago

scdrumz commented 4 years ago

Definitely related to #127, but I didn't want to reopen an older thread.

I've completed lesson 1 on my pi 4b, and made the modifications mentioned in the above thread, specifically:

Replaced the contents of config.txt with:

arm64bit=1

and then modified src/mini_uart.c to change the baud rate:

    put32(AUX_MU_BAUD_REG,541);

I've verified my code against both this repo and @vikash876, and it appears to match up.

But, using putty, I just get gibberish output. I tried the serial monitor in my arduino app to see if there's a difference, and it's a little less muddled:

image

But, it is still incorrect. Everything I'm seeing currently indicates this could just be attributed to the mini uart being tied to the GPU clock as compared to the PL011 uart. Would that seem reasonable? I'm inclined to move forward as-is if so -- I see the same behaviour when I tried to set to 9600 baud.

Is there anything else obvious I might be missing?

andre-richter commented 4 years ago

I had exactly the same problem. I spent a whole day trying to understand what is happening. At one point I hooked the UART lines to a logic analyzer and saw that while the first few characters are okay, later ones had different bit times. Hence, I also concluded that it must be some sort of DVFS going on, and in fact it seems to be the case: https://www.raspberrypi.org/documentation/configuration/uart.md

However, none of the config options to fix the frequency worked for me on the Pi4. For my project (https://github.com/rust-embedded/rust-raspi3-OS-tutorials/tree/master/06_drivers_gpio_uart) I eventually ditched the mini UART altogether. Using the init_uart_clock config.txt option (description in the link) makes the PL011 UART setup as easy as the miniUART setup, because you don't need the mailbox to change frequency settings.

rockytriton commented 4 years ago

If you are using the pi 4, be sure not to try to power it with your serial cable. I made the mistake and spent tons of time trying to debug it, but once I plugged in a usbc to power it everything was fine. it needs more amps than the usb serial cable will provide.

andre-richter commented 4 years ago

For me, Pi4 works with USB serial cable only (only PL011 UART, as stated above, though).

scdrumz commented 4 years ago

Cool, this all makes sense. I'll start with the exercise to enable the PL011 and go from there. I definitely am using the USB power, I spent my first night playing with the wiring getting all that down :). And, I have verified the serial adapter itself on my arduino board, so I know that bit's good. Glad to hear others have run into this as well.

On Sun, 15 Dec 2019 at 12:32, Andre Richter notifications@github.com wrote:

For me, Pi4 works with USB serial cable only (only PL011 UART, as stated above, though).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/s-matyukevich/raspberry-pi-os/issues/161?email_source=notifications&email_token=ABBCRWV7AFUFVCUA3JT2SV3QYVUHVA5CNFSM4J2ZXBZ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEG4NSUI#issuecomment-565762385, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBCRWQO6A6XHH7IDCTHAVLQYVUHVANCNFSM4J2ZXBZQ .

rockytriton commented 4 years ago

if you are that lost, I would recommend this udemy class, it's about stm32, not raspberry pi, but it's arm based and teaches you how drivers are developed. The instructor is Indian but very easily understandable: https://www.udemy.com/course/mastering-microcontroller-with-peripheral-driver-development/

AlexGatz commented 4 years ago

Thanks, I'll check it out. I did figure out what my issue was shortly after making that comment. I really need to re-learn embedded c also, its been quite a long time since I've played with it at all. This is all part oft he reason I wanted to work on this project though. Excited to get down to bare-metal and really learn what it takes.