07b sopc nios hw tutorial - unipi.it · – build a (nios ii) computer tailored to application...
TRANSCRIPT
![Page 1: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/1.jpg)
SISTEMIEMBEDDED
BuildingaNios IIComputerfromscratch
FedericoBaronti Lastversion:201603211
![Page 2: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/2.jpg)
Introduction• Problem:– Builda(NIOSII)Computertailoredtoapplicationneeds
• Solutions:– UselibrarycoresandcustomHDLcode– Usespecificdesigntools(Qsys)tohelpassemblethesystem• Components(CPUs,memory(controllers),peripherals,…)selectedfromAltera,othervendorsorcustomlibraries
• Connections(AvalonSystemInterconnectFabric) aregeneratedautomaticallybythetool– Needforstandardinterfaces
• DE2_basic_andDE2_media_computersarepre-builtNios IIsystemswithdifferentchoicesfortheproc.(economyandfast)andtheperipheralsavailableintheUniversityProgrampackage 2
![Page 3: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/3.jpg)
Avalon SystemFabric
• OverviewofAvalonstandardinterfaces:– Clock– Reset– Interrupt– Memory-Mapped(masterandslave)– Streaming(sourceandsink)– Conduit
3
![Page 4: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/4.jpg)
Example:FirstNiosSystem• Handles slider switches andLEDs throughPIOperipherals
AvalonSystemFabric
NiosIICore/e
JTAGDebugModule
KEY0
JTAGController
CycloneII:EP2C35F672C6
On-chipmem
PIO(8-bitinput)
SW7...SW0
PIO(8-bitoutput)
LEDG7...LEDG0
JTAGHUB
USB-BlasterHOST-PC
SystemID
CLOCK_50
Clocksource
reset_n clk
4
![Page 5: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/5.jpg)
FirstNios Computercomponents
• CPU(simplest,i.e.,economy version)withJTAGDebugModule
• On-chipmemory forprogram anddata(8KB)• 2PIOs– Inputforreading slider switches (8bit)– Outputfordriving greenLEDs (8bit)
• SystemIDPeripheralforcomputeridentification
5
![Page 6: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/6.jpg)
Nios IIHardwareFlow
<proc_design_unit>.v<proc_design_unit>.v
Qsys<nios_system>.qsys
Quartus II
<nios_system>.sopcinfo
Nios IISBTEclipse<nios_system>.v
<top_level_name>.v
<project_name>.sof
<proc_design_unit>.v
<custom_design_unit>.v<custom_design_unit>.v<custom_design_unit>.v
<project_name>.qpf
<top_level_name >.sdc
<onchip_mem>.hex
6
![Page 7: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/7.jpg)
Qsys Flow
<proc_design_unit>.v<proc_design_unit>.v
Create/OpenNios IIsystem
<nios_system>.qsys
<nios_system>.v <proc_design_unit>.v
Insertcomponentfromlibrary
ConfigurecomponentHWparameters
ConfigureBaseaddressesandIRQ
End?
GenerateNios system
<nios_system>.qsys
Library
<nios_system>.sopcinfo
NoYes
ConfigureConnections
7
![Page 8: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/8.jpg)
Guidedexample(1)• CreateanewprojectinQuartus II
– SelectFPGA:CycloneIIEP2C35F672C6N• LaunchQsys tool• DefinetheNios_system components
– Clocksource:clk (itisaddedautomatically)– Nios IIProc.:nios2_proc
• ChoosetheeconomyversionoftheNiosII proc.(NiosII/e)andtheLevel1fortheJTAGDebugModule
– On-chipMemory:onchip_memory– PIO:green_leds
• OutputfordrivingLEDS– PIO:sliders
• Inputforreadingsliderswitchesstatus– SystemIDPeripheral:sysid (ID=1!)
8
![Page 9: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/9.jpg)
Qsys main window
Configureinternalco
nnectio
ns
Decide
sign
alstobe
broug
ht
(exported)to
the
Qsyssystembou
ndary
Componentinstancename Baseaddress
9
![Page 10: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/10.jpg)
CPUchoice
• Choosethemostsuitedprocessorcore
• 3variants:– Economy– Standard– Fast
• Differentfeatures– Trade-offperformance-cost
AtleastonememorymustbepresentintheQsys systeminordertoconfiguretheReset andException addresses
10
![Page 11: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/11.jpg)
Additional peripherals
11
![Page 12: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/12.jpg)
On-chip memory
• Define theorganizationof theonchip-memory– Type (ROM,RAM)– Size– Wordlength
• Initialization file:onchip_mem.hex
12
![Page 13: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/13.jpg)
Guidedexample(2)• Configureinternalconnections– Route clk fromClockSourcecomponenttotheothercomponents
– Createreset network• “Route”resetsignals fromClockSourceandJTAGDebug Module (withintheNios IIproc.)components totheother components
• Canbedone automatically using CreateGlobalResetNetworkcommand(Systemmenu)
– LinktheAvalonMemory-Mapped Interfaces:• data_master (Nios IIproc.),jtag_debug_module (Nios IIproc.),s1(onchip_memory), s1 (PIO:sliders,green_leds),control_slave (sysid)
• instruction_master (Nios IIproc.),jtag_debug_module (Nios IIproc.),s1(onchip_memory)
13
![Page 14: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/14.jpg)
Guidedexample(3)• Exportexternalconnections– Sliders andgreen_leds PIOs have conduit interfaces,therelated signals (external_connection)mustberouted totheQsys system boundary
• Assignbaseaddresses– ManuallytoeachcomponentwithslaveMemory-MappedInterfaces(payattentiontoavoidoverlaps!)
– Assign BaseAddresses (fromtheSystemmenu)
14
![Page 15: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/15.jpg)
Guidedexample(4)WearenowreadytogeneratetheQsys system
andgobacktoQuartus II
15
![Page 16: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/16.jpg)
Guidedexample(6)
• BacktoQuartus II– ImportQsys systemintoQuartus project.Doone ofthefollowings:• MethodI:Addthe.qip filestoredinnios_system>/synthesistotheproject
• MethodII:Addthe.qsys filetotheproject
– Createtherootmoduleoftheproject– IncludetheNios_systemmoduleashierarchicalblock(Verilog)
– Importpinassignmentfromde2.qsf– Compiletheprojecttomakethehardwareready
16
![Page 17: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/17.jpg)
Guidedexample(7)
• IntegratingQsys systemintoQuartus IIproject– MethodI:Addthe(Quartus IIfile).qip filestoredin<nios_system>/synthesistotheproject• .qip fileiscreatedwhengeneratingtheQsys systemtogetherwiththe.sopcinfo andtheHDLfiles• ItlistsallthefilesnecessaryforcompilationinQuartusII,includingthereferencestotheHDLfilesgeneratedbyQsys
17
![Page 18: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/18.jpg)
Guidedexample(8)
• IntegratingQsys systemintoQuartus IIproject– MethodII:Addthe.qsys filetoproject• TheQsys systemisnow (re)generatedbyQuartus IIateachcompilation
• ThegeneratedHDLfilesarestoredatadifferentpaththanthosegenerateddirectlybyQsys– db/ip/<nios_system>
• Notethatthesysid timestampchangesateachcompilationinQuartus II
• TheBSPmustberegeneratedusingthenewsopcinfo fileaftereachcompilation,evenifwehavenotmadeanychangetotheQsys system!
18
![Page 19: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/19.jpg)
Guidedexample(7)• Projectrootmodule
//my_DE2_first_computer.v
module my_DE2_first_computer(//inputCLOCK_50,KEY,SW,//outputLEDG
);input CLOCK_50;input [0:0]KEY;input [7:0]SW;
output [7:0]LEDG;
//Addthenios_systeminstance//Theinstancetemplatecanbecopied fromQsysHDLexampletab
endmodule 19
![Page 20: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/20.jpg)
TestingFirstNios System(1)• WriteaprogramthatmakestheGREENLEDStobe
controlledbytheSLIDERSSWITCHES• If successful,generatethehex filetoinitialize theon-chip
memory.Recompile theQuartus project andreprogramtheFPGA.Yourprogram should run automatically!
• Togeneratethehex filefromelf.OpentheNios 2Command ShellandnavigatetotheEclipse project folder.Customize thefollowing command:
elf2hex--record=4--width=32--base=<onchip_memory base address>--end=<onchip_memory end address> --input=<eclipse_project_name.elf>--output=../../Hardware/onchip_mem.hex
20
![Page 21: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/21.jpg)
Testing FirstNios System(1a)• EnrichtheFirstNios Systemw/2additionalPIOsproperlyconfiguredtocontrolthepushbuttons(w/edgecapturecapability)andtheHEX3-HEX07-segdisplays availableontheDE2board.– MaketheIDofthisnewcomputerequalto2– Testthecomputerrunning theLEDrotation,theFastClickandtheWeekday programs
– Recallthatthepushbuttonsignalislowwhentheswitchispressedandthataledofthe7-segdisplayisONwhendrivenlow• Trytoguesswhat’sinsidetheparallelportperipheralconnectedtotheHEX7-segdisplaysusedintheDE2BasicComputer
21
![Page 22: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/22.jpg)
TestingFirstNios System(2)
• GobacktoQsys,addtheJTAG-UARTperipheral (Library/InterfaceProtocols/Serial),regeneratetheNiossystemandcompilethedesignagain(toplevelentrydoesnotneedtobechanged)
• WriteaprogramthatsayHellotothehosttogether w/thesystem IDandtimestamp
22
![Page 23: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/23.jpg)
TestingFirstNios System(3)
• Allocatedonchipmemoryisnotenough!– JTAG-UARTdevicedriverrequiresmorememorythantheoneavailable
– Inafuturelesson,wewilllearnsometechniquestoreducethememoryfootprintofoursoftware
– Now,wecan:• trytoenlargetheon-chipmemory.Notethat EP2C35FPGAhas105xM4Kb=52.5KB;someM4Kblocksareusedtoimplementtheproc.andtheJTAGDebugModule
• addtheSDRAMControllertoourQsys systemtousethe8MBSDRAMmemory(Zentel A3V64S40ETP-G6)presentontheDE2board
23
![Page 24: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/24.jpg)
SDRAMmemory(1)A3V64S40FTP
64M Single Data Rate Synchronous DRAM
Revision 1.0 Aug., 2011 Page 3 / 40
Type Designation Code A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6: 166MHz@CL=3 G: Green Package Type TP:TSOP (II) Process Generation Function Reserved for Future Use Organization 2n 4:x16 SDR Synchronous DRAM Density 64:64M bits Interface V:LVTTL Memory Style (DRAM) Zentel DRAM
A0-11
4096 x 256 x 16 4096 x 256 x 16 4096 x 256 x 16 4096 x 256 x 16
DQMU,L
DQ0-15 I/O
Input:CommandBankaddress I/OMask 24
![Page 25: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/25.jpg)
SDRAMmemory(2)
A3V64S40FTP
64M Single Data Rate Synchronous DRAM
Revision 1.0 Aug., 2011 Page 16 / 40
Operation of the SDRAM Read/Write Operations Bank active Before executing a read or write operation, the corresponding bank and the row address must be activated by the bank active (ACT) command. An interval of tRCD is required between the bank active command input and the following read/write command input. Read operation A read operation starts when a read command is input. Output buffer becomes Low-Z in the (/CAS Latency - 1) cycle after read command set. The SDRAM can perform a burst read operation. The burst length can be set to 1, 2, 4 and 8. The start address for a burst read is specified by the column address and the bank select address at the read command set cycle. In a read operation, data output starts after the number of clocks specified by the /CAS Latency. The /CAS Latency can be set to 2 or 3. When the burst length is 1, 2, 4 and 8 the DOUT buffer automatically becomes High-Z at the next clock after the successive burst-length data has been output. The /CAS latency and burst length must be specified at the mode register.
A3V64S40FTP
64M Single Data Rate Synchronous DRAM
Revision 1.0 Aug., 2011 Page 17 / 40
Write operation Burst write or single write mode is selected 1. Burst write: A burst write operation is enabled by setting OPCODE A9 to 0. A burst write starts in the same clock as a write
command set. (The latency of data input is 0 clock.) The burst length can be set to 1, 2, 4 and 8, like burst read operations. The write start address is specified by the column address and the bank select address at the write command set cycle.
.
2. Single write: A single write operation is enabled by setting OPCODE A9 to 1. In a single write operation, data is only
written to the column address and the bank select address specified by the write command set cycle without regard to the burst length setting. (The latency of data input is 0 clock).
Read
Write
25
![Page 26: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/26.jpg)
SDRAMmemory(2)
A3V64S40FTP
64M Single Data Rate Synchronous DRAM
Revision 1.0 Aug., 2011 Page 8 / 40
OPERATING AC PARAMETER (AC operating conditions unless otherwise noted)
Parameter Symbol Version
Unit Note -6 -7
Row active to row active delay tRRD(min) 12 14 ns 1
RAS to CAS delay tRCD(min) 18 21 ns 1
Row precharge time tRP(min) 18 21 ns 1
Row active time tRAS(min) 40 42 ns 1
tRAS(max) 100 100 us
Row cycle time tRC(min) 58 63 ns 1
Last data in to row precharge tRDL(min) 2 2 CLK 2
Col. address to col. address delay tCCD(min) 1 1 CLK-
Last data in to new col. address delay tCDL(min) 1 1 CLK 2
Last data in to burst stop tBDL(min) 1 1 CLK 2
Mode register set cycle time tMRD(min) 2 2 CLK
Refresh interval time tREF(max) 64 64 ms
Auto refresh cycle time tARFC(min) 60 70 ns
NOTES: 1. The minimum number of clock cycles is determined by dividing the minimum time required with clock cycle time and then rounding off to the next higher integer. 2. Minimum delay is required to complete write.
26
![Page 27: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/27.jpg)
SDRAMmemory(3)A3V64S40FTP
64M Single Data Rate Synchronous DRAM
Revision 1.0 Aug., 2011 Page 9 / 40
AC CHARACTERISTICS (AC operating conditions unless otherwise noted)
Parameter Symbol -6 -7 Unit Note
Min Max Min Max
CLK cycle time CAS latency=3 tCC (3) 6
1000
7
1000 ns 1 CAS latency=2 tCC (2) 10 10
CLK to valid output delay CAS latency=3 tSAC (3) 5.5 6
ns 1,2 CAS latency=2 tSAC (2) 6 6
Output data hold time CAS latency=3 tOH (3) 2.5 2.5
ns 2 CAS latency=2 tOH (2) 2.5 2.5
CLK high pulse width tCH 2.5 2.5 ns 3
CLK low pulse width tCL 2.5 2.5 ns 3
Input setup time tSI 1.5 1.5 ns 3
Input hold time tHI 1 1 ns 3
Transition time of CLK tSLZ 0 0 ns 2
CLK to output in Hi-Z CAS latency=3
tSHZ 5.5 6
ns CAS latency=2 6 6
NOTES : 1. Parameters depend on programmed CAS latency. 2. If clock rising time is longer than 1ns, (tr/2-0.5)ns should be added to the parameter. 3. Assumed input rise and fall time (tr & tf) = 1ns.
If tr & tf is longer than 1ns, transient time compensation should be considered, i.e., [(tr + tf)/2-1]ns should be added to the parameter.
27
![Page 28: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/28.jpg)
SDRAMmemory(4)
A3V64S40FTP
64M Single Data Rate Synchronous DRAM
Revision 1.0 Aug., 2011 Page 15 / 40
Power-up sequence Power-up sequence 1. Apply VDD and VDDQ at the same time. Keep CKE low during power up. 2. Wait for stable power. 3. Start clock and drive CKE high. Note : Voltage on any input pin must not exceed VDD+0.3V during power up. Initialization sequence 4. After stable power and stable clock, wait 200us. 5. Issue precharge all command (PALL). 6. After tRP delay, set 2 or more auto refresh commands (REF). 7. Set the mode register set command (MRS) to initialize the mode register. Note : We recommend that you keep DQM and CKE high during initialization sequence to prevent data contention on the DQ bus.
Power stable Clock stable
CKE
Command CKE
PALL REF REF MRS CMD
tRP tARFC tARFC tMRD
28
![Page 29: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/29.jpg)
SDRAMcontroller(1)APLLcanbeused tocompensatefortheclockskewDE2boardSDRAMClockmustleadtheControllerClockby3ns(Phaseshift)
29
![Page 30: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/30.jpg)
SDRAMcontroller(2)• Library/MemoryandMemoryControllers/SDRAMInterfaces
30
![Page 31: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/31.jpg)
SDRAMcontroller(3)• Library/MemoryandMemoryControllers/SDRAMInterfaces
=64ms/4096
31
![Page 32: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/32.jpg)
SDRAMcontroller(4)• InstantiateandconfigurethecomponentforSDRAMmemory
• SetQsys internalconnection:clock,resetandAvalonMMslave
• Exportsignalstowardsthememorychip(Conduitinterface)
• AssignBaseAddress
• MoveResetandExceptionaddressestofreshlycreatedSDRAMcontroller
32
![Page 33: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/33.jpg)
SDRAMcontroller(5)
• GeneratetheQsys system(mandatoryifusingthe.qip file)andgobacktoQuartus II
• UpdatetheQsys systeminstance(youcanusethetemplateintheHDLExampletabofQsys)
• UpdatethemoduleinterfacetoincludetheexternalSDRAMcontrollersignals– ConnectthemtonewQsys systeminstance– CreatethePLLtogeneratetheSDRAMclock
33
![Page 34: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/34.jpg)
SDRAMcontroller(6)//my_DE2_first_computer.v
module my_DE2_first_computer(//inputCLOCK_50,KEY,SW,//outputLEDG//Memory(SDRAM)DRAM_DQ,DRAM_ADDR,DRAM_BA_1,DRAM_BA_0,DRAM_CAS_N,DRAM_RAS_N,DRAM_CLK,DRAM_CKE,DRAM_CS_N,DRAM_WE_N,DRAM_UDQM,DRAM_LDQM
); 34
![Page 35: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/35.jpg)
SDRAMcontroller(6)input CLOCK_50;input [0:0] KEY;input [7:0] SW;output [7:0] LEDG;//Memory(SDRAM)inout [15:0] DRAM_DQ;output [11:0] DRAM_ADDR;output DRAM_BA_1;output DRAM_BA_0;output DRAM_CAS_N;output DRAM_RAS_N;output DRAM_CLK;output DRAM_CKE;output DRAM_CS_N;output DRAM_WE_N;output DRAM_UDQM;output DRAM_LDQM;
//Addthenios_systeminstance//Theinstancetemplatecanbecopied fromQsysHDLexampletab
//(Generate)andConnecttheSDRAMClock(DRAM_CLK)endmodule
35
![Page 36: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/36.jpg)
SDRAMClock
• DRAM_CLKmustlead CLOCK_50by3ns• Require instantiatingandconfiguringaPLL– CanbedoneusingtheMegaWizardPlug-inManager[I/OLibrary]
– c0andc1havethesamefrequencyasinclok0,i.e.,50MHzbutareshiftedeachotherby3ns
• IntegratethePLLinto thetopmodule
• Compilethedesign36
![Page 37: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/37.jpg)
Puttingintopractice
• CreateanewprojectinEclipseandseeifthenewcomputerworkswiththeSDRAMmemory
• Ifok,re-enablethestdio functionsandwriteasimpleprogramthatusethem–WorkontheBlocking/NonblockingI/Ooperations
• Whendone,goaheadtointegratetheLCDintoyourcomputer
37
![Page 38: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/38.jpg)
16x2CharacterDisplay(1)Architectureofthe16x2characterdisplayperipheral
38
![Page 39: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/39.jpg)
16x2CharacterDisplay(2)Portdeclarationofthe16x2characterLCDmodule
modulecharacter_lcd_0(//Inputsclk,reset,address,chipselect,read,write,writedata,
//BidirectionalsLCD_DATA,
//OutputsLCD_ON,LCD_BLON,LCD_EN,LCD_RS,LCD_RW,readdata,waitrequest
);
ExternalsignalsoftheFPGAconnectedtothe16x2characterdisplay
39
![Page 40: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/40.jpg)
CharacterLCDAPI• Headerfile:altera_up_character_lcd.h• Devicetype:alt_up_character_lcd_dev• Functionprototypes:
– alt_up_character_lcd_dev*alt_up_character_lcd_open_dev(constchar*name);
– voidalt_up_character_lcd_init(alt_up_character_lcd_dev*lcd);– int alt_up_character_lcd_set_cursor_pos (alt_up_character_lcd_dev
*lcd,unsignedx_pos, unsignedy_pos);– voidalt_up_character_lcd_string(alt_up_character_lcd_dev*lcd,
const char*ptr);– ...
40
![Page 41: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/41.jpg)
TestthenewNiosIIsystem
• Writeasimpleprogramthatwtitesastringonthe16x2characterdisplay
41
![Page 42: 07b SOPC Nios HW Tutorial - unipi.it · – Build a (NIOS II) Computer tailored to application needs • Solutions: ... A 3 V 64 S 4 0 F TP- G 6 Speed Grade 7: 143MHz@CL=3 6:](https://reader036.vdocuments.site/reader036/viewer/2022081521/5ec342afc229b2021f317af3/html5/thumbnails/42.jpg)
References
• Altera“EmbeddedPeripheralsUserGuide,”ug_embedded_ip.pdf– SectionI- Chapter2.SDRAMcontroller
• Zentel,“A3V64S40FTPdatasheet”• Altera,“UsingtheSDRAMMemoryonAltera’sDE2Board,”tut_DE2_sdram_verilog.pdf withVerilogDesign
• Altera,“16x2CharacterDisplayforAlteraDE2-SeriesBoards,”Character_LCD.pdf
42