1 |
2 |
ldalmasso |
------------------------------------------------------------------------
|
2 |
|
|
-- Engineer: Dalmasso Loic
|
3 |
|
|
-- Create Date: 19/02/2025
|
4 |
|
|
-- Module Name: PmodSF3SPIController
|
5 |
|
|
-- Description:
|
6 |
|
|
-- Pmod SF3 SPI Controller for the 32 MB NOR Flash Memory MT25QL256ABA.
|
7 |
|
|
-- Supports Single, Dual and Quad SPI Modes:
|
8 |
|
|
-- | i_spi_dual_enable | i_spi_single_enable | SPI Mode
|
9 |
|
|
-- | 0 | 1 | Single
|
10 |
|
|
-- | 1 | 1 | Single
|
11 |
|
|
-- | 1 | 0 | Dual
|
12 |
|
|
-- | 0 | 1 | Quad
|
13 |
|
|
--
|
14 |
|
|
-- The 'o_ready' signal indicates this module is ready to start new SPI transmission.
|
15 |
|
|
-- The 'i_start' signal starts the SPI communication, according to the mode (Read or Write memory), command/address/data bytes.
|
16 |
|
|
-- In Write operation, when the 'o_next_data_w' is set to '1', the MSB of the 'i_data_w' is loaded.
|
17 |
|
|
-- In Read operation, when the 'o_data_ready', data from memory is available in 'o_data_r' signal.
|
18 |
|
|
--
|
19 |
|
|
-- Ports
|
20 |
|
|
-- Input - i_sys_clock: System Input Clock
|
21 |
|
|
-- Input - i_sys_clock_en: System Input Clock Enable
|
22 |
|
|
-- Input - i_reset: System Input Reset ('0': No Reset, '1': Reset)
|
23 |
|
|
-- Input - i_start: Start SPI Transmission ('0': No Start, '1': Start)
|
24 |
|
|
-- Input - i_spi_single_enable: Enable SPI Single Mode ('0': Disable, '1': Enable)
|
25 |
|
|
-- Input - i_spi_dual_enable: Enable SPI Dual Mode ('0': Disable, '1': Enable)
|
26 |
|
|
-- Input - i_mode: Set Memory Operation Mode ('0': Write, '1': Mode)
|
27 |
|
|
-- Input - i_command: Command Byte
|
28 |
|
|
-- Input - i_addr_bytes: Number of Address Bytes to use (0 to 3 bytes)
|
29 |
|
|
-- Input - i_addr: Address Bytes
|
30 |
|
|
-- Input - i_dummy_cycles: Number of Dummy Cycles (0 to 14 cycles)
|
31 |
|
|
-- Input - i_data_bytes: Number of Data Bytes to write
|
32 |
|
|
-- Input - i_data_w: Data Bytes to write
|
33 |
|
|
-- Output - o_next_data_w: Next bit of Data Bytes trigger ('0': Disable, '1': Enable)
|
34 |
|
|
-- Output - o_data_r: Data Bytes read from Memory
|
35 |
|
|
-- Output - o_data_ready: Data Bytes read from Memory Ready ('0': NOT Ready, '1': Ready)
|
36 |
|
|
-- Output - o_ready: System Ready for transmission
|
37 |
|
|
-- Output - o_reset: Memory Reset ('0': Reset, '1': No Reset)
|
38 |
|
|
-- Output - o_sclk: SPI Serial Clock
|
39 |
|
|
-- In/Out - io_dq: SPI Serial Data
|
40 |
|
|
-- Output - o_ss: SPI Slave Select Line ('0': Enable, '1': Disable)
|
41 |
|
|
------------------------------------------------------------------------
|
42 |
|
|
|
43 |
|
|
LIBRARY IEEE;
|
44 |
|
|
USE IEEE.STD_LOGIC_1164.ALL;
|
45 |
|
|
USE IEEE.NUMERIC_STD.ALL;
|
46 |
|
|
|
47 |
|
|
ENTITY Testbench_PmodSF3SPIController is
|
48 |
|
|
END Testbench_PmodSF3SPIController;
|
49 |
|
|
|
50 |
|
|
ARCHITECTURE Behavioral of Testbench_PmodSF3SPIController is
|
51 |
|
|
|
52 |
|
|
COMPONENT PmodSF3SPIController is
|
53 |
|
|
|
54 |
|
|
PORT(
|
55 |
|
|
-- Module Control
|
56 |
|
|
i_sys_clock: IN STD_LOGIC;
|
57 |
|
|
i_sys_clock_en: IN STD_LOGIC;
|
58 |
|
|
i_reset: IN STD_LOGIC;
|
59 |
|
|
i_start: IN STD_LOGIC;
|
60 |
|
|
-- SPI Mode Config (Single, Dual or Quad)
|
61 |
|
|
i_spi_single_enable: IN STD_LOGIC;
|
62 |
|
|
i_spi_dual_enable: IN STD_LOGIC;
|
63 |
|
|
-- Memory Command/Addr/Data
|
64 |
|
|
i_mode: IN STD_LOGIC;
|
65 |
|
|
i_command: IN UNSIGNED(7 downto 0);
|
66 |
|
|
i_addr_bytes: IN INTEGER range 0 to 3;
|
67 |
|
|
i_addr: IN UNSIGNED(23 downto 0);
|
68 |
|
|
i_dummy_cycles: IN INTEGER range 0 to 14;
|
69 |
|
|
i_data_bytes: IN INTEGER;
|
70 |
|
|
i_data_w: IN UNSIGNED(7 downto 0);
|
71 |
|
|
o_next_data_w: OUT STD_LOGIC;
|
72 |
|
|
o_data_r: OUT UNSIGNED(7 downto 0);
|
73 |
|
|
o_data_ready: OUT STD_LOGIC;
|
74 |
|
|
-- Module Outputs
|
75 |
|
|
o_ready: OUT STD_LOGIC;
|
76 |
|
|
o_reset: OUT STD_LOGIC;
|
77 |
|
|
o_sclk: OUT STD_LOGIC;
|
78 |
|
|
io_dq: INOUT STD_LOGIC_VECTOR(3 downto 0);
|
79 |
|
|
o_ss: OUT STD_LOGIC
|
80 |
|
|
);
|
81 |
|
|
|
82 |
|
|
END COMPONENT;
|
83 |
|
|
|
84 |
|
|
signal sys_clock: STD_LOGIC := '0';
|
85 |
|
|
signal sys_clock_en: STD_LOGIC := '0';
|
86 |
|
|
signal reset: STD_LOGIC := '0';
|
87 |
|
|
signal start: STD_LOGIC := '0';
|
88 |
|
|
|
89 |
|
|
signal spi_single_enable: STD_LOGIC := '0';
|
90 |
|
|
signal spi_dual_enable: STD_LOGIC := '0';
|
91 |
|
|
|
92 |
|
|
signal mode: STD_LOGIC := '0';
|
93 |
|
|
signal command: UNSIGNED(7 downto 0) := (others => '0');
|
94 |
|
|
signal addr_bytes: INTEGER range 0 to 3 := 0;
|
95 |
|
|
signal addr: UNSIGNED(23 downto 0):= (others => '0');
|
96 |
|
|
signal dummy_cycles: INTEGER range 0 to 14 := 0;
|
97 |
|
|
signal data_bytes: INTEGER := 0;
|
98 |
|
|
signal data_w: UNSIGNED(7 downto 0):= (others => '0');
|
99 |
|
|
signal next_data_w: STD_LOGIC := '0';
|
100 |
|
|
signal data_r: UNSIGNED(7 downto 0):= (others => '0');
|
101 |
|
|
signal data_ready: STD_LOGIC := '0';
|
102 |
|
|
|
103 |
|
|
signal ready: STD_LOGIC := '0';
|
104 |
|
|
signal reset_mem: STD_LOGIC := '0';
|
105 |
|
|
signal sclk: STD_LOGIC := '0';
|
106 |
|
|
signal dq: STD_LOGIC_VECTOR(3 downto 0) := (others => '0');
|
107 |
|
|
signal ss: STD_LOGIC := '1';
|
108 |
|
|
|
109 |
|
|
begin
|
110 |
|
|
|
111 |
|
|
-- Clock 100 MHz
|
112 |
|
|
sys_clock <= not(sys_clock) after 5 ns;
|
113 |
|
|
|
114 |
|
|
-- Clock Enable
|
115 |
|
|
sys_clock_en <= not(sys_clock) after 5 ns;
|
116 |
|
|
|
117 |
|
|
-- Reset
|
118 |
|
|
reset <= '1', '0' after 145 ns;
|
119 |
|
|
|
120 |
|
|
-- Start
|
121 |
|
|
start <= '0',
|
122 |
|
|
-- Read then Write Cycles (SPI Single Mode)
|
123 |
|
|
'1' after 200 ns, '0' after 326 ns,
|
124 |
|
|
'1' after 2505 ns, '0' after 2631 ns,
|
125 |
|
|
-- Read then Write Cycles (SPI Dual Mode)
|
126 |
|
|
'1' after 5000 ns, '0' after 5150 ns,
|
127 |
|
|
'1' after 6000 ns, '0' after 6150 ns,
|
128 |
|
|
-- Read then Write Cycles (SPI Dual Mode)
|
129 |
|
|
'1' after 8000 ns, '0' after 8150 ns,
|
130 |
|
|
'1' after 9000 ns, '0' after 9150 ns;
|
131 |
|
|
|
132 |
|
|
-- SPI Modes (Single, then Dual, then Quad)
|
133 |
|
|
spi_single_enable <= '1', '0' after 4950 ns, '0' after 7950 ns;
|
134 |
|
|
spi_dual_enable <= '0', '1' after 4950 ns, '0' after 7950 ns;
|
135 |
|
|
|
136 |
|
|
-- Memory Operation Mode (Read then Write)
|
137 |
|
|
mode <= -- SPI Single Mode
|
138 |
|
|
'1', '0' after 500 ns,
|
139 |
|
|
-- SPI Dual Mode
|
140 |
|
|
'1' after 4950 ns, '0' after 5150 ns,
|
141 |
|
|
-- SPI Quad Mode
|
142 |
|
|
'1' after 7950 ns, '0' after 8150 ns;
|
143 |
|
|
|
144 |
|
|
-- Command
|
145 |
|
|
command <= x"A2";
|
146 |
|
|
|
147 |
|
|
-- Address Bytes
|
148 |
|
|
addr_bytes <= 3;
|
149 |
|
|
|
150 |
|
|
-- Address
|
151 |
|
|
addr <= x"123456";
|
152 |
|
|
|
153 |
|
|
-- Dummy Cycles
|
154 |
|
|
dummy_cycles <= 0, 3 after 5000 ns;
|
155 |
|
|
|
156 |
|
|
-- Data Bytes
|
157 |
|
|
data_bytes <= 2;
|
158 |
|
|
|
159 |
|
|
-- Data to Write
|
160 |
|
|
data_w <= x"8B", x"EF" after 5000 ns, x"B0" after 8000 ns;
|
161 |
|
|
|
162 |
|
|
-- SPI DQ[3:0]
|
163 |
|
|
dq <= (others => 'Z'),
|
164 |
|
|
-- Read then Write (SPI Single Mode)
|
165 |
|
|
-- Byte 1 (0xAD)
|
166 |
|
|
"0010" after 855 ns,
|
167 |
|
|
"0000" after 875 ns,
|
168 |
|
|
"0010" after 895 ns,
|
169 |
|
|
"0000" after 915 ns,
|
170 |
|
|
"0010" after 935 ns,
|
171 |
|
|
"0010" after 955 ns,
|
172 |
|
|
"0000" after 975 ns,
|
173 |
|
|
"0010" after 995 ns,
|
174 |
|
|
-- Byte 2 (0xF1)
|
175 |
|
|
"0010" after 1015 ns,
|
176 |
|
|
"0010" after 1035 ns,
|
177 |
|
|
"0010" after 1055 ns,
|
178 |
|
|
"0010" after 1075 ns,
|
179 |
|
|
"0000" after 1095 ns,
|
180 |
|
|
"0000" after 1115 ns,
|
181 |
|
|
"0000" after 1135 ns,
|
182 |
|
|
"0010" after 1155 ns,
|
183 |
|
|
(others => 'Z') after 1175 ns,
|
184 |
|
|
|
185 |
|
|
-- Read then Write (SPI Dual Mode)
|
186 |
|
|
-- Byte 1 (0x9C)
|
187 |
|
|
"0010" after 5395 ns,
|
188 |
|
|
"0001" after 5415 ns,
|
189 |
|
|
"0011" after 5435 ns,
|
190 |
|
|
"0000" after 5455 ns,
|
191 |
|
|
-- Byte 2 (0x9C)
|
192 |
|
|
"0010" after 5475 ns,
|
193 |
|
|
"0001" after 5495 ns,
|
194 |
|
|
"0011" after 5515 ns,
|
195 |
|
|
"0000" after 5535 ns,
|
196 |
|
|
(others => 'Z') after 5555 ns,
|
197 |
|
|
|
198 |
|
|
-- Read then Write (SPI Quad Mode)
|
199 |
|
|
-- Byte 1 (0xD5)
|
200 |
|
|
"1101" after 8235 ns,
|
201 |
|
|
"0101" after 8255 ns,
|
202 |
|
|
-- Byte 2 (0xD9)
|
203 |
|
|
"1101" after 8275 ns,
|
204 |
|
|
"1001" after 8295 ns,
|
205 |
|
|
(others => 'Z') after 8315 ns;
|
206 |
|
|
|
207 |
|
|
uut: PmodSF3SPIController
|
208 |
|
|
PORT map(
|
209 |
|
|
i_sys_clock => sys_clock,
|
210 |
|
|
i_sys_clock_en => sys_clock_en,
|
211 |
|
|
i_reset => reset,
|
212 |
|
|
i_start => start,
|
213 |
|
|
i_spi_single_enable => spi_single_enable,
|
214 |
|
|
i_spi_dual_enable => spi_dual_enable,
|
215 |
|
|
i_mode => mode,
|
216 |
|
|
i_command => command,
|
217 |
|
|
i_addr_bytes => addr_bytes,
|
218 |
|
|
i_addr => addr,
|
219 |
|
|
i_dummy_cycles => dummy_cycles,
|
220 |
|
|
i_data_bytes => data_bytes,
|
221 |
|
|
i_data_w => data_w,
|
222 |
|
|
o_next_data_w => next_data_w,
|
223 |
|
|
o_data_r => data_r,
|
224 |
|
|
o_data_ready => data_ready,
|
225 |
|
|
o_ready => ready,
|
226 |
|
|
o_reset => reset_mem,
|
227 |
|
|
o_sclk => sclk,
|
228 |
|
|
io_dq => dq,
|
229 |
|
|
o_ss => ss);
|
230 |
|
|
|
231 |
|
|
end Behavioral;
|