Skip to content

Commit 85fd39b

Browse files
committed
flash address decoding seems to work
1 parent c0cf648 commit 85fd39b

File tree

1 file changed

+49
-38
lines changed

1 file changed

+49
-38
lines changed

spispy.v

+49-38
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module top(
3737

3838
wire reset = 0;
3939

40+
/*
4041
reg [31:0] counter;
4142
always @(posedge clk_48)
4243
counter <= counter + 1;
@@ -45,6 +46,9 @@ module top(
4546
wire pwm_g;
4647
pwm pwm_g_driver(clk_48, 1, pwm_g);
4748
assign led_g = !(counter[25:23] == 0 && pwm_g);
49+
*/
50+
assign led_g = 1;
51+
4852

4953
// generate a 3 MHz/12 MHz serial clock from the 48 MHz clock
5054
// this is the 3 Mb/s maximum supported by the FTDI chip
@@ -81,7 +85,17 @@ module top(
8185
8286
assign debug0 = serial_txd;
8387
*/
88+
89+
// Emlated 256 bytes of flash ROM
90+
reg [23:0] read_addr;
91+
reg [7:0] flash_rom[0:255];
92+
wire [7:0] flash_data = flash_rom[read_addr[7:0]];
93+
94+
// initialize the flash_rom
95+
initial $readmemb("flash.bin", flash_rom);
96+
8497
// Connect the SPI port to the decoder
98+
reg spi_tx_strobe;
8599
wire spi_rx_strobe;
86100
wire [7:0] spi_rx_data;
87101

@@ -98,47 +112,35 @@ module top(
98112
*/
99113

100114
wire spi_cs_in = gpio_36;
101-
/*
102-
SB_IO #(
103-
.PIN_TYPE(1), // input
104-
.PULLUP(1), // pullup enabled
105-
) spi_cs_buffer (
106-
.PACKAGE_PIN(gpio_36),
107-
.D_IN_0(spi_cs_in)
108-
);
109-
*/
110115

111116
// copy the incoming CS pin to the outbound CS
112117
assign gpio_43 = gpio_36;
113118

114-
spi_device #(.MONITOR(1)) spi0(
119+
spi_device spi0(
115120
.mclk(clk_48),
116121
.reset(reset),
117122
.spi_cs(spi_cs_in),
118123
.spi_clk(gpio_28),
119124
.spi_mosi(gpio_38),
120-
.spi_miso(gpio_42),
125+
.spi_miso_in(gpio_42),
126+
//.spi_miso_out(),
127+
.spi_tx_data(flash_data),
128+
.spi_tx_strobe(spi_tx_strobe),
121129
.spi_rx_strobe(spi_rx_strobe),
122130
.spi_rx_data(spi_rx_data)
123131
);
124132

125133
reg [12:0] bytes;
126-
reg newline;
127-
reg spi_ready;
134+
reg [15:0] serial_out;
135+
reg do_serial;
136+
reg do_hex;
128137
reg spi_cs_buf;
129138
reg spi_cs_prev;
130139
reg spi_cs_sync;
131140

132141
assign led_b = spi_cs_sync; // idles high
133142

134143
reg read_in_progress;
135-
reg [23:0] read_addr;
136-
reg [7:0] flash_rom[0:255];
137-
wire [7:0] flash_data = flash_rom[read_addr[7:0]];
138-
139-
// initialize the flash_rom
140-
initial $readmemb("flash.bin", flash_rom);
141-
142144
// watch for new commands on the SPI bus, print first x bytes
143145
always @(posedge clk_48)
144146
begin
@@ -148,8 +150,8 @@ module top(
148150
spi_cs_sync <= spi_cs_prev;
149151

150152
// Default is no output from the SPI bus
151-
newline <= 0;
152-
spi_ready <= 0;
153+
do_serial <= 0;
154+
do_hex <= 0;
153155

154156
if (reset) begin
155157
// nothing to do
@@ -158,54 +160,63 @@ module top(
158160
// falling edge of the CS, reset the transaction
159161
bytes <= 0;
160162
if (read_in_progress) begin
161-
newline <= 1;
162-
spi_ready <= 1;
163+
serial_out = "\r\n";
164+
do_serial <= 1;
163165
end
164166
read_in_progress <= 0;
165167
end else
166168
if (spi_cs_sync && !spi_cs_prev) begin
167169
// rising edge of the CS, send newline if we
168170
// have received a non-zero number of bytes
169-
if (read_in_progress) begin
170-
newline <= 1;
171-
spi_ready <= 1;
172-
end
173171
read_in_progress <= 0;
174172
end else
175173
if (spi_rx_strobe) begin
176174
// new byte on the wire; print the first four bytes
177175
// parse the command in the first byte
178176
if (bytes == 0 && spi_rx_data == 3) begin
179-
//spi_ready <= 1;
180177
read_in_progress <= 1;
181178
end else
182179
if (bytes <= 3 && read_in_progress)
183180
begin
184-
spi_ready <= 1;
185181
read_addr <= { read_addr[15:8], spi_rx_data };
186-
//if (bytes == 3 && read_addr[
182+
do_serial <= 1;
183+
do_hex <= 1;
187184
end else
188185
if (read_in_progress)
189186
begin
190-
spi_tx_data <= flash_rom[read_addr];
191187
read_addr <= read_addr + 1;
192188
end
193189

194190
bytes <= bytes + 1;
191+
end else begin
192+
/*
193+
if (read_addr == 24'hFFB880) begin
194+
// disable flash address overlays
195+
do_overlay <= 0;
196+
do_serial <= 1;
197+
serial_out <= "--";
198+
end else
199+
if (read_addr == 24'hFFB800) begin
200+
// enable overlay
201+
do_overlay <= 1;
202+
do_serial <= 1;
203+
serial_out <= "++";
204+
end
205+
*/
195206
end
196207
end
197208

209+
198210
reg fifo_read_strobe;
199211
wire fifo_available;
200212

201213
fifo_spram_16to8 buffer(
202214
.clk(clk_48),
203215
.reset(reset),
204-
.write_data( newline ? "\r\n" : {
205-
hexdigit(spi_rx_data[7:4]),
206-
hexdigit(spi_rx_data[3:0])
207-
}),
208-
.write_strobe(spi_ready),
216+
.write_data(do_hex
217+
? { hexdigit(spi_rx_data[7:4]), hexdigit(spi_rx_data[3:0]) }
218+
: serial_out),
219+
.write_strobe(do_serial) ,
209220
.data_available(fifo_available),
210221
.read_data(uart_txd),
211222
.read_strobe(fifo_read_strobe)
@@ -219,7 +230,7 @@ module top(
219230
// single port fifo can't read/write the same cycle
220231
if (fifo_available
221232
&& uart_txd_ready
222-
&& !spi_ready
233+
&& !do_serial
223234
&& !uart_txd_strobe
224235
) begin
225236
fifo_read_strobe <= 1;

0 commit comments

Comments
 (0)