Understand ChengYeXing · Start from every drop
Electronic component suppliers of global famous brands

CPLD is read and written to VHDL program by STM32

CPLD is read and written to VHDL program by STM32

CPLD is read and written to VHDL program by STM32

one




two




3 -- This program is used to test the read and write operation of STM32 to CPLD




four




5 -- Test functions are as follows:




six




7 -- Write 0x01 to 0x05 address, the LED stops flashing, and other data will continue flashing




eight




9 -- 0x03,0x04 registers are fixed values, which can be read through STM32 and then output through serial port to see if they are consistent




ten




eleven




twelve




13 -- File name: AD.vhd




fourteen




15 library ieee;




sixteen




17 use ieee.std_ logic_ 1164.all;




eighteen




19 use ieee.std_ logic_ unsigned.all;




twenty




twenty-one




twenty-two




23 entity AD is




twenty-four




25 port(




twenty-six




27 -- System signal line




twenty-eight




29 CLK: in std_ logic;




thirty




31 LED: out std_ logic;




thirty-two




33 -- Signal line connected to ARM




thirty-four




35 Adr_ L: in std_ logic_ vector(7 downto 0); -- A7... A0, only the low-octet address line is used




thirty-six




37 D: inout std_ logic_ vector(7 downto 0); -- Only the low-octet data line is used




thirty-eight




39 FSMC_ NE4: in std_ logic;




forty




41 FSMC_ NOE: in std_ logic;




forty-two




43 FSMC_ NWE: in std_ logic




forty-four




45 );




forty-six




47 end AD;




forty-eight




forty-nine




fifty




51 architecture art of AD is




fifty-two




53 -- Set register for storing data




fifty-four




55 signal AD0_ H_ data,AD0_ L_ data,AD1_ H_ data,AD1_ L_ data,LED_ ctrl: std_ logic_ vector(7 downto 0);




fifty-six




57 -- data buffer register




fifty-eight




59 signal data_ buf: std_ logic_ vector(7 downto 0);




sixty




61 -- Data output control




sixty-two




63 signal data_ outctl: std_ logic;




sixty-four




65 signal datacnt:integer range 0 to 4000000;-- Frequency division count




sixty-six




67 -- LED flashing enable




sixty-eight




69 signal LED_ flag: std_ logic;




seventy




seventy-one




seventy-two




seventy-three




seventy-four




75 -- Unified address, address line data line is 8 bits, and each address data width is 8 bits




seventy-six




77 --"00000001" AD0_ H_ data0x01




seventy-eight




79 --"00000010" AD0_ L_ data0x02




eighty




81 --"00000011" AD1_ H_ data0x03




eighty-two




83 --"00000100" AD1_ L_ data0x04




eighty-four




85 --"00000101" LED_ ctrl0x05




eighty-six




eighty-seven




eighty-eight




89 begin




ninety




ninety-one




ninety-two




93 AD1_ H_ data <="10100001";




ninety-four




95 AD1_ L_ data <="00010001";




ninety-six







97 -- LED flashing, used as CPLD operation indicator




ninety-eight




ninety-nine




one hundred




101 process(LED_ctrl) is




one hundred and two




103 begin




one hundred and four




105 if(LED_ctrl="00000001") then




one hundred and six




107 LED_ flag <= '0';




one hundred and eight




109 else




one hundred and ten




111 LED_ flag <= '1';




one hundred and twelve




113 end if;




one hundred and fourteen




115 end process;




one hundred and sixteen




one hundred and seventeen




one hundred and eighteen




119 process(CLK)is




one hundred and twenty




121 begin




one hundred and twenty-two




one hundred and twenty-three




one hundred and twenty-four




one hundred and twenty-five




one hundred and twenty-six




127 if(CLK'event and CLK='1') then




one hundred and twenty-eight




129 if(LED_flag='1') then




one hundred and thirty




131 datacnt<=datacnt+1;




one hundred and thirty-two




133 if (datacnt>2000000) then




one hundred and thirty-four




135 LED <= '1';




one hundred and thirty-six




137 end if;




one hundred and thirty-eight




139 if (datacnt>=4000000) then




one hundred and forty




141 LED <='0';




one hundred and forty-two




143 datacnt <=0;




one hundred and forty-four




145 end if;




one hundred and forty-six




147 end if;




one hundred and forty-eight




149 end if;




one hundred and fifty




151 end process;




one hundred and fifty-two




one hundred and fifty-three




one hundred and fifty-four




155 -- Used to determine when to output data to the bus when reading CPLD data




one hundred and fifty-six




157 data_ outctl <= (not FSMC_NE4) and (not FSMC_NOE) and (FSMC_NWE);




one hundred and fifty-eight




159 D <= data_ buf when (data_outctl='1') else "ZZZZZZZZ";-- Output data to the data line, otherwise it will remain in the high resistance state




one hundred and sixty




one hundred and sixty-one




one hundred and sixty-two




163 -- Write operation, mode 1, sequence diagram in data manual P331




one hundred and sixty-four




165 process(FSMC_NE4,FSMC_NWE,Adr_L,FSMC_NOE) is --,FSMC_ NBL,D,RESET




one hundred and sixty-six




167 begin




one hundred and sixty-eight




169 if(FSMC_NWE'event and FSMC_NWE='1') then




one hundred and seventy




171 if((FSMC_NOE and (not FSMC_NE4))='1') then




one hundred and seventy-two




173 case (Adr_L) is




one hundred and seventy-four




175 when "00000001" =>




one hundred and seventy-six




177 AD0_ H_ data<= D; -- 0x01




one hundred and seventy-eight




179 when "00000010" =>




one hundred and eighty




181 AD0_ L_ data<= D; -- 0x02




one hundred and eighty-two




183 when "00000101" =>




one hundred and eighty-four




185 LED_ ctrl<= D;-- 0x05




one hundred and eighty-six




187 when others =>




one hundred and eighty-eight




189 AD0_ H_ data<= AD0_ H_ data;




one hundred and ninety




191 AD0_ L_ data<= AD0_ L_ data;




one hundred and ninety-two




193 end case;




one hundred and ninety-four




195 end if;




one hundred and ninety-six




197 end if;




one hundred and ninety-eight




199 end process;




two hundred




two hundred and one




two hundred and two




203 -- Read operation, mode 1, P331




two hundred and four




205 process(FSMC_NE4,FSMC_NWE,Adr_L,FSMC_NOE) is




two hundred and six




207 begin




two hundred and eight




209 if (FSMC_NOE='0 'and FSMC_NOE'event) then -- update data directly at the falling edge of NOE




two hundred and ten




211 case (Adr_L) is




two hundred and twelve




213 when "00000001" =>




two hundred and fourteen




215 data_ buf <= AD0_ H_ data; -- 0x01




two hundred and sixteen




217 when "00000010" =>




two hundred and eighteen




219 data_ buf <= AD0_ L_ data; -- 0x02




two hundred and twenty




221 when "00000011" =>




two hundred and twenty-two




223 data_ buf <= AD1_ H_ data; -- 0x03




two hundred and twenty-four




225 when "00000100" =>




two hundred and twenty-six




227 data_ buf <= AD1_ L_ data; -- 0x04




two hundred and twenty-eight




229 when others => data_ buf <= "ZZZZZZZZ";




two hundred and thirty




231 end case;




two hundred and thirty-two




233 end if;




two hundred and thirty-four




235 end process;




two hundred and thirty-six




237 end;




two hundred and thirty-eight




two hundred and thirty-nine




two hundred and forty




two hundred and forty-one




two hundred and forty-two




two hundred and forty-three

粤ICP备2022135715号