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

Single spi #4

Closed
wants to merge 26 commits into from
Closed
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ddbf7e3
glitches
mattvenn Nov 15, 2018
4734746
savefile
mattvenn Nov 16, 2018
05b7d34
savefile
mattvenn Nov 16, 2018
e1f09eb
looking at null bytes
mattvenn Nov 16, 2018
067cc73
move gtkwave filters
Nov 18, 2018
f21638c
working with regular clock
Nov 18, 2018
9760a04
tidy up sspi dir
Nov 18, 2018
5a43d03
formal
Nov 18, 2018
696e225
formally verified with CDC
mattvenn Nov 19, 2018
e006d8e
assign spi_rdy and err high
mattvenn Nov 19, 2018
e229432
added more testbench support files
mattvenn Nov 20, 2018
a25d0c4
no_glitch localparam to turn on clock glitching
mattvenn Nov 20, 2018
ed19d85
testing spi comms and camera
mattvenn Nov 21, 2018
07048df
wait for acks properly by controlling cs pin manually
mattvenn Nov 21, 2018
332e583
add length and position to read and write routines
mattvenn Nov 21, 2018
a9efb1b
random write/read test
mattvenn Nov 21, 2018
1ae583a
kernel upload, run and readout works, but only with 128byte reads
mattvenn Nov 21, 2018
b67c8d5
fixed ACK: working with 1024 byte write/reads
mattvenn Nov 21, 2018
4575fe0
nicer formatting
mattvenn Nov 21, 2018
02e10bd
include spi client verilog
mattvenn Nov 26, 2018
1bbcbb3
pcf for lattice up5k dev board
mattvenn Nov 26, 2018
5a1619e
gtkwave config
mattvenn Nov 26, 2018
931fafa
Merge branch 'single_spi_reg_clock' of mattvenn.net:~/symbiotic_eda/m…
mattvenn Nov 26, 2018
443d1e4
change print for python2
mattvenn Nov 26, 2018
9f1006e
Merge branch 'single_spi_reg_clock' of mattvenn.net:~/symbiotic_eda/m…
mattvenn Nov 26, 2018
ed52c10
pinout
mattvenn Nov 26, 2018
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -23,7 +23,8 @@ ML_RTL = \
../rtl/top.v \
../rtl/sequencer.v \
../rtl/compute.v \
../rtl/memory.v
../rtl/memory.v \
../rtl/spi_client.v

#####################################################################

@@ -1,12 +1,12 @@
set_io clock 35

set_io qpi_csb 2
set_io qpi_clk 4
set_io spi_csb 2
set_io spi_clk 46

set_io qpi_io0 47
set_io qpi_io1 45
set_io qpi_io2 3
set_io qpi_io3 48
set_io spi_mosi 44
set_io spi_miso 47

set_io qpi_rdy 46
set_io qpi_err 44
set_io spi_rdy 45
set_io spi_err 48

#
@@ -0,0 +1,46 @@
# Raspberry Pi Support

## Run the mlaccel testbench with Python

Enable spi with raspi-config:

* spidev for spi comms

Install Python modules spidev and RPi.GPIO:

* sudo pip install spidev
* sudo pip install RPi.GPIO

Connect the Pi's SPI pins to the pins defined in the [UP5k dev board's pcf](../demo/mlaccel.pcf).

![pinout](pinout.jpeg)

Run the test:

python spi_test.py

## Camera SPI Demo

This demo will eventually stream video to the mlaccel core over SPI. For now it just
captures frames and sends the raw data over SPI to an imaginary receiver.

Install opencv the easy way:

sudo apt-get update
sudo apt-get install python-opencv

Install Python modules picamera and spidev:

sudo pip install "picamera[array]"
sudo pip install spidev

Enable interfaces with raspi-config:

* enable camera for camera module
* spidev for spi comms

Now [cam_to_spi.py](cam_to_spi.py) should:

* read a frame from the camera
* resize according to the resolution set by export_resolution
* send the frame row by row over SPI
@@ -0,0 +1,57 @@
# import the necessary packages
from picamera.array import PiRGBArray
from picamera import PiCamera
import spidev
import time
import cv2

# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()

export_resolution = (16, 16)
camera_res = (32, 32)

camera.resolution = camera_res
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=camera_res)

# allow the camera to warmup
time.sleep(0.1)


import spidev
spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 8000000

# capture frames from the camera
time_start = time.time()
frames = 0
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
# grab the raw NumPy array representing the image, then initialize the timestamp
# and occupied/unoccupied text
image = frame.array

#grey scale
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# resize
if export_resolution != camera_res:
image = cv2.resize(image, dsize=export_resolution, interpolation=cv2.INTER_CUBIC)

#cv2.imshow("Frame", image)
key = cv2.waitKey(1) & 0xFF

#print(image[0])
for row in image:
spi.xfer(row.tolist())
# clear the stream in preparation for the next frame
rawCapture.truncate(0)

# if the `q` key was pressed, break from the loop
if key == ord("q"):
break
frames += 1
if frames % 100 == 0:
print(time.time() - time_start)
time_start = time.time()
ProTip! Use n and p to navigate between commits in a pull request.