Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

valentyusb serial #347

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft

valentyusb serial #347

wants to merge 4 commits into from

Conversation

mkj
Copy link
Contributor

@mkj mkj commented Feb 10, 2022

This adds valentyusb as a uart, works for orangecrab though should be applicable to other platforms.

I'm leaving this as a draft pull request because the software side needs a bit of tidying up - usb_hello is a bit of a demo, really console.c should switch similarly to potato?

It isn't 100% reliable, I have sometimes had the Linux system lock up, yet to debug.

Note that the UART TX will wait forever until a USB host starts reading the USB tty - just "cat /dev/ttyUSBS0" may not be reliable enough and the board will seem to get stuck (screen /dev/ttyUSBS0 works OK).

An early kernel liteuart driver is in mkj/linux@9b3975d

@umarcor
Copy link
Contributor

umarcor commented Feb 10, 2022

FTR, stnolting/neorv32#102.

@programmerjake
Copy link

I tried this out, to get usb_hello to build, I had to simlink hello_world/head.S into usb_hello.

https://libre-soc.org/irclog/%23libre-soc.2022-03-03.log.html

I didn't get it to work fully:
the USB interface appears to work correctly, and the OrangeCrab's button works, but microwatt appears to never read/write the serial interface.

commands I ran:

(cd usb_hello; ln -s ../hello_world/head.S .; make)
sudo make FPGA_TARGET=ORANGE-CRAB-0.21 dfuprog DOCKER=1 RAM_INIT_FILE=usb_hello/usb_hello.hex MEMORY_SIZE=$((1<<18))

Also, why is usb_hello.elf included in this PR?

@programmerjake
Copy link

also, it would probably be useful to have the button reset only microwatt if pressed for a short interval, but also reset the usb interface if pressed for a longer interval, that way you can catch whatever microwatt tries to do immediately after reset, but before the host sets up the usb device.

mkj added 4 commits March 4, 2022 10:49
Signed-off-by: Matt Johnston <[email protected]>
An extra uart is added at 0xc0008000 attached to valentyusb, using
the OrangeCrab's onboard USB port.
This has a liteuart interface, an identifier bit is added to syscon.

Generated from branch hw_cdc_eptri of
https://github.com/litex-hub/valentyusb

The generate script is based on valentyusb/sim/generate_verilog.py

UARTUSB: usbserial@8000 {
        device_type = "serial";
        compatible = "litex,liteuart";
        reg = <0x8000 0x100>;
        interrupts = <0x15 0x1>;
};

(requires extra kernel patches for early console at present v5.16)

Signed-off-by: Matt Johnston <[email protected]>
usb_hello is a copy of hello_world but uses both consoles

Signed-off-by: Matt Johnston <[email protected]>
That makes it easier to override a non-litedram build for testing
RAM_INIT_FILE, eg

make microwatt.dfu  LITEDRAM_GHDL_ARG=-gUSE_LITEDRAM=false  RAM_INIT_FILE=usb_hello/usb_hello.hex

Signed-off-by: Matt Johnston <[email protected]>
@mkj
Copy link
Contributor Author

mkj commented Mar 4, 2022

microwatt appears to never read/write the serial interface.

Ah, it's because by default it builds litedram which doesn't use RAM_INIT_FILE.
I've pushed an update, it should work now:

make FPGA_TARGET=ORANGE-CRAB-0.21 dfuprog DOCKER=1 LITEDRAM_GHDL_ARG=-gUSE_LITEDRAM=false RAM_INIT_FILE=usb_hello/usb_hello.hex MEMORY_SIZE=$((1<<18))

The usb tx on the microwatt side will wait for a host to be attached to the usb serial terminal, so it isn't critical to connect straight away. At some point that would need fixing though.

I've also added head.S and rebased to master branch, seems fine in quick testing (4cf2921 had some changes). I've removed usb_hello.elf.

(unrelated - when I tried a latest docker build, routing was taking hours. Perhaps a recent toolchain update is problematic, an older oss-cad-suite 20220118 is OK here)

@programmerjake
Copy link

tested...it works for me now! hopefully I can figure out how to get it to work with litedram though, since I want to try to boot linux at some point, and the fpga's memory is likely too small for that

@mkj
Copy link
Contributor Author

mkj commented Mar 4, 2022

It will work OK with litedram, just the default litedram init code is using console.c functions which write to uart0 not the usb uart. If you modify console.c so that it calls usb_putchar() instead of putchar() it should print the microwatt "boot loading" messages to the valentyusb. You'll need to rebuild the litedram_core.init by running litedram/gen-src/generate.py - with litex/litex-board/litedram etc in your python path.

Upstream Linux already has a liteuart serial driver, you can enable it in the devicetree with

UARTUSB: usbserial@8000 {
        device_type = "serial";
        compatible = "litex,liteuart";
        reg = <0x8000 0x100>;
        interrupts = <0x15 0x1>;
};

        chosen {
                stdout-path = &UARTUSB;
        }

The branch https://github.com/mkj/linux/commits/matt/orangecrab also has a liteuart driver for powerpc early boot. mkj/linux@9b3975d - not necessary but is useful to see what's going on.

programmerjake added a commit to programmerjake/microwatt that referenced this pull request Mar 4, 2022
I added a simple 3D maze game that is a pretty impressive demo of what Microwatt can do.

It's based on antonblanchard#347

Signed-off-by: Jacob Lifshay <[email protected]>
@paulusmack
Copy link
Collaborator

It's a pity this doesn't just have a standard 16550 register interface. That would make the software side so much easier.

@programmerjake
Copy link

any progress?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants