1 |
2 |
ldalmasso |
------------------------------------------------------------------------
|
2 |
|
|
-- Engineer: Dalmasso Loic
|
3 |
|
|
-- Create Date: 04/03/2025
|
4 |
|
|
-- Module Name: PmodSF3Driver
|
5 |
|
|
-- Description:
|
6 |
|
|
-- Pmod SF3 Driver for the 32 MB NOR Flash memory MT25QL256ABA.
|
7 |
|
|
-- The communication with the Flash uses the SPI protocol (Simple, Dual or Quad SPI modes, dynamically configurable).
|
8 |
|
|
-- User specifies the System Input Clock and the Pmod SF3 Driver dynamically computes the SPI Serial Clock Frequency according to the actual Dummy Cycles
|
9 |
|
|
-- User specifies the maximum bytes buffer used for data read & write.
|
10 |
|
|
-- For each read/write operation, user specifies the number of expected address and data bytes, 'i_addr_bytes' and 'i_data_bytes' respectively.
|
11 |
|
|
--
|
12 |
|
|
-- Usage:
|
13 |
|
|
-- The 'o_ready' signal indicates this module is ready to start new SPI transmission.
|
14 |
|
|
-- The 'i_start' signal starts the SPI communication, according to the mode 'i_rw' (Read or Write memory), command/address/data bytes and the expected number of bytes.
|
15 |
|
|
-- In Read operation, when the 'o_data_ready', data from memory is available in 'o_data' signal.
|
16 |
|
|
--
|
17 |
|
|
-- Generics
|
18 |
|
|
-- sys_clock: System Input Clock Frequency (Hz)
|
19 |
|
|
-- Ports
|
20 |
|
|
-- Input - i_sys_clock: System Input Clock
|
21 |
|
|
-- Input - i_reset: Module Reset ('0': No Reset, '1': Reset)
|
22 |
|
|
-- Input - i_start: Start SPI Transmission ('0': No Start, '1': Start)
|
23 |
|
|
-- Input - i_rw: Read / Write Mode ('0': Write, '1': Read)
|
24 |
|
|
-- Input - i_command: FLASH Command Byte
|
25 |
|
|
-- Input - i_addr_bytes: Number of Address Bytes
|
26 |
|
|
-- Input - i_addr: FLASH Address Bytes
|
27 |
|
|
-- Input - i_data_bytes: Number of Data Bytes to Read/Write
|
28 |
|
|
-- Input - i_data: FLASH Data Bytes to Write
|
29 |
|
|
-- Output - o_data: Read FLASH Data Bytes
|
30 |
|
|
-- Output - o_data_ready: FLASH Data Output Ready (Read Mode) ('0': NOT Ready, '1': Ready)
|
31 |
|
|
-- Output - o_ready: Module Ready ('0': NOT Ready, '1': Ready)
|
32 |
|
|
-- Output - o_reset: FLASH Reset ('0': Reset, '1': No Reset)
|
33 |
|
|
-- Output - o_sclk: SPI Serial Clock
|
34 |
|
|
-- In/Out - io_dq: SPI Data Lines (Simple, Dual or Quad Modes)
|
35 |
|
|
-- Output - o_ss: SPI Slave Select Line ('0': Enable, '1': Disable)
|
36 |
|
|
-- Output - o_using_sys_freq: System Input Clock as SPI Serial Clock Frequency ('0': Disable, '1': Enable)
|
37 |
|
|
------------------------------------------------------------------------
|
38 |
|
|
|
39 |
|
|
LIBRARY IEEE;
|
40 |
|
|
USE IEEE.STD_LOGIC_1164.ALL;
|
41 |
|
|
USE IEEE.NUMERIC_STD.ALL;
|
42 |
|
|
|
43 |
|
|
ENTITY Testbench_PmodSF3Driver is
|
44 |
|
|
END Testbench_PmodSF3Driver;
|
45 |
|
|
|
46 |
|
|
ARCHITECTURE Behavioral of Testbench_PmodSF3Driver is
|
47 |
|
|
|
48 |
|
|
COMPONENT PmodSF3Driver is
|
49 |
|
|
|
50 |
|
|
GENERIC(
|
51 |
|
|
sys_clock: INTEGER := 100_000_000;
|
52 |
|
|
max_data_byte: INTEGER := 1
|
53 |
|
|
);
|
54 |
|
|
|
55 |
|
|
PORT(
|
56 |
|
|
i_sys_clock: IN STD_LOGIC;
|
57 |
|
|
i_reset: IN STD_LOGIC;
|
58 |
|
|
i_start: IN STD_LOGIC;
|
59 |
|
|
i_rw: IN STD_LOGIC;
|
60 |
|
|
i_command: IN UNSIGNED(7 downto 0);
|
61 |
|
|
i_addr_bytes: IN INTEGER range 0 to 4;
|
62 |
|
|
i_addr: IN UNSIGNED(23 downto 0);
|
63 |
|
|
i_data_bytes: IN INTEGER range 0 to max_data_byte;
|
64 |
|
|
i_data: IN UNSIGNED((max_data_byte*8)-1 downto 0);
|
65 |
|
|
o_data: OUT UNSIGNED((max_data_byte*8)-1 downto 0);
|
66 |
|
|
o_data_ready: OUT STD_LOGIC;
|
67 |
|
|
o_ready: OUT STD_LOGIC;
|
68 |
|
|
o_reset: OUT STD_LOGIC;
|
69 |
|
|
o_sclk: OUT STD_LOGIC;
|
70 |
|
|
io_dq: INOUT STD_LOGIC_VECTOR(3 downto 0);
|
71 |
|
|
o_ss: OUT STD_LOGIC;
|
72 |
|
|
o_spi_using_sys_freq: OUT STD_LOGIC
|
73 |
|
|
);
|
74 |
|
|
|
75 |
|
|
END COMPONENT;
|
76 |
|
|
|
77 |
|
|
signal sys_clock: STD_LOGIC := '0';
|
78 |
|
|
signal reset: STD_LOGIC := '0';
|
79 |
|
|
signal start: STD_LOGIC := '0';
|
80 |
|
|
signal mode: STD_LOGIC := '0';
|
81 |
|
|
signal command: UNSIGNED(7 downto 0) := (others => '0');
|
82 |
|
|
signal addr_bytes: INTEGER range 0 to 3 := 0;
|
83 |
|
|
signal addr: UNSIGNED(23 downto 0):= (others => '0');
|
84 |
|
|
signal data_bytes: INTEGER := 0;
|
85 |
|
|
signal data_w: UNSIGNED(7 downto 0):= (others => '0');
|
86 |
|
|
signal data_r: UNSIGNED(7 downto 0):= (others => '0');
|
87 |
|
|
signal data_ready: STD_LOGIC := '0';
|
88 |
|
|
|
89 |
|
|
signal ready: STD_LOGIC := '0';
|
90 |
|
|
signal reset_mem: STD_LOGIC := '0';
|
91 |
|
|
signal sclk: STD_LOGIC := '0';
|
92 |
|
|
signal dq: STD_LOGIC_VECTOR(3 downto 0) := (others => '0');
|
93 |
|
|
signal ss: STD_LOGIC := '1';
|
94 |
|
|
signal spi_using_sys_freq: STD_LOGIC := '1';
|
95 |
|
|
|
96 |
|
|
begin
|
97 |
|
|
|
98 |
|
|
-- Clock 100 MHz
|
99 |
|
|
sys_clock <= not(sys_clock) after 5 ns;
|
100 |
|
|
|
101 |
|
|
-- Reset
|
102 |
|
|
reset <= '1', '0' after 145 ns;
|
103 |
|
|
|
104 |
|
|
-- Start
|
105 |
|
|
start <= '0',
|
106 |
|
|
-- SPI Single Mode --
|
107 |
|
|
-- Read Volatile Dummy Cycles
|
108 |
|
|
'1' after 200 ns, '0' after 326 ns,
|
109 |
|
|
-- Read Volatile SPI Mode
|
110 |
|
|
'1' after 2000 ns, '0' after 2300 ns,
|
111 |
|
|
-- Write Data
|
112 |
|
|
'1' after 3000 ns, '0' after 3300 ns,
|
113 |
|
|
-- Write Volatile Dummy Cycles (2)
|
114 |
|
|
'1' after 5000 ns, '0' after 5300 ns,
|
115 |
|
|
-- Write Volatile SPI Mode (Dual)
|
116 |
|
|
'1' after 7000 ns, '0' after 7300 ns,
|
117 |
|
|
|
118 |
|
|
-- SPI Dual Mode --
|
119 |
|
|
-- Read Volatile Dummy Cycles (2)
|
120 |
|
|
'1' after 8000 ns, '0' after 8050 ns,
|
121 |
|
|
-- Read Volatile SPI Mode (Dual)
|
122 |
|
|
'1' after 9000 ns, '0' after 9050 ns,
|
123 |
|
|
-- Write Data
|
124 |
|
|
'1' after 10000 ns, '0' after 10300 ns,
|
125 |
|
|
-- Write Volatile Dummy Cycles (0)
|
126 |
|
|
'1' after 11000 ns, '0' after 11050 ns,
|
127 |
|
|
-- Write Volatile SPI Mode (Quad)
|
128 |
|
|
'1' after 12000 ns, '0' after 12050 ns,
|
129 |
|
|
|
130 |
|
|
-- SPI Quad Mode --
|
131 |
|
|
-- Read Volatile Dummy Cycles (0)
|
132 |
|
|
'1' after 13000 ns, '0' after 13025 ns,
|
133 |
|
|
-- Read Volatile SPI Mode (Quad)
|
134 |
|
|
'1' after 14000 ns, '0' after 14025 ns,
|
135 |
|
|
-- Write Data
|
136 |
|
|
'1' after 15000 ns, '0' after 15025 ns,
|
137 |
|
|
|
138 |
|
|
-- Write Volatile Dummy Cycles (5)
|
139 |
|
|
'1' after 16000 ns, '0' after 16025 ns,
|
140 |
|
|
-- Read Data
|
141 |
|
|
'1' after 17000 ns, '0' after 17025 ns;
|
142 |
|
|
|
143 |
|
|
-- Memory Operation Mode (Read then Write)
|
144 |
|
|
mode <= -- SPI Single Mode --
|
145 |
|
|
-- Read Volatile Dummy Cycles & Read Volatile SPI Mode
|
146 |
|
|
'1',
|
147 |
|
|
-- Write Data, Write Volatile Dummy Cycles (2), Write Volatile SPI Mode (Dual)
|
148 |
|
|
'0' after 2500 ns,
|
149 |
|
|
|
150 |
|
|
-- SPI Dual Mode --
|
151 |
|
|
-- Read Volatile Dummy Cycles (2) & Read Volatile SPI Mode Dual)
|
152 |
|
|
'1' after 7800 ns,
|
153 |
|
|
-- Write Data, Write Volatile Dummy Cycles (0), Write Volatile SPI Mode (Quad)
|
154 |
|
|
'0' after 9800 ns,
|
155 |
|
|
|
156 |
|
|
-- SPI Quad Mode --
|
157 |
|
|
-- Read Volatile Dummy Cycles (0) & Read Volatile SPI Mode (Quad)
|
158 |
|
|
'1' after 12800 ns,
|
159 |
|
|
-- Write Data
|
160 |
|
|
'0' after 14800 ns,
|
161 |
|
|
-- Read Data
|
162 |
|
|
'1' after 16800 ns;
|
163 |
|
|
|
164 |
|
|
-- Command
|
165 |
|
|
command <=
|
166 |
|
|
-- SPI Single Mode --
|
167 |
|
|
-- Read Volatile Dummy Cycles
|
168 |
|
|
x"85" after 180 ns,
|
169 |
|
|
-- Read Volatile SPI Mode
|
170 |
|
|
x"65" after 1800 ns,
|
171 |
|
|
-- Write Data
|
172 |
|
|
x"AB" after 2800 ns,
|
173 |
|
|
-- Write Volatile Dummy Cycles (2)
|
174 |
|
|
x"81" after 4800 ns,
|
175 |
|
|
-- Write Volatile SPI Mode (Dual)
|
176 |
|
|
x"61" after 6800 ns,
|
177 |
|
|
|
178 |
|
|
-- SPI Dual Mode --
|
179 |
|
|
-- Read Volatile Dummy Cycles (2)
|
180 |
|
|
x"85" after 7800 ns,
|
181 |
|
|
-- Read Volatile SPI Mode (Dual)
|
182 |
|
|
x"65" after 8800 ns,
|
183 |
|
|
-- Write Data
|
184 |
|
|
x"AB" after 9800 ns,
|
185 |
|
|
-- Write Volatile Dummy Cycles (0)
|
186 |
|
|
x"81" after 10800 ns,
|
187 |
|
|
-- Write Volatile SPI Mode (Quad)
|
188 |
|
|
x"61" after 11800 ns,
|
189 |
|
|
|
190 |
|
|
-- SPI Quad Mode --
|
191 |
|
|
-- Read Volatile Dummy Cycles (0)
|
192 |
|
|
x"85" after 12800 ns,
|
193 |
|
|
-- Read Volatile SPI Mode (Quad)
|
194 |
|
|
x"65" after 13800 ns,
|
195 |
|
|
-- Write Data
|
196 |
|
|
x"AB" after 14800 ns,
|
197 |
|
|
|
198 |
|
|
-- Write Volatile Dummy Cycles (5)
|
199 |
|
|
x"81" after 15800 ns,
|
200 |
|
|
-- Read Data
|
201 |
|
|
x"AB" after 16800 ns;
|
202 |
|
|
|
203 |
|
|
-- Address Bytes
|
204 |
|
|
addr_bytes <=
|
205 |
|
|
-- SPI Single Mode --
|
206 |
|
|
-- Read Volatile Dummy Cycles
|
207 |
|
|
|
208 |
|
|
-- Read Volatile SPI Mode
|
209 |
|
|
|
210 |
|
|
-- Write Data
|
211 |
|
|
3 after 2800 ns,
|
212 |
|
|
-- Write Volatile Dummy Cycles (2) & Write Volatile SPI Mode (Dual)
|
213 |
|
|
|
214 |
|
|
|
215 |
|
|
-- SPI Dual Mode --
|
216 |
|
|
-- Read Volatile Dummy Cycles (2)
|
217 |
|
|
|
218 |
|
|
-- Read Volatile SPI Mode (Dual)
|
219 |
|
|
|
220 |
|
|
-- Write Data
|
221 |
|
|
3 after 9800 ns,
|
222 |
|
|
-- Write Volatile Dummy Cycles (0)
|
223 |
|
|
|
224 |
|
|
-- Write Volatile SPI Mode (Quad)
|
225 |
|
|
|
226 |
|
|
|
227 |
|
|
-- SPI Quad Mode --
|
228 |
|
|
-- Read Volatile Dummy Cycles (0)
|
229 |
|
|
|
230 |
|
|
-- Read Volatile SPI Mode (Quad)
|
231 |
|
|
|
232 |
|
|
-- Write Data
|
233 |
|
|
1 after 14800 ns,
|
234 |
|
|
|
235 |
|
|
-- Write Volatile Dummy Cycles (5)
|
236 |
|
|
|
237 |
|
|
-- Read Data
|
238 |
|
|
3 after 16800 ns;
|
239 |
|
|
|
240 |
|
|
-- Address
|
241 |
|
|
addr <= x"123456";
|
242 |
|
|
|
243 |
|
|
-- Data Bytes
|
244 |
|
|
data_bytes <=
|
245 |
|
|
-- SPI Single Mode --
|
246 |
|
|
-- Read Volatile Dummy Cycles
|
247 |
|
|
1 after 180 ns,
|
248 |
|
|
-- Read Volatile SPI Mode
|
249 |
|
|
1 after 1800 ns,
|
250 |
|
|
-- Write Data
|
251 |
|
|
2 after 2800 ns,
|
252 |
|
|
-- Write Volatile Dummy Cycles (2) & Write Volatile SPI Mode (Dual)
|
253 |
|
|
1 after 4800 ns,
|
254 |
|
|
|
255 |
|
|
-- SPI Dual Mode --
|
256 |
|
|
-- Read Volatile Dummy Cycles (2)
|
257 |
|
|
1 after 7800 ns,
|
258 |
|
|
-- Read Volatile SPI Mode (Dual)
|
259 |
|
|
1 after 8800 ns,
|
260 |
|
|
-- Write Data
|
261 |
|
|
3 after 9800 ns,
|
262 |
|
|
-- Write Volatile Dummy Cycles (0)
|
263 |
|
|
1 after 10800 ns,
|
264 |
|
|
-- Write Volatile SPI Mode (Quad)
|
265 |
|
|
1 after 11800 ns,
|
266 |
|
|
|
267 |
|
|
-- SPI Quad Mode --
|
268 |
|
|
-- Read Volatile Dummy Cycles (0)
|
269 |
|
|
1 after 12800 ns,
|
270 |
|
|
-- Read Volatile SPI Mode (Quad)
|
271 |
|
|
1 after 13800 ns,
|
272 |
|
|
-- Write Data
|
273 |
|
|
1 after 14800 ns,
|
274 |
|
|
|
275 |
|
|
-- Write Volatile Dummy Cycles (5)
|
276 |
|
|
1 after 15800 ns,
|
277 |
|
|
-- Read Data
|
278 |
|
|
1 after 16800 ns;
|
279 |
|
|
|
280 |
|
|
-- Data to Write
|
281 |
|
|
data_w <=
|
282 |
|
|
-- SPI Single Mode --
|
283 |
|
|
-- Read Volatile Dummy Cycles
|
284 |
|
|
(others => '0') after 180 ns,
|
285 |
|
|
-- Read Volatile SPI Mode
|
286 |
|
|
(others => '0') after 1800 ns,
|
287 |
|
|
-- Write Data
|
288 |
|
|
x"8B" after 2800 ns,
|
289 |
|
|
-- Write Volatile Dummy Cycles (2)
|
290 |
|
|
"00101011" after 4800 ns,
|
291 |
|
|
-- Write Volatile SPI Mode (Dual)
|
292 |
|
|
"10111111" after 6800 ns,
|
293 |
|
|
|
294 |
|
|
-- SPI Dual Mode --
|
295 |
|
|
-- Read Volatile Dummy Cycles (2) & Read Volatile SPI Mode (Dual)
|
296 |
|
|
(others => '0') after 7800 ns,
|
297 |
|
|
-- Write Data
|
298 |
|
|
x"98" after 9800 ns,
|
299 |
|
|
-- Write Volatile Dummy Cycles (0)
|
300 |
|
|
"11111011" after 10800 ns,
|
301 |
|
|
-- Write Volatile SPI Mode (Quad)
|
302 |
|
|
"01111111" after 11800 ns,
|
303 |
|
|
|
304 |
|
|
-- SPI Quad Mode --
|
305 |
|
|
-- Read Volatile Dummy Cycles (0)
|
306 |
|
|
(others => '0') after 12800 ns,
|
307 |
|
|
-- Read Volatile SPI Mode (Quad)
|
308 |
|
|
(others => '0') after 13800 ns,
|
309 |
|
|
-- Write Data
|
310 |
|
|
x"CD" after 14800 ns,
|
311 |
|
|
|
312 |
|
|
-- Write Volatile Dummy Cycles (5)
|
313 |
|
|
"01011011" after 15800 ns,
|
314 |
|
|
|
315 |
|
|
-- Read Data
|
316 |
|
|
(others => '0') after 16800 ns;
|
317 |
|
|
|
318 |
|
|
-- SPI DQ[3:0]
|
319 |
|
|
dq <= (others => 'Z'),
|
320 |
|
|
-- SPI Single Mode --
|
321 |
|
|
-- Read Volatile Dummy Cycles
|
322 |
|
|
-- 1 Byte (0xFB)
|
323 |
|
|
"0010" after 405 ns,
|
324 |
|
|
"0010" after 425 ns,
|
325 |
|
|
"0010" after 445 ns,
|
326 |
|
|
"0010" after 465 ns,
|
327 |
|
|
"0010" after 485 ns,
|
328 |
|
|
"0000" after 505 ns,
|
329 |
|
|
"0010" after 525 ns,
|
330 |
|
|
"0010" after 545 ns,
|
331 |
|
|
(others => 'Z') after 565 ns,
|
332 |
|
|
|
333 |
|
|
-- Read Volatile SPI Mode
|
334 |
|
|
-- 1 Byte (0xFF)
|
335 |
|
|
"0010" after 2205 ns,
|
336 |
|
|
"0010" after 2225 ns,
|
337 |
|
|
"0010" after 2245 ns,
|
338 |
|
|
"0010" after 2265 ns,
|
339 |
|
|
"0010" after 2285 ns,
|
340 |
|
|
"0010" after 2305 ns,
|
341 |
|
|
"0010" after 2325 ns,
|
342 |
|
|
"0010" after 2345 ns,
|
343 |
|
|
-- Write Data, Write Volatile Dummy Cycles (2), Write Volatile SPI Mode (Dual)
|
344 |
|
|
(others => 'Z') after 2365 ns,
|
345 |
|
|
|
346 |
|
|
-- SPI Dual Mode --
|
347 |
|
|
-- Read Volatile Dummy Cycles (2)
|
348 |
|
|
-- 1 Byte (0x2B)
|
349 |
|
|
"0000" after 8125 ns,
|
350 |
|
|
"0010" after 8145 ns,
|
351 |
|
|
"0010" after 8165 ns,
|
352 |
|
|
"0011" after 8185 ns,
|
353 |
|
|
(others => 'Z') after 8205 ns,
|
354 |
|
|
|
355 |
|
|
-- Read Volatile SPI Mode (Dual)
|
356 |
|
|
-- 1 Byte (0xBF)
|
357 |
|
|
"0010" after 9125 ns,
|
358 |
|
|
"0011" after 9145 ns,
|
359 |
|
|
"0011" after 9165 ns,
|
360 |
|
|
"0011" after 9185 ns,
|
361 |
|
|
(others => 'Z') after 9205 ns,
|
362 |
|
|
|
363 |
|
|
-- Write Data, Write Volatile Dummy Cycles (0), Write Volatile SPI Mode (Quad)
|
364 |
|
|
(others => 'Z') after 9800 ns,
|
365 |
|
|
|
366 |
|
|
-- SPI Quad Mode --
|
367 |
|
|
-- Read Volatile Dummy Cycles (0)
|
368 |
|
|
-- 1 Byte (0xFB)
|
369 |
|
|
"1111" after 13085 ns,
|
370 |
|
|
"1011" after 13105 ns,
|
371 |
|
|
(others => 'Z') after 13125 ns,
|
372 |
|
|
-- Read Volatile SPI Mode (Quad)
|
373 |
|
|
-- 1 Byte (0x7F)
|
374 |
|
|
"0111" after 14085 ns,
|
375 |
|
|
"1111" after 14105 ns,
|
376 |
|
|
(others => 'Z') after 14125 ns,
|
377 |
|
|
|
378 |
|
|
-- Read Data
|
379 |
|
|
-- 1 Byte (0xC1)
|
380 |
|
|
"1100" after 17305 ns,
|
381 |
|
|
"0001" after 17325 ns,
|
382 |
|
|
(others => 'Z') after 17345 ns;
|
383 |
|
|
|
384 |
|
|
uut: PmodSF3Driver
|
385 |
|
|
GENERIC map(
|
386 |
|
|
sys_clock => 100_000_000,
|
387 |
|
|
max_data_byte => 1)
|
388 |
|
|
|
389 |
|
|
PORT map(
|
390 |
|
|
i_sys_clock => sys_clock,
|
391 |
|
|
i_reset => reset,
|
392 |
|
|
i_start => start,
|
393 |
|
|
i_rw => mode,
|
394 |
|
|
i_command => command,
|
395 |
|
|
i_addr_bytes => addr_bytes,
|
396 |
|
|
i_addr => addr,
|
397 |
|
|
i_data_bytes => data_bytes,
|
398 |
|
|
i_data => data_w,
|
399 |
|
|
o_data => data_r,
|
400 |
|
|
o_data_ready => data_ready,
|
401 |
|
|
o_ready => ready,
|
402 |
|
|
o_reset => reset_mem,
|
403 |
|
|
o_sclk => sclk,
|
404 |
|
|
io_dq => dq,
|
405 |
|
|
o_ss => ss,
|
406 |
|
|
o_spi_using_sys_freq => spi_using_sys_freq);
|
407 |
|
|
|
408 |
|
|
end Behavioral;
|