# 開源FPGA/Verilog 入門學習研討與工作坊 課程講義:https://drive.google.com/file/d/1G1jGkdioWYk1VALm7GKb-FsMcFeSeGeX/view?usp=sharing 課程檔案: 1. [ 9:00-10:00 開源 FPGA Toolchain 簡介 ] ### FPGA Toolchain - FPGA開源工具介紹 - Project IceStorm 介紹 - APIO 與 VSCode 開發環境 - Icestudio 圖像式開發環境 - F4PGA/SymbiFlow ### FPGA Dev Kits - Lattice iCE40 - iCE40HX1K:iCestick - iCE40UP5K :OK :iCE40pro - OK:iCE40pro 電路設計介紹 - PMOD 電路設計介紹 - VGA, NeoPix,RGB LED - HDMI, 7-Seg,.... - OpenSource IceStorm 工具鏈介紹 - 簡單易用的 APIO 與 VSCode Verilog 開發環境 - 適合教學的圖形開發環境 :IceStudio IDE 2. [ 10:00-11:00 三款開源 CPU 設計介紹 ] ### FPGA CPU Examples - 數位邏輯設計與Verilog基礎 - Minimal CPU & Verilog-in-30min - 三款 FPGA CPU/Verilog 範例 - 8bit - NES - 16bit - J1A Forth SOC - 32bit - RISC-V picorv32 + LCD - Lattice iCE40-UP5K 晶片的應用電路設計 - WiFiBoy FPGA 玩學機 OK:iCE40Pro 電路設計 4. [ 13:00-14:00 簡單易學 OK-8 CPU 設計 ] ### Minimal CPU Design - OK-8 CPU/Verilog 設計 - 極精簡CPU框架 - ISA指令集設計 - PSG 聲音產生器 - Programmable Sound Generator - OK-8 + PSG 範例 - OK-8 CPU 原始程式解析 - OK-8 如何做 Blink 範例 - OK-8 如何加入有趣的 Sound Generator 範例 5. [ 14:00-16:00 FPGA 工作坊 ] ### FPGA Workshop - APIO-VSCode 開發環境安裝 - Blink & OK-8 實作 - OK:iCE40Pro Bitstreams 範例 - J1A Forth 的實驗 - RSIC-V Picorv32 - Icestorm 圖像開發環境安裝 - PMOD 實驗 (NeoPix) ## 開源 FPGA Toolchain 簡介 ### Opensource FPGA Toolchain - FPGA 是什麼 - Logic Input -> Field Programmable Gate Array -> Logic Output - 有什麼好處 - Flexibility - Accessibility - Longevity - Community ### FPGA Tool/Flow 數位邏輯設計工具與流程 - Synthesis(合成:產出netlist) -> Placement & Routing(自動佈局與繞線:產出tileinfo) -> Bitstream Generation(位元流生成:產出bitstreams) APIO 安裝環境  ## 三款開源 CPU 設計介紹   ## 簡單易學 OK-8 CPU 設計 **CPU規格:** - 一個暫存器 ACC,一個 PC (Program Counter) - ROM、RAM 各有16個bytes - 只有4個指令:LOAD x, ADD x, STORE x, HALT - 8bits 指令格式為 "ooxxxxxx":oo=opcode, xxxxxx=operand 1. Verilog的電路,是由一塊塊module組合連接而成的: ```verilog module MinimalCPU (input clk, output led); // ... endmodule ``` 2. 數位邏輯電路設計,要先認識「reg暫存訊號線」。 ```verilog reg[7:0] PC = 8'b00000000; reg[7:0] ACC = 8'b00000000; reg[7:0] ROM[0:15]; reg[7:0] RAM[0:15]; ``` 3. 給ROM 輸入一段小程式。(指令格式 ooxxxxxx) ```verilog initital begin ROM[0] = 8'b00000001; ROM[1] = 8'b01000010; ROM[2] = 8'b10000011; ROM[3] = 8'b11000000; end ``` 4. 做一個「在clk正元觸發指令」的電路 clk 訊號是CPU的「心動時刻」 ```verilog always @(posedge clk) begin IR = ROM[PC]; opcode = IR[7:6]; operand = IR[5:0]; // ... PC = PC+1; end ``` 5. 剛才做的電路有三個沒有定義 ```verilog reg [7:0] IR; reg [1:0] opcode; reg [5:0] operand; ``` 7. 現在要開始解析、執行指令。 ```verilog always @(posedge clk) begin IR = ROM[PC]; opcode = IR[7:6]; operand = IR[5:0]; case(opcode) 2'b00: ACC = operand; // LOAD 2'b01: ACC = ACC + operand; // ADD 2'b10: RAM[operand] = ACC; // STORE 2'b11: led = 0; // HALT endcase PC = PC+1; end ``` 7. 有一個小漏洞,HALT時,PC不能再加一了。 ```verilog if(opcode != 2'b11) PC = PC+1; ``` 8. 最小CPU程式碼完成了 ```verilog module MinimalCPU(input clk, output led); reg[7:0] PC = 8'b0000000; reg[7:0] ACC =8'b0000000; reg[7:0] ROM[0:15]; reg[7:0] RAM[0:15]; initial begin ROM[0] = 8'b00000001; ROM[1] = 8'b01000010; ROM[2] = 8'b10000011; ROM[3] = 8'b11000000; end reg[7:0] IR; reg[1:0] opcode; reg[5:0] operand; always @(posedge clk) begin IR = ROM[PC]; opcode = IR[7:6]; operand = IR[5:0]; case(opcode) 2'b00 ACC = operand; 2'b01 PC = ACC + operand; 2'b10 RAM[operand] = ACC; 2'b11 led = 0; endcase if(opcode != 2'b11) PC = PC + 1; end endmodule ``` ## 開源 CPU & OK-8 實務操作 #### vscode  ```shell $pip install apio $apio install -a $apio drivers --ftdi-enable $iceprog "the path of game" ``` select Dual RS232-HS Driver FTDIBUS -> libusbK vscode install extension 1. IceStorm ctrl + shif + p -> create the fpga project 2. Verilog-HDL/SystemVerilog #### icestudio 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up