Skip to content

Commit 1ec473b

Browse files
committed
Added test of SPI interface.
1 parent 45b7004 commit 1ec473b

File tree

5 files changed

+123
-31
lines changed

5 files changed

+123
-31
lines changed

fpga/panologic_g2/fpga.ucf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ NET "uart_rxd_o" LOC="AB19" | IOSTANDARD=LVTTL; # AKA DDC2_SDA
6666
# Ethernet PHY
6767
NET "GMII_RST_N" LOC = R11 | IOSTANDARD = LVCMOS33;
6868

69-
#NET "led_red" LOC = E12 | IOSTANDARD = LVCMOS33;
69+
# Pano Button LED Output, Active High
70+
NET "led_red" LOC = E12 | IOSTANDARD = LVCMOS33;
7071
NET "led_blue" LOC = H13 | IOSTANDARD = LVCMOS33;
71-
#NET "led_green" LOC = F13 | IOSTANDARD = LVCMOS33;
72+
NET "led_green" LOC = F13 | IOSTANDARD = LVCMOS33;
73+
74+
# Pano Button Input, Active Low
75+
NET "pano_button" LOC = H12 | IOSTANDARD = LVCMOS33;
7276

fpga/panologic_g2/top.v

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
module top
55
(
66
input SYSCLK
7+
,inout pano_button
78
,output GMII_RST_N
8-
,output led_blue
9+
,output led_red
10+
,inout led_green
11+
,inout led_blue
912

1013
// UART
1114
,input uart_txd_i
@@ -16,15 +19,8 @@ module top
1619
,output flash_cs_o
1720
,output flash_si_o
1821
,input flash_so_i
19-
20-
// GPIO Headers
21-
,inout [11:0] porta
22-
,inout [11:0] portb
2322
);
2423

25-
wire [11:0] porta;
26-
wire [11:0] portb;
27-
2824
// Generate 32 Mhz system clock from 125 Mhz input clock
2925
wire clk32_i;
3026

@@ -105,7 +101,7 @@ fpga_top
105101
.CLK_FREQ(32000000)
106102
,.BAUDRATE(1000000) // SoC UART baud rate
107103
,.UART_SPEED(1000000) // Debug bridge UART baud (should match BAUDRATE)
108-
,.C_SCK_RATIO(50) // SPI clock divider (SPI_CLK=CLK_FREQ/C_SCK_RATIO)
104+
,.C_SCK_RATIO(1) // SPI clock divider (SPI_CLK=CLK_FREQ/C_SCK_RATIO)
109105
`ifdef CPU_SELECT_ARMV6M
110106
,.CPU("armv6m") // riscv or armv6m
111107
`else
@@ -142,25 +138,32 @@ assign flash_cs_o = spi_cs_w[0];
142138
assign spi_so_w = flash_so_i;
143139

144140
//-----------------------------------------------------------------
145-
// GPIO (Port A=gpio[11:0],...,Port B=gpio[27:16])
141+
// GPIO bits
142+
// 0: reserved for CPU reset (?)
143+
// 1: Pano button
144+
// 2: Output only - red LED
145+
// 3: In/out - green LED
146+
// 4: In/out - blue LED
147+
// 5...31: Not implmented
146148
//-----------------------------------------------------------------
147-
genvar i;
148-
generate
149-
for (i=0; i < 12; i=i+1)
150-
begin
151-
assign porta[i] = gpio_out_en_w[0+i] ? gpio_out_w[0+i] : 1'bz;
152-
assign portb[i] = gpio_out_en_w[16+i] ? gpio_out_w[16+i] : 1'bz;
153149

154-
assign gpio_in_w[0+i] = porta[i];
155-
assign gpio_in_w[16+i] = portb[i];
156-
end
157-
endgenerate
150+
assign pano_button = gpio_out_en_w[1] ? gpio_out_w[1] : 1'bz;
151+
assign gpio_in_w[1] = pano_button;
152+
153+
assign led_red = gpio_out_w[2];
154+
assign gpio_in_w[2] = led_red;
155+
156+
assign led_green = gpio_out_en_w[3] ? gpio_out_w[3] : 1'bz;
157+
assign gpio_in_w[3] = led_green;
158158

159+
assign led_blue = gpio_out_en_w[4] ? gpio_out_w[4] : 1'bz;
160+
assign gpio_in_w[4] = led_blue;
161+
162+
genvar i;
159163
generate
160-
for (i=12; i < 16; i=i+1)
164+
for (i=5; i < 31; i=i+1)
161165
begin
162-
assign gpio_in_w[0+i] = 1'b0;
163-
assign gpio_in_w[16+i] = 1'b0;
166+
assign gpio_in_w[i] = 1'b0;
164167
end
165168
endgenerate
166169

@@ -180,8 +183,6 @@ else
180183
// 'OR' two UARTs together
181184
assign uart_rxd_o = txd_q;
182185

183-
assign led_blue = uart_rxd_o;
184-
185186
// ODDR2 debug_buf (
186187
// .D0(1'b1),
187188
// .D1(1'b0),

src_c/arch/riscv/init.c

100644100755
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#include "irq_ctrl.h"
88
#endif
99

10+
#ifdef CONFIG_SPILITE
11+
#include "spi_lite.h"
12+
#endif
13+
1014
#ifdef CONFIG_MALLOC
1115
#include "malloc.h"
1216
#endif
@@ -20,12 +24,18 @@ static uint8_t _heap[CONFIG_MALLOC_SIZE];
2024
//-----------------------------------------------------------------
2125
void init(void)
2226
{
27+
#ifdef CONFIG_UARTLITE
2328
// Setup serial port
2429
uartlite_init(CONFIG_UARTLITE_BASE);
30+
#endif
2531

2632
// Register serial driver with printf
2733
printf_register(uartlite_putc);
2834

35+
#ifdef CONFIG_SPILITE
36+
spi_init(CONFIG_SPILITE_BASE);
37+
#endif
38+
2939
#ifdef CONFIG_MALLOC
3040
malloc_init(_heap, CONFIG_MALLOC_SIZE, 0, 0);
3141
#endif

src_c/main.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,89 @@
22
#include <unistd.h>
33
#include <stdio.h>
44
#include <stdlib.h>
5+
#include <string.h>
56

7+
#include "spi_lite.h"
68
#include "printf.h"
79

10+
void LogHex(void *Data,int Len);
11+
812
//-----------------------------------------------------------------
913
// main
1014
//-----------------------------------------------------------------
1115
int main(int argc, char *argv[])
1216
{
1317
int i;
18+
unsigned char Buf[256];
19+
int Id = 0;
1420
for(i = 0; i < 8; i++) {
1521
printf("helloworld!\n");
1622
}
1723

24+
printf("Spi read test\n");
25+
memset(Buf,0x55,sizeof(Buf));
26+
spi_cs(0);
27+
// read SPI flash device id
28+
spi_sendrecv(0x9f);
29+
// Read and toss first byte which was received while the command was
30+
// being shifted out
31+
spi_readblock(Buf,1);
32+
spi_readblock(Buf,3);
33+
spi_cs(1);
34+
printf("SPI flash JEDEC device ID:");
35+
for(i = 0; i < 3; i++) {
36+
Id <<= 8;
37+
Id += Buf[i];
38+
printf(" 0x%02x",Buf[i]);
39+
}
40+
printf("\n");
41+
42+
switch(Id) {
43+
case 0x202018:
44+
printf("M25P128 SPI flash confirmed\n");
45+
break;
46+
47+
case 0x202014:
48+
printf("M25P80 SPI flash confirmed\n");
49+
break;
50+
51+
default:
52+
printf("Unknown JEDEC ID\n");
53+
break;
54+
}
55+
56+
printf("\nReading first 256 bytes of flash...");
57+
spi_cs(0);
58+
spi_sendrecv(0x03);
59+
spi_sendrecv(0);
60+
spi_sendrecv(0);
61+
spi_sendrecv(0);
62+
spi_readblock(Buf,1);
63+
spi_readblock(Buf,sizeof(Buf));
64+
spi_cs(1);
65+
66+
printf("\n");
67+
LogHex(Buf,sizeof(Buf));
68+
1869
return 0;
1970
}
71+
72+
void LogHex(void *Data,int Len)
73+
{
74+
int i;
75+
uint8_t *cp = (uint8_t *) Data;
76+
77+
for(i = 0; i < Len; i++) {
78+
if(i != 0 && (i & 0xf) == 0) {
79+
printf("\n");
80+
}
81+
else if(i != 0) {
82+
printf(" ");
83+
}
84+
printf("%02x",cp[i]);
85+
}
86+
if(((i - 1) & 0xf) != 0) {
87+
printf("\n");
88+
}
89+
}
90+

src_c/makefile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,26 @@ PLATFORM = machine-fpga
44

55
EXTRA_CFLAGS+= -DCPU_KHZ=50000
66

7+
# UART driver
8+
EXTRA_CFLAGS += -DCONFIG_UARTLITE
9+
EXTRA_CFLAGS += -DCONFIG_UARTLITE_BASE=0x92000000
10+
11+
# SPI driver
12+
EXTRA_CFLAGS += -DCONFIG_SPILITE
13+
EXTRA_CFLAGS += -DCONFIG_SPILITE_BASE=0x93000000
14+
715
SRC_DIR = ./
816
SRC_DIR += ./include
917
SRC_DIR += ../soc/core_soc/src_c
1018

11-
# UART driver
12-
EXTRA_CFLAGS += -DCONFIG_UARTLITE
13-
EXTRA_CFLAGS += -DCONFIG_UARTLITE_BASE=0x92000000
14-
SRC_DIR += ./drivers/uart
1519

1620
BASE_ADDRESS = 0x0
1721
OPT = 2
1822

1923
TARGET_PORT ?= /dev/ttyUSB1
2024
RUN_PREFIX := ../run.py -d $(TARGET_PORT) -b 1000000 -f
2125

26+
ENABLE_LST=yes
27+
2228
MAKE_DIR=./make
2329
include $(MAKE_DIR)/makefile.exe

0 commit comments

Comments
 (0)