NiosIIExercisesVer3.docx
《NiosIIExercisesVer3.docx》由会员分享,可在线阅读,更多相关《NiosIIExercisesVer3.docx(71页珍藏版)》请在冰豆网上搜索。
NiosIIExercisesVer3
DesigningwithNiosIIandSOPCBuilder
ExerciseManual
Lab1
CreatingaNiosIISystem
_____________________________________________________________________
Note:
Forthefollowingsetoflabexercises,moredetailedstep-by-stepinstructionsareprovidedinthe“SolutionsManual”locatedatthebackofthisdocument.
_____________________________________________________________________
Hardwaresetuprequirements:
∙ByteBlaster,ByteBlasterII,ByteBlasterMV,orUSB-BlasterconnectedbetweencomputerandByteBlasterconnectionondevelopmentboard
∙Powersupplyconnectedtotheboard
1.CreateadirectoryontheCdriveofyourcomputercalled“altera_trn”ifthereisn’tonealready.Copythefilenios_II_lab_QII4.1.exetothatdirectoryanddoubleclickonit.Thiswillunzipthelabfilestoadirectorycallednios_II_lab.AmongthesefilesisthepartiallycompletedQuartusIIprojectcalledniosII_lab.qpfthatwewillusetoday.
2.StarttheQuartusIISoftware,andopenthisQuartusIIproject.
3.AssigndevicefamilyandpinoutsettingstotheQuartusIIproject:
SourceoneoftheTCLscriptsthatwehaveprovidedtoassignrelevantdevicesettingsandpinoutsfortheparticularFPGAdevelopmentboardthatyouareusing.Thatis,fromtheToolsmenuselectTclScripts,andthenfromtheprojectfolderhighlightthesetupscriptforyourdevelopmentboard(eg.Setup_Cyclone_1C20.tcl,etc.),andthenclickRun.(IfunsureofwhichscripttorunpleasecheckwhichFPGAisonyourdevelopmentboardorconsulttheworkshopco-ordinator.)ThiswillsetupyourQuartusprojectforthelabtoday.
4.Let’snowbuildourembeddedsystem!
StartSOPCBuilder,andprovidethesystemname,niosII.YoucanchooseVHDLorVerilog,dependingonwhichimplementationlanguageyouprefer.IntheSPCBuilderwindow,TargettheparticularStratixorCyclonedevelopmentboardthatyouareusingandensurethattheSystemClockFrequencyissetto50MHz.
5.AddaNiosIIProcessortoyourdesign.FortheprocessorcoreselectNiosII/s.Settheinstructioncachesizeto4kbytes.ClicktheJTAGDebugModuletab.
6.SelecttheJTAGTargetConnectionDownloadLevel3optionandclickFinish.Thiswillgiveusallofthedebugoptionslistedonthehighlightedtab.
7.Renametheprocessorbyrightclickingonthecurrentnameandselectingrename.Typeincpuandhitenter.
NB:
ItisimportanttoenterthenamesofanyperipheralsormemorieswithinSOPCBuilderEXACTLYasshown.ThesearereferencedbypinsettingsandC–CodeexamplesandassucharealsoCASESENSITIVE.
8.AddanIDT71V416SRAMmemorytoyourdesign.Selectamemorysizeof1024kB,andrenamethememorytoext_ram.
9.AddaFlashMemory(CommonFlashInterface)toyourdesign-choosetheAMD29LV065D-120Rpresetwithanaddresswidthof23andadatawidthof8.Renamethememorytoext_flash.
10.AddtheJTAGUARTperipheralandacceptthedefaults.IntheSimulationtabbesuretoselectCreateModelSimaliastoopenawindowshowingoutputasASCIItext,andrenametheperipheraltojtag_uart.
11.AddaPIO(ParallelI/O)withbuswidthof16bitswithdirectionsettooutputportsonly.Renamethisperipheralseven_seg_pio.
12.AddanotherPIO(ParallelI/O)withbuswidthof8bitssettooutputportsonly.Renamethisperipheralled_pio.
13.AddonemorePIO(ParllelI/O),thistimewithawidthof4bitssettoInputportsonly.Renamethisperipheralbutton_pio.
14.AddanIntervalTimerfromtheOthersectioninthelistofSOPCBuilderperipherals.Acceptthedefaults,andrenamethetimertosys_clk_timer.
15.AddanotherIntervalTimer,butthistimechangetheperiodtousec.Renamethetimertohigh_res_timer.(Wearegoingtousethislaterwhenwetimethespeedofsomeofoursoftwarefunctions.)
16.NowaddaSystemIDPeripheralfromtheOthersection.
17.AddanAvalonTri-StateBridge,beingsuretosettheRegisteredoption.Renametheperipheralext_ram_bus.
18.ToensurethatallbaseaddressesarevalidselectAuto-AssignBaseAddresses.
19.NowsettheResetandExceptionAddressesoftheCPUontheMore“cpu”Settingspage:
Chooseext_flashfortheResetAddressandext_ramfortheExceptionAddress.Also,UnchecktheSimulationcheckbox.Thiswillspeedupsystemgeneration.
Yoursystemshouldlooklikethis:
(withtheTargetsettotheboardyouareusing.)
20.NowclickGeneratesothatSOPCBuildercanproducetheparameterizedNiosIIprocessorsystem.
21.AftertheSOPCBuilderhasfinishedgeneratingyoursystem,openthepartially-completedniosII_lab.bdfschematicinQuartusII,andaddtheniosIIsymbol.
22.PressOKandlocateandplacethesymbolintheschematicsothatitlinesupwiththepinplacementsasshownbelow.Thepinsshouldalllineupexactly!
Iftheydon’t,chancesarethatyouneedtogobacktotheeSOPCBuilderandre-checkyourwork.
23.NowsavetheschematicandstartcompilationinQuartusbyselectingStartCompilationfromtheProcessingmenu.
Donotwaitforcompilationtocomplete.Wewillcontinuefromthispointduringthenextlab.
ENDOFLAB1
Lab2
SoftwareFlow
WearenowgoingtoprogramtheFPGAwiththedesignimage,andrunsomesoftwareonit.
1.OpentheQuartusIIProgrammer,anddownloadtheNiosIIFPGAdesign(ie.thenios_sys.sof)createdinthepreviouslabtotheNiosdevelopmentboard.
2.LaunchtheNiosIIIDE.
3.CreateanewsoftwareprojectcalledniosII_training_project.EnsurethattheptffilefromyourSOPCBuildersession(niosII.ptf)populatestheSOPCBuilderSystemfieldintheSelectTargetHardwaresection.Also,usetheBlankProjecttemplate.
4.PressNextandFinishtocreateanewsystemlibraryforyourapplication.
5.YouhavenowactuallycreatedtwonewsoftwareprojectsintheNiosIIIDE-aC/C++applicationprojectandasystemlibraryproject.However,theC/C++applicationprojectisblankandweneedtoaddsourcecodefilestotheproject.Addthesimple.cfiletotheprojectbyclickingontheNavigatortabonthelowerlefthandpaneloftheNiosIIIDEandexpandingtheniosII_training_projectfolder.
Then,openFileExplorerinWindowsandthenbrowsetothealtera_trn\nios_II_lab\softwarefolder.Dragthesimple.cfilefromthisfolderintotheniosII_training_projectfolderintheNavigatortabintheNiosIIIDE.
6.NowswitchbacktotheC/C++ProjecttabonthelefthandpanelintheNiosIIIDE.HighlighttheniosII_training_projectfolder,right-clickonthisfolder,andthenselectRefreshtoensurethattheprojectrecognizesthatwehaveaddedthesimple.cfile.
7.EdittheSystemLibraryPropertiesforthissoftwareproject,andensurethatthestdout,stderrandstdindevicesaresettojtag_uart.AlsoensurethatthePeriodicsystemtimerissettoSYS_CLK_TIMERandthattheProgram,Read-onlydata,andRead/writememoryfieldsaresettoext_ram.
8.WehavenowcreatedaprojecttorunoutofexternalSRAMthatusestheJTAGUARTasthestdiodevice.Now,compiletheprojectintheNiosIIIDE.
9.Afterthecompilationcompletes,downloadandRuntheprogramonthedevelopmentboard.
Note:
IfRunterminatesbeforethecodedownloadstoyourboard,andyougetamessagepertainingtotheJTAGdownloadcable.thenselectRun>Run…andfromtheTargetConnectiontabchoosetheappropriatedownloadcablethatyouareusingandhitApplyandRun.
ObservethattheconsolewindowintheNiosIIIDEdisplaystheprintfstatementfromthesimple.cprogram.PressofanyofthebuttonsontheboardtoshifttheLEDonespacetotheright.
10.NowstartthedebuggerbyselectingDebugAs->NiosIIHardware.Thedebuggerwilllaunch,connecttothetargetanddownloadtheprogramreadyfordebug.
11.Setbreakpointsonline22andline37.(IfthetexteditorintheNiosIIIDEdoesnotdisplaythelinernumberthenweneedtosetthoseinthePreferencesfromtheWindowmenu.OpentheC/C++folderandselectC/C++Editor.ChecktheShowlinenumbersboxandpressOK).Acirclewillappearnexttothelinenumberonwhichyouhavesetabreakpoint.
12.Clickontheresumebutton
.
13.Now,selecttheVariableswindowandviewthecontentsofthebuttonsvariable.NoticethatthebuttonshavebeenreadasshownintheVariableswindow.Changethisviewtohexadecimalbyright-clickingonthebuttonsvalueandselectingFormat=>Hexadecimal.
14.Clickresume
again.Sincetheifexpressionisfalse(ie.nobuttonsarepressed)thestatementswithinthecurlybracesarenotexecutedandwewillnotbreakonline37,insteadwewillbreakonline22again.
15.HolddownswitchSW3ontheboardandclickresume.Anewvalueisstoredinthevariablebuttons.
16.ContinuetoholddownSW3andclickresumeagain.Thebreakpointonline37isnowcaughtasabuttonwaspressed,sotheifconditionistrue.NoticethatthelitLEDhasalsochangedposition.
17.Clickresume.
18.Double-clickonbuttonswithinthevariableswindow.Nowchangethevalueto0xeandpressOK.Clickresume.Theifstatementisexecutedastruebecausewewehavechangedthebuttonvalueusingthevariableswindow.
Thisisusefulforemulatingexternalhardwareeventsorotherconditionsthataredifficulttoreplicate!
19.Fromthedebugmenu,right-clickonthesoftwareproject,andselectTerminateandRemove.Thenclose(
)simple.cintheNiosIIIDE.
Lab3
RTLSimulation
InthislabwewilluseModelSim-Alteratosimulaterunningcode.
1.SOPCBuildercanbeusedtocustomizetheJTAGUARTsothatitcangenerateadatastreamtosendtothehostprocessorduringsimulation.Doubleclickthejtag_uartperipheral,andasthedialogboxopens,ClicktheSimulationtab.T