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

A few fixes (some specific for 5A-75B) #2

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
e54c51c
if you are not in the soc directory the svd files end up in the wrong…
nkrackow Apr 6, 2021
0dc8be3
1. For the colorlight5A-75b V7 there needs to be 0 tx delay, otherwis…
nkrackow Apr 6, 2021
071f0bb
commit build outputs for me
nkrackow Apr 6, 2021
cd3d9b4
blinkyblinkyblink :)
nkrackow Apr 6, 2021
cb8804c
Accedently pushed to master.. Revert "1. For the colorlight5A-75b V7 …
nkrackow Apr 7, 2021
246728e
Revert "Accedently pushed to master.. Revert "1. For the colorlight5A…
nkrackow Apr 7, 2021
c89baad
Thats what I wanted to revert.. Revert "commit build outputs for me"
nkrackow Apr 7, 2021
ddacad2
And that. Revert "blinkyblinkyblink :)"
nkrackow Apr 7, 2021
abeb9d3
adc with csr and data transmition via TCP and uart working
nkrackow Apr 11, 2021
a464df1
yay, interrupts are doing something at least!
nkrackow Apr 13, 2021
86aaf6c
using peripherals in interrupt routies works
nkrackow Apr 13, 2021
7428198
fixed ecpprog with two ftdis
nkrackow Apr 13, 2021
2f90d94
yey, fixed the interrupt storm!
nkrackow Apr 13, 2021
8c36144
Understanding the liteX event manager a bit now. still only timer tri…
nkrackow Apr 13, 2021
f8dd9e0
struggeling about with interrupts. They work but LED toggeling in the…
nkrackow Apr 20, 2021
e66af2e
Update README.md
nkrackow Apr 20, 2021
d6c1e7a
Update README.md
nkrackow Apr 20, 2021
58ff7a1
interrupt problems where due to memory congestion bc the man function…
nkrackow Apr 21, 2021
7e9c130
Merge branch 'interrupt_tryharding' of github.com:SingularitySurfer/R…
nkrackow Apr 21, 2021
5eea281
rename
nkrackow Apr 29, 2021
88dc0dc
baseline prepared
nkrackow Apr 29, 2021
994f0e3
pac formated! and interrupts now use the pac enum
nkrackow Apr 29, 2021
602b40a
IIR working i think
nkrackow Apr 30, 2021
5828360
ADC -> RiscV IRQ with Biquad IIR -> DAC works :) Using unsafe static …
nkrackow May 2, 2021
d543192
higher sample rate and led timing
nkrackow May 2, 2021
15ef3d7
Yay, tamed that computer into linearity, at least somewhat..
nkrackow May 3, 2021
5e76904
Update README.md
nkrackow May 3, 2021
db09340
Update README.md
nkrackow May 3, 2021
3306540
ratiometric ADC working :)
nkrackow May 3, 2021
d2e9621
Merge branch 'temp_controller_demo' of github.com:SingularitySurfer/R…
nkrackow May 3, 2021
a3470de
hmm so many thngs... Temperature control loop with ethernet tele some…
nkrackow May 4, 2021
032b1e4
pre-cleanup
nkrackow May 15, 2021
56042a7
HORRAYY computer likes when I say hi via TCP :)
nkrackow May 15, 2021
d571fe7
demo SoC working! :)
nkrackow May 16, 2021
9a3d3a3
Update README.md
nkrackow May 16, 2021
bc4136a
Update README.md
nkrackow May 16, 2021
200ad0d
Update README.md
nkrackow May 16, 2021
70ee1ce
Update README.md
nkrackow May 16, 2021
7be1726
cleanup for merge
nkrackow Jun 7, 2021
59200f2
Merge remote-tracking branch 'refs/remotes/origin/tcp_interface_tests…
nkrackow Jun 7, 2021
c3bf772
merge Readme
nkrackow Jun 7, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
# `Colorlight 5A-75X Litex Ethernet Demo`
# `Rust SoC Playground using LiteX, VexRiscV and the Colorlight 5A-75B board`

> Litex SoC and Rust software for [Colorlight 5A-75X][colorlight] board as a simple Ethernet demo.
This repository contains a lot of fun with rust and RiscV.

This project is developed and maintained by [DerFetzer][team].
The main branch is a small demo of a TCP connection with different options like turning LEDs on/off or registering an external button interrupt.
It is somewhat ceaned up and meant for people who want to get started.

## Usage
Most of the instructions are adapted from https://github.com/DerFetzer/colorlight-litex and https://github.com/icebreaker-fpga/icebreaker-litex-examples:

1. Install Litex as described [here][litex].
2. Install [ecpprog][ecpprog].
4. Connect a USB to JTAG adaptor to your board.
5. Build and flash the SOC with something like the following:
```
python soc/colorlight_5a_75x.py --build --flash --board=5a-75e --revision=6.0 --with-ethernet --sys-clk-freq 50e6 --use-internal-osc
python3 colorlight_5a_75x.py --flash --board=5a-75b --revision=7.0 --with-ethernet --sys-clk-freq 60e6

```
4. Follow the instructions in [eth_demo][eth_demo] to build the software.
4. Follow the instructions in [SoC_demo][SoC_demo] to build the software.


There are a few things added to the standard Colorlight 5A-75B. If you just want to try the SoC with one onboard LED, the onboard button and just the TX of the UART you do not need to modify anything.


Working in some branch:
- Ethernet with smoltcp thanks to https://github.com/DerFetzer/colorlight-litex
- Interrupts by staring a lot at https://github.com/betrusted-io/xous-core
- A simple second order sigma-delta ADC using a CIC decimator
- An IIR filter using on-chip sigma-delta ADC/DAC
- A peltier temperature controller using a custom on-SoC ratiometric ADC, an IIR filter triggered by timer interrupts, TCP telemetry, UDP temperature set and the onboard line drivers in parallel as peltier drivers ;)

## Credits

Expand All @@ -26,4 +39,4 @@ and the Litex [target file][target] for the Colorlight board.
[litex-example]: https://github.com/icebreaker-fpga/icebreaker-litex-examples
[colorlight]: http://www.colorlight-led.com/product/colorlight-5a-75e-led-display-receiving-card.html
[target]: https://github.com/litex-hub/litex-boards/blob/master/litex_boards/targets/colorlight_5a_75x.py
[eth_demo]: rust/eth_demo/README.md
[SoC_demo]: rust/SoC_demo/README.md
48 changes: 48 additions & 0 deletions python/recieve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import socket
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import datetime as dt

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('192.168.1.50', 1234))

msg = s.recv(4)
s.close()
val = int.from_bytes(msg, byteorder='big', signed=False)
print([x for x in msg])
print(val)

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
xs = []
ys = []



def animate(i, xs, ys):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('192.168.1.50', 1234))
msg = s.recv(4)
s.close()
val = int.from_bytes(msg, byteorder='big', signed=False)
print([x for x in msg])
print(val)
xs.append(dt.datetime.now().strftime('%H:%M:%S.%f'))
ys.append(val)
# Limit x and y lists to 100 items
xs = xs[-200:]
ys = ys[-200:]

# Draw x and y lists
ax.clear()
ax.plot(xs, ys)

# Format plot
plt.xticks(rotation=45, ha='right')
plt.subplots_adjust(bottom=0.30)
plt.title('SoCstream')
plt.ylabel('Temperature')

# Set up plot to call animate() function periodically
ani = animation.FuncAnimation(fig, animate, fargs=(xs, ys), interval=500)
plt.show()
9 changes: 9 additions & 0 deletions python/recieve_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('192.168.1.50', 1234))

msg = s.recv(1024)

print([x for x in msg])
Empty file added python/socket
Empty file.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ set -e
riscv64-unknown-elf-objcopy $1 -O binary $1.bin

# Program Colorlight
ecpprog -o 0x00100000 $1.bin
ecpprog -o 0x00100000 -d i:0x0403:0x6014:1 $1.bin
36 changes: 22 additions & 14 deletions rust/eth_demo/Cargo.lock → rust/SoC_demo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions rust/eth_demo/Cargo.toml → rust/SoC_demo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
[package]
name = "eth_demo"
name = "temp_controller"
version = "0.1.0"
authors = ["Piotr Esden-Tempski <[email protected]>", "DerFetzer <[email protected]>"]
authors = ["Piotr Esden-Tempski <[email protected]>", "DerFetzer <[email protected]>", "SingularitySurfer"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
litex-pac = { path = "../litex-pac" }
riscv-rt = "0.8.0"
riscv = "0.6.0"
vexriscv = "0.0.3"
panic-halt = "0.2"
log = "0.4.11"
smoltcp = { version = "0.6", default-features = false, features = ["ethernet", "proto-ipv4", "socket-udp" ,"socket-tcp", "log"] }
Expand All @@ -22,4 +24,3 @@ debug = true
# Improve code generation
lto = true
codegen-units = 1

19 changes: 6 additions & 13 deletions rust/eth_demo/README.md → rust/SoC_demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,22 @@ cargo run --release

It might be necessary to reset the board with a power cycle or by loading the SOC bitstream again.

You now should have a TCP endpoint at `192.168.1.50:1234` and a UDP endpoint at `192.168.1.50:5678` listening for connections.
You now should have a TCP endpoint at `192.168.1.50:1234`.

Connect your computer to the board's Ethernet port an assign a static IP from the `192.168.1.0/24` subnet.

You can now connect to the sockets and get a `Hello World!` back.
You can now connect to the SoC using netcat:

```
echo "" | netcat 192.168.1.50 1234
echo "" | netcat -u 192.168.1.50 5678
```
rlwrap nc -vv 192.168.1.50 1234

Connect a USB to UART adapter as described in [litex-boards][uart].
```

You should be able to access the console output by running the wishbone-tool.
Now you should have a TCP connection with the SoC and you can talk to it. For example just type "hi" and press enter. Or "led on". If you press the button on the board, you should get a "button pressed" message via TCP. Have a look at main.rs to see which commands the SoC can parse.

```
wishbone-tool --uart /dev/ttyUSB1 -s terminal
```

You can find the wishbone-tool here: https://github.com/litex-hub/wishbone-utils

NOTE: If you decided to build your SOC without the `--debug` parameter you can access the console output directly. For example using screen:
NOTE: You can also look at the UART output. Just connect a UART probe to the correct pins (look at the custom pinout at the top of the LiteX SoC description). Example using screen:

```
screen /dev/ttyUSB1 115200
Expand All @@ -63,4 +57,3 @@ To exit screen you can type `Ctrl-a k` or `Ctrl-a Ctrl-k`


[bug]: https://github.com/rust-lang/cargo/issues/7915#issuecomment-683294870
[uart]: https://github.com/litex-hub/litex-boards/blob/e4cdbe0f7ad0653e825556d992d233a1723273e3/litex_boards/targets/colorlight_5a_75x.py#L11
4 changes: 4 additions & 0 deletions rust/SoC_demo/rust-project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"rust.target": "riscv32imac-unknown-none-elf",
"rust.all_targets": false
}
16 changes: 16 additions & 0 deletions rust/SoC_demo/src/adc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use litex_pac::ADC;

pub struct Adc {
registers: ADC,
}

#[allow(dead_code)]
impl Adc {
pub fn new(registers: ADC) -> Self {
Self { registers }
}

pub fn read(&mut self) -> u32 {
self.registers.adc_value.read().bits()
}
}
18 changes: 18 additions & 0 deletions rust/SoC_demo/src/dac.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use litex_pac::DAC;

pub struct Dac {
registers: DAC,
}

#[allow(dead_code)]
impl Dac {
pub fn new(registers: DAC) -> Self {
Self { registers }
}

pub fn set(&mut self, value: u32) {
unsafe{
self.registers.val.write(|w| w.bits(value));
}
}
}
File renamed without changes.
103 changes: 103 additions & 0 deletions rust/SoC_demo/src/gpio.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
use litex_pac::GPIO;

pub struct Gpio {
registers: GPIO,
}

#[allow(dead_code)]
impl Gpio {
pub fn new(registers: GPIO) -> Self {
Self { registers }
}

pub fn status(&mut self) -> u32 {
self.registers.in_.read().bits()
}

pub fn set_interrupt_polarity(&mut self, pol: bool) {
unsafe {
if pol {
self.registers.polarity.write(|w| w.bits(1));
} else {
self.registers.polarity.write(|w| w.bits(0));
}
}
}

pub fn en_interrupt(&mut self) {
unsafe {
self.registers.ev_enable.write(|w| w.bits(0xFFFF_FFFF));
}
}

pub fn clr_interrupt(&mut self) {
unsafe {
self.registers.ev_pending.write(|w| w.bits(0xFFFF_FFFF));
}
}

pub fn dis_interrupt(&mut self) {
unsafe {
self.registers.ev_enable.write(|w| w.bits(0));
}
}

}

// pub struct Gpio2 {
// registers: GPIO2,
// }
//
// #[allow(dead_code)]
// impl Gpio2 {
//
// pub fn new(registers: GPIO2) -> Self {
// Self { registers }
// }
//
// pub fn status(&mut self) -> u32 {
// self.registers.in_.read().bits()
// }
//
// pub fn set_interrupt_polarity(&mut self, pol: bool) {
// unsafe {
// if pol {
// self.registers.polarity.write(|w| w.bits(1));
// }else {
// self.registers.polarity.write(|w| w.bits(0));
// }
// }
// }
//
// pub fn en_interrupt(&mut self) {
// unsafe {
//
// self.registers.ev_enable.write(|w| w.bits(0xffff));
// }
// }
//
// pub fn clr_interrupt(&mut self) {
// unsafe {
// self.registers.ev_pending.write(|w| w.bits(0xFFFF_FFFF));
// }
// }
//
// pub fn dis_interrupt(&mut self) {
// unsafe {
// self.registers.ev_enable.write(|w| w.bits(0));
// }
// }
//
// pub fn ev_pending(&mut self) -> u32 {
// self.registers.ev_pending.read().bits()
// }
//
// pub fn ev_status(&mut self) -> u32 {
// self.registers.ev_status.read().bits()
// }
//
// pub fn ev_enable(&mut self) -> u32 {
// self.registers.ev_enable.read().bits()
// }
//
// }
Loading