app.rst 143 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474
  1. .. _design_app:
  2. Application
  3. ===========
  4. .. _design_app_overview:
  5. Overview
  6. --------
  7. In Nuclei SDK, we just provided applications which can
  8. run in different boards without any changes in code to
  9. demonstrate the baremetal service, freertos service and
  10. ucosii service features.
  11. The provided applications can be divided into three categories:
  12. * Bare-metal applications: Located in ``application/baremetal``
  13. * FreeRTOS applications: Located in ``application/freertos``
  14. * UCOSII applications: Located in ``application/ucosii``
  15. * RTThread applications: Located in ``application/rtthread``
  16. * ThreadX applications: Located in ``application/threadx``
  17. **If you want to find more examples, please visit the following links**:
  18. * Nuclei Board Labs: https://github.com/Nuclei-Software/nuclei-board-labs
  19. * Nuclei Tensorflow Lite Micro AI Demo: https://github.com/Nuclei-Software/npk-tflm
  20. * Nuclei Tinymaix TinyAI Demo: https://github.com/Nuclei-Software/npk-tinymaix
  21. * NMSIS DSP Examples: https://doc.nucleisys.com/nmsis/dsp/get_started.html#how-to-run
  22. * NMSIS NN Examples: https://doc.nucleisys.com/nmsis/nn/get_started.html#how-to-run
  23. * NMSIS Crypto(MbedTLS) Examples: https://github.com/Nuclei-Software/mbedtls/blob/nuclei/v3.3.0/accelerator/README.md
  24. And we can also provide more examples to test cpu features, please contact with our
  25. AE for help.
  26. If you want to develop your own application in Nuclei SDK, please click
  27. :ref:`develop_appdev` to learn more about it.
  28. The following applications are running using RV-STAR board or Nuclei Eval SoC.
  29. .. note::
  30. * Since 0.7.0 introduced support for CLINT and PLIC interrupt mode, if
  31. you are working in such interrupt mode or don't have ECLIC module, then
  32. all RTOSes will not able to run in your environment, due to RTOS port
  33. require ECLIC interrupt.
  34. * Most of the application demostrated below using ``SOC=gd32vf103``,
  35. you can easily change it to other SoC such as evalsoc by change it to
  36. ``SOC=evalsoc``
  37. * Some applications may not be able to be run on your SoC using Nuclei CPU
  38. due to lack of cpu feature required to run on it.
  39. * Almost all the applications required Nuclei CPU configured with
  40. ECLIC and System Timer hardware feature.
  41. * Almost all the application required UART to print message, so you need to
  42. implement an UART drivers and clib stub functions, if you use
  43. :ref:`develop_buildsystem_var_semihost` to print message, it is not required.
  44. Bare-metal applications
  45. -----------------------
  46. .. _design_app_helloworld:
  47. helloworld
  48. ~~~~~~~~~~
  49. This `helloworld application`_ is used to print hello world, and also
  50. will check this RISC-V CSR **MISA** register value.
  51. **How to run this application:**
  52. .. code-block:: shell
  53. # Assume that you can set up the Tools and Nuclei SDK environment
  54. # cd to the helloworld directory
  55. cd application/baremetal/helloworld
  56. # Clean the application first
  57. make SOC=gd32vf103 clean
  58. # Build and upload the application
  59. make SOC=gd32vf103 upload
  60. **Expected output as below:**
  61. .. code-block:: console
  62. Nuclei SDK Build Time: Feb 21 2020, 12:24:22
  63. Download Mode: FLASHXIP
  64. CPU Frequency 109323529 Hz
  65. MISA: 0x40901105
  66. MISA: RV32IMACUX
  67. 0: Hello World From Nuclei RISC-V Processor!
  68. 1: Hello World From Nuclei RISC-V Processor!
  69. 2: Hello World From Nuclei RISC-V Processor!
  70. 3: Hello World From Nuclei RISC-V Processor!
  71. 4: Hello World From Nuclei RISC-V Processor!
  72. 5: Hello World From Nuclei RISC-V Processor!
  73. 6: Hello World From Nuclei RISC-V Processor!
  74. 7: Hello World From Nuclei RISC-V Processor!
  75. 8: Hello World From Nuclei RISC-V Processor!
  76. 9: Hello World From Nuclei RISC-V Processor!
  77. 10: Hello World From Nuclei RISC-V Processor!
  78. 11: Hello World From Nuclei RISC-V Processor!
  79. 12: Hello World From Nuclei RISC-V Processor!
  80. 13: Hello World From Nuclei RISC-V Processor!
  81. 14: Hello World From Nuclei RISC-V Processor!
  82. 15: Hello World From Nuclei RISC-V Processor!
  83. 16: Hello World From Nuclei RISC-V Processor!
  84. 17: Hello World From Nuclei RISC-V Processor!
  85. 18: Hello World From Nuclei RISC-V Processor!
  86. 19: Hello World From Nuclei RISC-V Processor!
  87. .. _design_app_cpuinfo:
  88. cpuinfo
  89. ~~~~~~~
  90. This `cpuinfo application`_ is used to print the Nuclei RISC-V CPU information
  91. to help you to know what CPU features are present in this processor.
  92. You can also use openocd to probe the cpu feature, see https://doc.nucleisys.com/nuclei_tools/openocd/intro.html#cpu-information-display
  93. .. note::
  94. - From Nuclei SDK 0.9.0 and Nuclei OpenOCD 2025.10, the cpuinfo implementation are synced using same code base to probe
  95. and analyze Nuclei CPU Information, both basic information and detailed information are provided.
  96. - In future, when Nuclei OpenOCD new release happened, it will sync cpuinfo implementation c code from latest Nuclei SDK
  97. implementation.
  98. **How to run this application:**
  99. .. code-block:: shell
  100. # Assume that you can set up the Tools and Nuclei SDK environment
  101. # cd to the helloworld directory
  102. cd application/baremetal/cpuinfo
  103. # Assume to run on UX1030 SMPx1 RVA23 CPU
  104. # Clean the application first
  105. make SOC=evalsoc DOWNLOAD=sram clean
  106. # Build and upload the application
  107. make SOC=evalsoc DOWNLOAD=sram upload
  108. **Expected output as below:**
  109. .. code-block:: console
  110. Nuclei SDK Build Time: Sep 23 2025, 09:41:30
  111. Download Mode: SRAM
  112. CPU Frequency 50327388 Hz
  113. CPU HartID: 0
  114. -----Nuclei RISC-V CPU Configuration Information-----
  115. MARCHID: 0x1000
  116. MIMPID: 0x10300
  117. ISA: RV64 A B C D F H I M S U V
  118. MCFG: ECLIC PLIC ICACHE DCACHE SMP IREGION SSTC No-Safety-Mechanism DLEN=VLEN VLEN=128
  119. ICACHE: 128 KB(set=512,way=4,lsize=64,ecc=0)
  120. DCACHE: 128 KB(set=1024,way=2,lsize=64,ecc=0)
  121. TLB: MainTLB(entry=256,way=4,ecc=0) ITLB(entry=16) DTLB(entry=16)
  122. IREGION: 0x18000000 128 MB
  123. Unit Size Address
  124. INFO 64KB 0x18000000
  125. DEBUG 64KB 0x18010000
  126. ECLIC 64KB 0x18020000
  127. TIMER 64KB 0x18030000
  128. SMP 64KB 0x18040000
  129. PLIC 64MB 0x1c000000
  130. SMP_CFG: CC_PRESENT=1 SMP_NUM=1 IOCP_NUM=0 PMON_NUM=4
  131. ECLIC: VERSION=0x1 NUM_INTERRUPT=147 CLICINTCTLBITS=3 MTH=0 NLBITS=3
  132. L2CACHE: 2 MB(set=2048,way=16,lsize=64,ecc=0)
  133. INFO-Detail:
  134. mpasize : 35
  135. prefetch: present
  136. prefetch_mode: normal
  137. status: disable
  138. version=4
  139. l2_pf_lbuf_num=10
  140. l2_pf_dbuf_num=2
  141. l1d_ena=1
  142. cc_ena=1
  143. scalar_ena=1
  144. vector_ena=1
  145. write_pref_ena=1
  146. cross_page_pref_ena=1
  147. pref_conflict_stop_th=1
  148. pref_conflict_decr_sel=2
  149. degree_incr_th=0
  150. degree_decr_th=0
  151. next_line_ena_th=5
  152. write_noalloc_l1_th=0
  153. write_noalloc_l2_th=0
  154. max_stream_l1_degree=6
  155. max_stream_l2_degree=16
  156. max_stride_cplx_l1_degree=3
  157. max_stride_cplx_l2_degree=8
  158. isa supported: present
  159. extension_list: vector smepmp sscofpmf zfh zfa svnapot svpbmt svinval bf16 zimop zcmop zicond zihintntl zihintpause zihpm smcntrpmf zicntr zawrs
  160. vpu: present
  161. vpu_extension_list: vector_b zve64f zve64d zvfh
  162. noseg_noshuf=0
  163. elen64=1
  164. vlm: absent
  165. flash bus: absent
  166. mem_region0: absent
  167. mem_region1: absent
  168. cppi: absent
  169. cmo: present
  170. cbozero_size: 64 Bytes
  171. cmo_size: 64 Bytes
  172. cmo_prefetch=1
  173. hw performance: present
  174. bus: ICB
  175. fpu_cycle=5
  176. high_div=1
  177. dcache_2stage=1
  178. delay_branch_flush=0
  179. dual_issue=0
  180. cross_4k=0
  181. dlm_2stage=0
  182. lsu_cut_fwd=0
  183. dsp_cycle=0
  184. ifu_cut_timing=0
  185. mem_cut_timing=0
  186. dcache_prefetch=0
  187. dcache_lbuf_num=4
  188. mul_cyc=3
  189. vfpu_cyc=4
  190. bht_entry_width=2
  191. high_performance=1
  192. agu_quick_forward=1
  193. cau_fwd=0
  194. hpm_ver=2
  195. misc:
  196. ws_tmout_max=767
  197. nc_tmout_max=0
  198. dev_store_early_ret=0
  199. reg_prot_chck_en=1
  200. pf_access=0
  201. cache_csr_access=0
  202. pma_csr_access=0
  203. -----End of Nuclei CPU INFO-----
  204. .. _design_app_demo_timer:
  205. demo_timer
  206. ~~~~~~~~~~
  207. This `demo_timer application`_ is used to demonstrate how to use
  208. the CORE TIMER API including the Timer Interrupt and Timer Software Interrupt in ECLIC interrupt mode.
  209. * Both interrupts are registered as non-vector interrupt.
  210. * First the timer interrupt will run for 5 times
  211. * Then the software timer interrupt will start to run for 5 times
  212. **How to run this application:**
  213. .. code-block:: shell
  214. # Assume that you can set up the Tools and Nuclei SDK environment
  215. # cd to the demo_timer directory
  216. cd application/baremetal/demo_timer
  217. # Clean the application first
  218. make SOC=gd32vf103 clean
  219. # Build and upload the application
  220. make SOC=gd32vf103 upload
  221. **Expected output as below:**
  222. .. code-block:: console
  223. Nuclei SDK Build Time: Feb 21 2020, 12:52:37
  224. Download Mode: FLASHXIP
  225. CPU Frequency 108794117 Hz
  226. init timer and start
  227. MTimer IRQ handler 1
  228. MTimer IRQ handler 2
  229. MTimer IRQ handler 3
  230. MTimer IRQ handler 4
  231. MTimer IRQ handler 5
  232. MTimer SW IRQ handler 1
  233. MTimer SW IRQ handler 2
  234. MTimer SW IRQ handler 3
  235. MTimer SW IRQ handler 4
  236. MTimer SW IRQ handler 5
  237. MTimer msip and mtip interrupt test finish and pass
  238. .. _design_app_demo_clint_timer:
  239. demo_clint_timer
  240. ~~~~~~~~~~~~~~~~
  241. This `demo_clint_timer application`_ is used to demonstrate how to use
  242. the CORE TIMER API including the Timer Interrupt and Timer Software Interrupt in CLINT interrupt mode.
  243. * Interrupt is set to working in CLINT interrupt mode
  244. * Both interrupts are registered as core interrupt.
  245. * First the timer interrupt will run for 5 times
  246. * Then the software timer interrupt will start to run for 5 times
  247. * **NOTE**: not able to working in qemu, and only works for evalsoc
  248. **How to run this application:**
  249. .. code-block:: shell
  250. # Assume that you can set up the Tools and Nuclei SDK environment
  251. # cd to the demo_timer directory
  252. cd application/baremetal/demo_clint_timer
  253. # Clean the application first
  254. make SOC=evalsoc clean
  255. # Build and upload the application
  256. make SOC=evalsoc upload
  257. **Expected output as below:**
  258. .. code-block:: console
  259. Nuclei SDK Build Time: Jul 25 2024, 10:39:39
  260. Download Mode: ILM
  261. CPU Frequency 16000614 Hz
  262. CPU HartID: 0
  263. init timer and start
  264. SysTimer IRQ handler 1
  265. SysTimer IRQ handler 2
  266. SysTimer IRQ handler 3
  267. SysTimer IRQ handler 4
  268. SysTimer IRQ handler 5
  269. SysTimer SW IRQ handler 1
  270. SysTimer SW IRQ handler 2
  271. SysTimer SW IRQ handler 3
  272. SysTimer SW IRQ handler 4
  273. SysTimer SW IRQ handler 5
  274. SysTimer MTIP and MSIP CLINT interrupt test finish and pass
  275. .. _design_app_demo_eclic:
  276. demo_eclic
  277. ~~~~~~~~~~
  278. This `demo_eclic application`_ is used to demonstrate how to use
  279. the ECLIC API and Interrupt is working in ECLIC interrupt mode.
  280. .. note::
  281. In this application's Makefile, we provided comments in Makefile about optimize
  282. for code size.
  283. If you want to optimize this application for code size, you can set the ``COMMON_FLAGS``
  284. variable to the following values, we recommend to use ``-Os -flto``.
  285. .. list-table:: Code size optimization for demo_eclic on RV-STAR target
  286. :widths: 60 20 20 20 20
  287. :header-rows: 1
  288. * - COMMON_FLAGS
  289. - text(bytes)
  290. - data(bytes)
  291. - bss(bytes)
  292. - total(bytes)
  293. * -
  294. - 13724
  295. - 112
  296. - 2266
  297. - 16102
  298. * - -flto
  299. - 13598
  300. - 112
  301. - 2266
  302. - 15976
  303. * - -Os
  304. - 9690
  305. - 112
  306. - 2264
  307. - 12066
  308. * - -Os -flto
  309. - 9132
  310. - 112
  311. - 2264
  312. - 11508
  313. * - -Os -msave-restore -fno-unroll-loops
  314. - 9714
  315. - 112
  316. - 2264
  317. - 12090
  318. * - -Os -msave-restore -fno-unroll-loops -flto
  319. - 9204
  320. - 112
  321. - 2264
  322. - 11580
  323. * The timer interrupt and timer software interrupt are used
  324. * The timer interrupt is registered as non-vector interrupt
  325. * The timer software interrupt is registered as vector interrupt,
  326. and we enable its preemptive feature by using ``SAVE_IRQ_CSR_CONTEXT``
  327. and ``RESTORE_IRQ_CSR_CONTEXT`` in timer software interrupt handler
  328. * The timer interrupt is triggered periodically
  329. * The timer software interrupt is triggered in timer interrupt handler using
  330. ``SysTimer_SetSWIRQ`` function
  331. * In the application code, there is a macro called ``SWIRQ_INTLEVEL_HIGHER`` to
  332. control the timer software interrupt working feature:
  333. - If **SWIRQ_INTLEVEL_HIGHER=1**, the timer software interrupt level is higher than
  334. timer interrupt level, so when timer software interrupt is triggered, then timer
  335. software interrupt will be processed immediately, and timer interrupt will be preempted
  336. by timer software interrupt.
  337. - If **SWIRQ_INTLEVEL_HIGHER=0**, the timer software interrupt level is lower than
  338. timer interrupt level, so when timer software interrupt is triggered, then timer
  339. software interrupt will be processed after timer interrupt, and timer interrupt will
  340. not be preempted by timer software interrupt.
  341. **How to run this application:**
  342. .. code-block:: shell
  343. # Assume that you can set up the Tools and Nuclei SDK environment
  344. # cd to the demo_eclic directory
  345. cd application/baremetal/demo_eclic
  346. # Change macro SWIRQ_INTLEVEL_HIGHER value in demo_eclic.c
  347. # to see different working mode of this demo
  348. # Clean the application first
  349. make SOC=gd32vf103 clean
  350. # Build and upload the application
  351. make SOC=gd32vf103 upload
  352. **Expected output(SWIRQ_INTLEVEL_HIGHER=1) as below:**
  353. .. code-block:: console
  354. Nuclei SDK Build Time: Feb 21 2020, 16:35:58
  355. Download Mode: FLASHXIP
  356. CPU Frequency 108794117 Hz
  357. Initialize timer and start timer interrupt periodically
  358. -------------------
  359. [IN TIMER INTERRUPT]timer interrupt hit 0 times
  360. [IN TIMER INTERRUPT]trigger software interrupt
  361. [IN TIMER INTERRUPT]software interrupt will run during timer interrupt
  362. [IN SOFTWARE INTERRUPT]software interrupt hit 0 times
  363. [IN SOFTWARE INTERRUPT]software interrupt end
  364. [IN TIMER INTERRUPT]timer interrupt end
  365. -------------------
  366. [IN TIMER INTERRUPT]timer interrupt hit 1 times
  367. [IN TIMER INTERRUPT]trigger software interrupt
  368. [IN TIMER INTERRUPT]software interrupt will run during timer interrupt
  369. [IN SOFTWARE INTERRUPT]software interrupt hit 1 times
  370. [IN SOFTWARE INTERRUPT]software interrupt end
  371. [IN TIMER INTERRUPT]timer interrupt end
  372. -------------------
  373. [IN TIMER INTERRUPT]timer interrupt hit 2 times
  374. [IN TIMER INTERRUPT]trigger software interrupt
  375. [IN TIMER INTERRUPT]software interrupt will run during timer interrupt
  376. [IN SOFTWARE INTERRUPT]software interrupt hit 2 times
  377. [IN SOFTWARE INTERRUPT]software interrupt end
  378. [IN TIMER INTERRUPT]timer interrupt end
  379. -------------------
  380. [IN TIMER INTERRUPT]timer interrupt hit 3 times
  381. [IN TIMER INTERRUPT]trigger software interrupt
  382. [IN TIMER INTERRUPT]software interrupt will run during timer interrupt
  383. [IN SOFTWARE INTERRUPT]software interrupt hit 3 times
  384. [IN SOFTWARE INTERRUPT]software interrupt end
  385. [IN TIMER INTERRUPT]timer interrupt end
  386. **Expected output(SWIRQ_INTLEVEL_HIGHER=0) as below:**
  387. .. code-block:: console
  388. Nuclei SDK Build Time: Feb 21 2020, 16:35:58
  389. Download Mode: FLASHXIP
  390. CPU Frequency 108794117 Hz
  391. Initialize timer and start timer interrupt periodically
  392. -------------------
  393. [IN TIMER INTERRUPT]timer interrupt hit 0 times
  394. [IN TIMER INTERRUPT]trigger software interrupt
  395. [IN TIMER INTERRUPT]software interrupt will run when timer interrupt finished
  396. [IN TIMER INTERRUPT]timer interrupt end
  397. [IN SOFTWARE INTERRUPT]software interrupt hit 0 times
  398. [IN SOFTWARE INTERRUPT]software interrupt end
  399. -------------------
  400. [IN TIMER INTERRUPT]timer interrupt hit 1 times
  401. [IN TIMER INTERRUPT]trigger software interrupt
  402. [IN TIMER INTERRUPT]software interrupt will run when timer interrupt finished
  403. [IN TIMER INTERRUPT]timer interrupt end
  404. [IN SOFTWARE INTERRUPT]software interrupt hit 1 times
  405. [IN SOFTWARE INTERRUPT]software interrupt end
  406. -------------------
  407. [IN TIMER INTERRUPT]timer interrupt hit 2 times
  408. [IN TIMER INTERRUPT]trigger software interrupt
  409. [IN TIMER INTERRUPT]software interrupt will run when timer interrupt finished
  410. [IN TIMER INTERRUPT]timer interrupt end
  411. [IN SOFTWARE INTERRUPT]software interrupt hit 2 times
  412. [IN SOFTWARE INTERRUPT]software interrupt end
  413. -------------------
  414. [IN TIMER INTERRUPT]timer interrupt hit 3 times
  415. [IN TIMER INTERRUPT]trigger software interrupt
  416. [IN TIMER INTERRUPT]software interrupt will run when timer interrupt finished
  417. [IN TIMER INTERRUPT]timer interrupt end
  418. [IN SOFTWARE INTERRUPT]software interrupt hit 3 times
  419. [IN SOFTWARE INTERRUPT]software interrupt end
  420. .. _design_app_demo_eclic_umode:
  421. demo_eclic_umode
  422. ~~~~~~~~~~~~~~~~
  423. This `demo_eclic_umode application`_ demonstrates how to switch from machine mode to user mode on Nuclei RISC-V processors.
  424. It showcases the usage of PMP (Physical Memory Protection) configuration, ECLIC (Enhanced Core-Local Interrupt Controller)
  425. interrupt handling, and SysTimer functionality.
  426. The application initializes a timer interrupt, configures PMP/SMPU(if present) protection, and then switches to user mode
  427. where it waits for timer interrupt to occur. When the interrupt is triggered and handled in machine mode, the user mode
  428. application detects this event and confirms successful mode switching and interrupt handling.
  429. .. note::
  430. This demo requires M/S/U mode, ECLIC, PMP, and optional SMPU to be present.
  431. **How to run this application:**
  432. .. code-block:: shell
  433. # Assume that you can set up the Tools and Nuclei SDK environment
  434. # cd to the demo_eclic_umode directory
  435. cd application/baremetal/demo_eclic_umode
  436. # Clean the application first
  437. # Assume you are running on evalsoc with U900 CORE
  438. # with ECLIC M/S/U mode present
  439. make SOC=evalsoc CORE=u900 clean
  440. # Build and upload the application
  441. make SOC=evalsoc CORE=u900 upload
  442. **Expected output(SWIRQ_INTLEVEL_HIGHER=1) as below:**
  443. .. code-block:: console
  444. Nuclei SDK Build Time: Sep 16 2025, 17:13:10
  445. Download Mode: ILM
  446. CPU Frequency 16167731 Hz
  447. CPU HartID: 0
  448. Configure SMPU due to TEE Present
  449. Initialize timer and start timer interrupt
  450. switch to user mode successfully
  451. Enter to SysTimer M-Mode interrupt handler
  452. go back to user mode from SysTimer IRQ handler
  453. [SUCCESS] Test M-mode drop to U-mode passed!
  454. .. _design_app_demo_eclic_stress:
  455. demo_eclic_stress
  456. ~~~~~~~~~~~~~~~~~
  457. This `demo_eclic_stress application`_ is used to validate the functionality of the Nuclei RISC-V processor's Enhanced Core Local Interrupt Controller (ECLIC) in both Machine Mode (M-Mode) and Supervisor Mode (S-Mode) environments. The test performs comprehensive stress validation of interrupt handling capabilities, focusing on:
  458. **M-Mode and S-Mode Interrupt Handling**: The application tests both timer interrupts (SysTimer_IRQn) with non-vector mode and software interrupts (SysTimerSW_IRQn) with vector mode, along with external interrupts (SOC_INT20_IRQn to SOC_INT39_IRQn) with mixed vector/non-vector modes.
  459. **Interrupt Nesting and Priority Handling**: The test validates different interrupt levels (0-4) to ensure proper handling of nested interrupts, where higher-level interrupts can preempt lower-level handlers with proper context restoration.
  460. **Cross-Mode Interrupt Scenarios**: The application verifies proper isolation and communication between M-Mode and S-Mode interrupt handling, ensuring both privilege levels function correctly under stress conditions.
  461. **Vector and Non-Vector Interrupt Testing**: The stress test comprehensively validates both vector and non-vector interrupt modes, including context saving/restoring for vector interrupts and proper handling of non-vector interrupts.
  462. **Advanced ECLIC Features**: The test validates level-triggered and edge-triggered interrupt configurations, interrupt pending/clear operations, CSR (Control and Status Register) context management, and ECLICv2 automatic stack switching when applicable.
  463. **Stress Testing**: The application continuously stresses the system with computation in interrupt handlers, background computation in main threads, and verification that all interrupt counters increment consistently to ensure reliable operation under heavy interrupt load.
  464. .. note::
  465. - This demo requires ECLIC, System Timer, and optional TEE (Trusted Execution Environment) and SSTC extension to be present. When TEE and SSTC is present, both M-Mode and S-Mode interrupts are tested. When TEE is not present, only M-Mode interrupts are tested.
  466. - It can also work with ECLICv2, see :ref:`design_soc_evalsoc_eclicv2`
  467. **How to run this application:**
  468. .. code-block:: shell
  469. # Assume that you can set up the Tools and Nuclei SDK environment
  470. # cd to the demo_eclic_stress directory
  471. cd application/baremetal/demo_eclic_stress
  472. # Clean the application first
  473. # Assume you are running on evalsoc with ECLIC and System Timer, TEE and SSTC present
  474. # If TEE and SSTC not present, just pass XLCFG_TEE=0 XLCFG_SSTC=0
  475. # Refer to the Makefile in this folder
  476. make SOC=evalsoc clean
  477. # Build and upload the application
  478. make SOC=evalsoc upload
  479. # To test on ECLICv2, assume TEE and SSTC present
  480. make SOC=evalsoc ECLIC_HWCTX=1 XLCFG_ECLIC=2 upload
  481. # To enable separated interrupt/exception stack (only valid for ECLICv2)
  482. make SOC=evalsoc INTSTACK=1 ECLIC_HWCTX=1 XLCFG_ECLIC=2 upload
  483. **Expected output as below:**
  484. .. code-block:: console
  485. Nuclei SDK Build Time: Jan 16 2026, 18:57:32
  486. Download Mode: ILM
  487. CPU Frequency 16009461 Hz
  488. CPU HartID: 0
  489. [M] Starting ECLIC Stress Test - M-Mode and S-Mode Integration
  490. [M] Calculating expected computation results...
  491. [M] Expected results for interrupt handlers:
  492. [M] eclic_irq3_int_handler: 5666
  493. [M] eclic_irq7_int_handler: 3729
  494. [M] eclic_irq20_int_handler: 5666
  495. [M] eclic_irq21_int_handler: 3729
  496. [M] eclic_irq22_int_handler: 4086
  497. [M] eclic_irq23_int_handler: 4088
  498. [M] eclic_irq24_int_handler: 3456
  499. [M] eclic_irq25_int_handler: 7414
  500. [M] eclic_irq26_int_handler: 2736
  501. [M] eclic_irq27_int_handler: 3206
  502. [M] eclic_irq28_int_handler: 4046
  503. [M] eclic_irq29_int_handler: 6859
  504. [M] eclic_irq30_int_handler: 10120
  505. [M] eclic_irq31_int_handler: 10941
  506. [M] eclic_irq32_int_handler: 5634
  507. [M] eclic_irq33_int_handler: 8516
  508. [M] eclic_irq34_int_handler: 7574
  509. [M] eclic_irq35_int_handler: 7352
  510. [M] eclic_irq36_int_handler: 9256
  511. [M] eclic_irq37_int_handler: 5195
  512. [M] eclic_irq38_int_handler: 6629
  513. [M] eclic_irq39_int_handler: 8119
  514. [M] eclic_irq1_int_handler: 9538
  515. [M] eclic_irq5_int_handler: 9538
  516. [M] m-mode background computations: 11899
  517. [M] s-mode background computations: 10538
  518. [M] Calculation completed! Use these values to update the interrupt handlers if needed.
  519. [M] ECLIC nlbits configuration: 3
  520. [M] ECLIC Shadow Register Groups: 2
  521. [M] Shadow Level Register: 0x000000000000005f
  522. [M] Initialize timer and start timer interrupt 10 ms periodically in M-Mode
  523. [M] Use separated interrupt stack for m-mode interrupt at 0x90004c70
  524. [M] TEE is present, will run both S-Mode and M-Mode demos
  525. [M] Current sp is 0x9000ff70, so it is in Machine Mode!
  526. [M] Configuring SysTimerSW_S, SysTimer_S and SOC_INT30-39 to execute in S-Mode
  527. [M] Dropping to S-Mode now
  528. [S] Hello Supervisor Mode!!!
  529. [S] Current sp is 0x90009c90, so it is in Supervisor Mode!
  530. [S] Initialize timer and start timer interrupt 20 ms periodically in S-Mode
  531. [S] ECLIC nlbits configuration: 3
  532. [S] ECLIC Shadow Register Groups: 2
  533. [S] Supervisor Shadow Level Register: 0x000000000000007f
  534. [S] Use separated interrupt stack for s-mode interrupt at 0x90007470
  535. [M] eclic_mtip_handler (level 0) triggered IRQ 20 (level 2, trigger counter: 100), msubm 0x440, mcause 0x90000007, mintstatus 0x1f000000
  536. [M] eclic_int20_handler (level 2) triggered IRQ 21 (level 3, trigger counter: 100), msubm 0x8940, mcause 0xb81f0014, mintstatus 0x5f000000
  537. [M] eclic_int21_handler (level 3) triggered IRQ 22 (level 3, trigger counter: 100), msubm 0x10140, mcause 0xb85f0015, mintstatus 0x7f000000
  538. [M] eclic_int21_handler - non-vector (level 3) run 100 times done!
  539. [M] eclic_int22_handler (level 3) triggered IRQ 23 (level 4, trigger counter: 100), msubm 0x10140, mcause 0xb85f0016, mintstatus 0x7f000000
  540. [M] eclic_int23_handler (level 4) triggered IRQ 24 (level 2, trigger counter: 100), msubm 0x140, mcause 0xb87f0017, mintstatus 0x9f000000
  541. [M] eclic_int23_handler - non-vector (level 4) run 100 times done!
  542. [M] eclic_int22_handler - non-vector (level 3) run 100 times done!
  543. [M] eclic_int20_handler - non-vector (level 2) run 100 times done!
  544. [M] eclic_int24_handler (level 2) triggered IRQ 25 (level 1, trigger counter: 100), msubm 0x8940, mcause 0xb81f0018, mintstatus 0x5f000000
  545. [M] eclic_int24_handler - non-vector (level 2) run 100 times done!
  546. [M] eclic_int25_handler (level 1), run counter: 100, msubm 0x8940, mcause 0xb81f0019, mintstatus 0x3f000000
  547. [M] eclic_int25_handler - non-vector (level 1) run 100 times done!
  548. [M] eclic_msip_handler (level 0) triggered IRQ 26 (level 2, trigger counter: 100), msubm 0x8140, mcause 0xb81f0003, mintstatus 0x3f000000
  549. [M] eclic_int26_handler (level 2) triggered IRQ 27 (level 3, trigger counter: 100), msubm 0x140, mcause 0xb83f001a, mintstatus 0x5f000000
  550. [M] eclic_int27_handler (level 3) triggered IRQ 28 (level 2, trigger counter: 100), msubm 0x140, mcause 0xb85f001b, mintstatus 0x7f000000
  551. [M] eclic_int27_handler - vector (level 3) run 100 times done!
  552. [M] eclic_int26_handler - vector (level 2) run 100 times done!
  553. [M] eclic_int28_handler (level 2) triggered IRQ 29 (level 4, trigger counter: 100), msubm 0x140, mcause 0xb83f001c, mintstatus 0x5f000000
  554. [M] eclic_int29_handler (level 4), run counter: 100, msubm 0x140, mcause 0xb85f001d, mintstatus 0x9f000000
  555. [M] eclic_int29_handler - vector (level 4) run 100 times done!
  556. [M] eclic_int28_handler - vector (level 2) run 100 times done!
  557. [M] eclic_msip_handler - vector (level 1) run 100 times done!
  558. [M] eclic_mtip_handler - non-vector (level 0) run 100 times done!
  559. [M] eclic_mtip_handler (level 0) triggered IRQ 20 (level 2, trigger counter: 200), msubm 0x440, mcause 0x90000007, mintstatus 0x1f000000
  560. [M] eclic_int20_handler (level 2) triggered IRQ 21 (level 3, trigger counter: 200), msubm 0x8940, mcause 0xb81f0014, mintstatus 0x5f000000
  561. [M] eclic_int21_handler (level 3) triggered IRQ 22 (level 3, trigger counter: 200), msubm 0x10140, mcause 0xb85f0015, mintstatus 0x7f000000
  562. [M] eclic_int21_handler - non-vector (level 3) run 200 times done!
  563. [M] eclic_int22_handler (level 3) triggered IRQ 23 (level 4, trigger counter: 200), msubm 0x10140, mcause 0xb85f0016, mintstatus 0x7f000000
  564. [M] eclic_int23_handler (level 4) triggered IRQ 24 (level 2, trigger counter: 200), msubm 0x140, mcause 0xb87f0017, mintstatus 0x9f000000
  565. [M] eclic_int23_handler - non-vector (level 4) run 200 times done!
  566. [M] eclic_int22_handler - non-vector (level 3) run 200 times done!
  567. [M] eclic_int20_handler - non-vector (level 2) run 200 times done!
  568. [M] eclic_int24_handler (level 2) triggered IRQ 25 (level 1, trigger counter: 200), msubm 0x8940, mcause 0xb81f0018, mintstatus 0x5f000000
  569. [M] eclic_int24_handler - non-vector (level 2) run 200 times done!
  570. [M] eclic_int25_handler (level 1), run counter: 200, msubm 0x8940, mcause 0xb81f0019, mintstatus 0x3f000000
  571. [M] eclic_int25_handler - non-vector (level 1) run 200 times done!
  572. [M] eclic_msip_handler (level 0) triggered IRQ 26 (level 2, trigger counter: 200), msubm 0x8140, mcause 0xb81f0003, mintstatus 0x3f000000
  573. [M] eclic_int26_handler (level 2) triggered IRQ 27 (level 3, trigger counter: 200), msubm 0x140, mcause 0xb83f001a, mintstatus 0x5f000000
  574. [M] eclic_int27_handler (level 3) triggered IRQ 28 (level 2, trigger counter: 200), msubm 0x140, mcause 0xb85f001b, mintstatus 0x7f000000
  575. [M] eclic_int27_handler - vector (level 3) run 200 times done!
  576. [M] eclic_int26_handler - vector (level 2) run 200 times done!
  577. [M] eclic_int28_handler (level 2) triggered IRQ 29 (level 4, trigger counter: 200), msubm 0x140, mcause 0xb83f001c, mintstatus 0x5f000000
  578. [M] eclic_int29_handler (level 4), run counter: 200, msubm 0x140, mcause 0xb85f001d, mintstatus 0x9f000000
  579. [M] eclic_int29_handler - vector (level 4) run 200 times done!
  580. [M] eclic_int28_handler - vector (level 2) run 200 times done!
  581. [M] eclic_msip_handler - vector (level 1) run 200 times done!
  582. [M] eclic_mtip_handler - non-vector (level 0) run 200 times done!
  583. [S] eclic_stip_handler (level 1) triggered IRQ 30 (level 3, trigger counter: 100), ssubm 0xc40, scause 0x98000005, sintstatus 0x3f00
  584. [S] eclic_int30_handler (level 3) triggered IRQ 31 (level 3, trigger counter: 100), ssubm 0x19140, scause 0x983f001e, sintstatus 0x7f00
  585. [S] eclic_int30_handler - non-vector (level 3) run 100 times done!
  586. [S] eclic_int31_handler (level 3) triggered IRQ 32 (level 2, trigger counter: 100), ssubm 0x19140, scause 0x983f001f, sintstatus 0x7f00
  587. [S] eclic_int31_handler - non-vector (level 3) run 100 times done!
  588. [S] eclic_int32_handler (level 2) triggered IRQ 32 (level 2, trigger counter: 100), ssubm 0x19140, scause 0x983f0020, sintstatus 0x5f00
  589. [S] eclic_int33_handler (level 4) triggered IRQ 34 (level 3, trigger counter: 100), ssubm 0x20140, scause 0x985f0021, sintstatus 0x9f00
  590. [S] eclic_int33_handler - non-vector (level 4) run 100 times done!
  591. [S] eclic_int34_handler (level 3) triggered IRQ 35 (level 2, trigger counter: 100), ssubm 0x20140, scause 0x985f0022, sintstatus 0x7f00
  592. [S] eclic_int34_handler - non-vector (level 3) run 100 times done!
  593. [S] eclic_int32_handler - non-vector (level 2) run 100 times done!
  594. [S] eclic_int35_handler (level 2), run counter: 100, ssubm 0x18140, scause 0x983f0023, sintstatus 0x5f00
  595. [S] eclic_int35_handler - non-vector (level 2) run 100 times done!
  596. [S] eclic_ssip_handler (level 1) triggered IRQ 36 (level 3, trigger counter: 100), ssubm 0x18140, scause 0x983f0001, sintstatus 0x7f00
  597. [S] eclic_ssip_handler - vector (level 3) run 100 times done!
  598. [S] eclic_int36_handler (level 3) triggered IRQ 37 (level 1, trigger counter: 100), ssubm 0x18140, scause 0x983f0024, sintstatus 0x7f00
  599. [S] eclic_int36_handler - vector (level 3) run 100 times done!
  600. [S] eclic_stip_handler - non-vector (level 1) run 100 times done!
  601. [S] eclic_int37_handler (level 1) triggered IRQ 38 (level 4, trigger counter: 100), ssubm 0x40, scause 0x98000025, sintstatus 0x3f00
  602. [S] eclic_int38_handler (level 4) triggered IRQ 39 (level 2, trigger counter: 100), ssubm 0x140, scause 0x983f0026, sintstatus 0x9f00
  603. [S] eclic_int38_handler - vector (level 4) run 100 times done!
  604. [S] eclic_int39_handler (level 2), run counter: 100, ssubm 0x140, scause 0x983f0027, sintstatus 0x5f00
  605. [S] eclic_int39_handler - vector (level 2) run 100 times done!
  606. [S] eclic_int37_handler - vector (level 1) run 100 times done!
  607. [S] PASS: All smode_eclic_int_cnt and mmode_eclic_int_cnt values are equal and greater than 100
  608. .. _design_app_demo_plic:
  609. demo_plic
  610. ~~~~~~~~~
  611. This `demo_plic application`_ is used to demonstrate how to use
  612. the PLIC API and Interrupt is working in CLINT/PLIC interrupt mode.
  613. .. note::
  614. This demo only works on evalsoc, and require PLIC module present.
  615. * This demo will show how to use plic external interrupt
  616. * This demo use uart rx interrupt
  617. * **NOTE**: not able to working in qemu
  618. **How to run this application:**
  619. .. code-block:: shell
  620. # Assume that you can set up the Tools and Nuclei SDK environment
  621. # cd to the demo_plic directory
  622. cd application/baremetal/demo_plic
  623. # For this case, if your bit has PLIC, and you are not using sdk generated by nuclei_gen
  624. # XLCFG_PLIC=1 will define CFG_HAS_PLIC macro
  625. make SOC=evalsoc XLCFG_PLIC=1 clean
  626. # Build and upload the application
  627. make SOC=evalsoc XLCFG_PLIC=1 upload
  628. .. code-block:: console
  629. Nuclei SDK Build Time: Jul 23 2024, 17:49:27
  630. Download Mode: ILM
  631. CPU Frequency 50000000 Hz
  632. CPU HartID: 0
  633. You can press any key now to trigger uart receive interrupt
  634. Enter uart0 interrupt, you just typed: 1
  635. Enter uart0 interrupt, you just typed: 2
  636. .. _design_app_demo_dsp:
  637. demo_dsp
  638. ~~~~~~~~
  639. This `demo_dsp application`_ is used to demonstrate how to NMSIS-DSP API.
  640. * Mainly show how we can use NMSIS DSP library and header files.
  641. * It mainly demo the ``riscv_conv_xx`` functions and its reference functions
  642. * By default, the application will use prebuilt NMSIS-DSP library match riscv isa arch
  643. defined by :ref:`develop_buildsystem_var_core` and :ref:`develop_buildsystem_var_archext`
  644. * If your selected **CORE** and **ARCH_EXT** don't have a prebuilt NMSIS DSP library,
  645. you can use :ref:`develop_buildsystem_var_nmsis_lib_arch` make variable to select
  646. another most suitable prebuilt NMSIS DSP or NN library.
  647. eg. If you build with ``make CORE=n900f ARCH_EXT=_zca_zcb_zcf_zcmp_zcmt_xxldsp clean all``,
  648. you will get a link error like this ``riscv64-unknown-elf/bin/ld: cannot find -lnmsis_dsp_rv32imaf_zca_zcb_zcf_zcmp_zcmt_xxldsp: No such file or directory``, this is
  649. caused by no prebuilt libraries are built with ``Zc*`` extension. But you can build it
  650. by modify this example's Makefile by adding ``NMSIS_LIB_ARCH := rv32imafc_xxldsp`` newline.
  651. Take care ``Zc*`` is not fully compatiable with ``C`` extension, especially when ``D`` extension
  652. present, see latest RISC-V ISA manual ``riscv-unprivileged.pdf`` which can found in
  653. https://github.com/riscv/riscv-isa-manual/releases .
  654. And if you want to modify and build your own NMSIS DSP and NN library and see other
  655. DSP and NN examples and test cases, you can checkout the following links:
  656. - https://github.com/Nuclei-Software/NMSIS
  657. - https://doc.nucleisys.com/nmsis/dsp/index.html
  658. - https://doc.nucleisys.com/nmsis/nn/index.html
  659. .. note::
  660. * For other Nuclei Processor Core based SoC, please check whether it has DSP
  661. feature enabled to decide which kind of **NMSIS-DSP** library to use.
  662. * Even our NMSIS-DSP library with DSP disabled are also optimized, so it can
  663. also provide good performance in some functions.
  664. **How to run this application:**
  665. .. code-block:: shell
  666. # Assume that you can set up the Tools and Nuclei SDK environment
  667. # cd to the demo_dsp directory
  668. cd application/baremetal/demo_dsp
  669. # Clean the application first
  670. make SOC=gd32vf103 clean
  671. # Build and upload the application
  672. make SOC=gd32vf103 upload
  673. **Expected output as below:**
  674. .. code-block:: console
  675. Nuclei SDK Build Time: Jun 18 2020, 17:43:31
  676. Download Mode: FLASHXIP
  677. CPU Frequency 108270000 Hz
  678. CSV, riscv_conv_q31, 1225418
  679. CSV, ref_conv_q31, 2666240
  680. SUCCESS, riscv_conv_q31
  681. CSV, riscv_conv_q15, 289940
  682. CSV, ref_conv_q15, 311158
  683. SUCCESS, riscv_conv_q15
  684. CSV, riscv_conv_q7, 463
  685. CSV, ref_conv_q7, 846
  686. SUCCESS, riscv_conv_q7
  687. CSV, riscv_conv_fast_q15, 106293
  688. CSV, ref_conv_fast_q15, 247938
  689. SUCCESS, riscv_conv_fast_q15
  690. CSV, riscv_conv_fast_q31, 490539
  691. CSV, ref_conv_fast_q31, 2215917
  692. SUCCESS, riscv_conv_fast_q31
  693. CSV, riscv_conv_opt_q15, 217250
  694. CSV, ref_conv_opt_q15, 311162
  695. SUCCESS, riscv_conv_opt_q15
  696. CSV, riscv_conv_opt_q7, 714
  697. CSV, ref_conv_opt_q7, 842
  698. SUCCESS, riscv_conv_opt_q7
  699. CSV, riscv_conv_fast_opt_q15, 137252
  700. CSV, ref_conv_fast_opt_q15, 249958
  701. SUCCESS, riscv_conv_fast_opt_q15
  702. all test are passed. Well done!
  703. .. _design_app_lowpower:
  704. lowpower
  705. ~~~~~~~~
  706. This `lowpower application`_ is used to demonstrate how to use low-power feature of RISC-V
  707. processor.
  708. Timer interrupt is setup before enter to wfi mode, and global interrupt will be disabled,
  709. so interrupt handler will not be entered, and will directly resume to next pc of wfi.
  710. **How to run this application:**
  711. .. code-block:: shell
  712. # Assume that you can set up the Tools and Nuclei SDK environment
  713. # Assume your processor has enabled low-power feature
  714. # cd to the low-power directory
  715. cd application/baremetal/lowpower
  716. # Clean the application first
  717. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300 clean
  718. # Build and upload the application
  719. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300 upload
  720. **Expected output as below:**
  721. .. code-block:: console
  722. Nuclei SDK Build Time: Jun 9 2022, 11:23:14
  723. Download Mode: ILM
  724. CPU Frequency 15996354 Hz
  725. CSV, WFI Start/End, 178264/178289
  726. CSV, WFI Cost, 25
  727. .. _design_app_smphello:
  728. smphello
  729. ~~~~~~~~
  730. This `smphello application`_ is used to demonstrate how to use baremetal SMP feature.
  731. This demo requires the SMP cores share the same RAM and ROM, for example, in current
  732. evalsoc system, ilm/dlm are private resource for cpu, only the DDR/SRAM memory are shared
  733. resource for all the cpu.
  734. And `RVA` atomic extension is required to run this application, this extension is used
  735. to do spinlock in this example.
  736. .. note::
  737. * It doesn't work with gd32vf103 processor.
  738. * **MUST** Need to enable I/D Cache in <Device.h> if I/D Cache present in CPU.
  739. * It needs at least a 2-Core SMP CPU
  740. * Each hart must wait until all the harts stop printing(or just stay in ``while (1);`` after its job has finished),
  741. because the ``_postmain_fini`` will print some dummy '\0', which has no lock-protecting to UART causing ``corrupted-printing``
  742. * ``spinlock lock`` should be ``volatile``, or else the compiler maybe optimize out the ``spinlock_unlock`` if
  743. more than one pair of ``spinlock_lock`` ``spinlock_unlock`` used in one function/branch, causing the lock unreleased
  744. **How to run this application:**
  745. .. code-block:: shell
  746. # Assume that you can set up the Tools and Nuclei SDK environment
  747. # Use Nuclei UX900 SMP 2 Core RISC-V processor as example
  748. # application needs to run in ddr memory not in ilm memory
  749. # cd to the smphello directory
  750. cd application/baremetal/smphello
  751. # Clean the application first
  752. make SOC=evalsoc BOARD=nuclei_fpga_eval SMP=2 CORE=ux900 clean
  753. # Build and upload the application
  754. make SOC=evalsoc BOARD=nuclei_fpga_eval SMP=2 CORE=ux900 upload
  755. **Expected output as below:**
  756. .. code-block:: console
  757. Nuclei SDK Build Time: May 30 2022, 15:38:00
  758. Download Mode: SRAM
  759. CPU Frequency 15998648 Hz
  760. Hello world from hart 0
  761. Hello world from hart 1
  762. All harts boot successfully!
  763. .. _design_app_demo_nice:
  764. demo_nice
  765. ~~~~~~~~~
  766. .. note::
  767. * It doesn't work with gd32vf103 processor.
  768. * Need nice feature enabled, and Nuclei NICE hardware demo integrated such as evalsoc
  769. This `demo_nice application`_ is used to demonstrate how to Nuclei NICE feature.
  770. **NICE** is short for Nuclei Instruction Co-unit Extension, which is used to
  771. support extensive customization and specialization.
  772. **NICE** allows customers to create user-defined instructions, enabling the
  773. integrations of custom hardware co-units that improve domain-specific
  774. performance while reducing power consumption.
  775. For more about **NICE** feature, please click `Nuclei User Extended Introduction`_.
  776. * Mainly show how to use NICE intrinsic function with compiler.
  777. * It only works with Nuclei RISC-V Processor with the hardware NICE demo integrated.
  778. **How to run this application:**
  779. .. code-block:: shell
  780. # Assume that you can set up the Tools and Nuclei SDK environment
  781. # Use Nuclei UX900 RISC-V processor as example, hardware NICE demo integrated
  782. # cd to the demo_dsp directory
  783. cd application/baremetal/demo_nice
  784. # Clean the application first
  785. make SOC=evalsoc BOARD=nuclei_fpga_eval CORE=ux900 clean
  786. # Build and upload the application
  787. make SOC=evalsoc BOARD=nuclei_fpga_eval CORE=ux900 upload
  788. **Expected output as below:**
  789. .. code-block:: console
  790. Nuclei SDK Build Time: May 28 2024, 13:32:18
  791. Download Mode: ILM
  792. CPU Frequency 49999631 Hz
  793. CPU HartID: 0
  794. Nuclei Nice Acceleration Demonstration
  795. Warning: This demo required CPU to implement Nuclei provided NICE Demo instructions.
  796. Otherwise this example will trap to cpu core exception!
  797. 1. Print input matrix array
  798. the element of array is :
  799. 10 30 90
  800. 20 40 80
  801. 30 90 120
  802. 2. Do reference matrix column sum and row sum
  803. 3. Do nice matrix column sum and row sum
  804. 4. Compare reference and nice result
  805. 5) Reference result:
  806. the sum of each row is :
  807. 130 140 240
  808. the sum of each col is :
  809. 60 160 290
  810. 6) Nice result:
  811. the sum of each row is :
  812. 130 140 240
  813. the sum of each col is :
  814. 60 160 290
  815. 7) Compare reference vs nice: PASS
  816. 8. Performance summary
  817. normal:
  818. instret: 502, cycle: 502
  819. nice :
  820. instret: 177, cycle: 177
  821. .. _design_app_demo_vnice:
  822. demo_vnice
  823. ~~~~~~~~~~
  824. .. note::
  825. * It only works with Nuclei EvalSoC with Vector NICE demo instructions enabled.
  826. * Need vector nice feature enabled, and Nuclei NICE hardware demo integrated such as evalsoc
  827. This `demo_vnice application`_ is used to demonstrate how to Nuclei Vector NICE feature.
  828. **NICE** is short for Nuclei Instruction Co-unit Extension, which is used to
  829. support extensive customization and specialization.
  830. **How to run this application:**
  831. .. code-block:: shell
  832. # Assume that you can set up the Tools and Nuclei SDK environment
  833. # Use Nuclei UX900 + Vector Nice RISC-V processor as example, hardware NICE demo integrated
  834. # cd to the demo_dsp directory
  835. cd application/baremetal/demo_vnice
  836. # Clean the application first
  837. make SOC=evalsoc clean
  838. # Build and upload the application
  839. make SOC=evalsoc upload
  840. **Expected output as below:**
  841. .. code-block:: console
  842. Nuclei SDK Build Time: May 28 2024, 13:31:08
  843. Download Mode: ILM
  844. CPU Frequency 1000000716 Hz
  845. CPU HartID: 0
  846. 1. Set array_normal_in1 array_normal_in1 array_vnice_in1 array_vnice_in2
  847. 2. Do reference vector complex mul, store, load
  848. 3. Do vector nice complex mul, store, load
  849. 4. Compare reference and vnice result
  850. PASS
  851. 5. Performance summary
  852. normal:
  853. instret: 22546, cycle: 22546
  854. vnice :
  855. instret: 1010, cycle: 1010
  856. .. _design_app_coremark:
  857. coremark
  858. ~~~~~~~~
  859. This `coremark benchmark application`_ is used to run EEMBC CoreMark Software.
  860. EEMBC CoreMark Software is a product of EEMBC and is provided under the terms of the
  861. CoreMark License that is distributed with the official EEMBC COREMARK Software release.
  862. If you received this EEMBC CoreMark Software without the accompanying CoreMark License,
  863. you must discontinue use and download the official release from www.coremark.org.
  864. In Nuclei SDK, we provided code and Makefile for this ``coremark`` application.
  865. You can also optimize the ``COMMON_FLAGS`` defined in coremark application Makefile
  866. to get different score number.
  867. * By default, this application runs for 800 iterations, you can also change this in Makefile.
  868. e.g. Change this ``-DITERATIONS=800`` to value such as ``-DITERATIONS=5000``
  869. * macro **PERFORMANCE_RUN=1** is defined
  870. * **STDCLIB ?= newlib_small** is added in its Makefile to enable float value print
  871. * For different Nuclei CPU series, the benchmark options are different, currently
  872. you can pass ``CPU_SERIES=900`` to select benchmark options for 900 series, otherwise
  873. the benchmark options for 200/300/600/900 will be selected which is also the default value.
  874. .. note::
  875. * Since for each SoC platforms, the CPU frequency is different, so user need to change
  876. the ``ITERATIONS`` defined in Makefile to proper value to let the coremark run at least
  877. 10 seconds
  878. * For example, for the ``gd32vf103`` based boards supported in Nuclei SDK, we suggest
  879. to change ``-DITERATIONS=800`` to ``-DITERATIONS=5000``
  880. **How to run this application:**
  881. .. code-block:: shell
  882. # Assume that you can set up the Tools and Nuclei SDK environment
  883. # cd to the coremark directory
  884. cd application/baremetal/benchmark/coremark
  885. # Clean the application first
  886. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300fd ARCH_EXT=_zba_zbb_zbc_zbs_zicond clean
  887. # Build and upload the application
  888. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300fd ARCH_EXT=_zba_zbb_zbc_zbs_zicond upload
  889. **Expected output as below:**
  890. .. code-block:: console
  891. Nuclei SDK Build Time: May 6 2025, 16:33:08
  892. Download Mode: ILM
  893. CPU Frequency 16003563 Hz
  894. CPU HartID: 0
  895. Start to run coremark for 800 iterations
  896. 2K performance run parameters for coremark.
  897. CoreMark Size : 666
  898. Total ticks : 207671961
  899. Total time (secs): 12.976789
  900. Iterations/Sec : 61.648533
  901. Iterations : 800
  902. Compiler version : GCC14.2.1 20240816
  903. Compiler flags : -Ofast -fno-code-hoisting -fno-common -finline-functions -falign-functions=6 -falign-jumps=6 -falign-loops=4 -finline-limit=2001
  904. Memory location : STACK
  905. seedcrc : 0xe9f5
  906. [0]crclist : 0xe714
  907. [0]crcmatrix : 0x1fd7
  908. [0]crcstate : 0x8e3a
  909. [0]crcfinal : 0xcc42
  910. Correct operation validated. See readme.txt for run and reporting rules.
  911. CoreMark 1.0 : 61.648533 / GCC14.2.1 20240816 -Ofast -fno-code-hoisting -fno-common -finline-functions -falign-functions=6 -falign-jumps=6 -faligns
  912. (Iterations is: 800
  913. (total_ticks is: 207671961
  914. (*) Assume the core running at 1 MHz
  915. So the CoreMark/MHz can be calculated by:
  916. (Iterations*1000000/total_ticks) = 3.852229 CoreMark/MHz
  917. CSV, Benchmark, Iterations, Cycles, CoreMark/MHz
  918. CSV, CoreMark, 800, 207671961, 3.852
  919. IPC = Instret/Cycle = 184031355/207671961 = 0.886
  920. .. _design_app_dhrystone:
  921. dhrystone
  922. ~~~~~~~~~
  923. This `dhrystone benchmark application`_ is used to run DHRYSTONE Benchmark Software, whose version is v2.1.
  924. The Dhrystone benchmark program has become a popular benchmark for CPU/compiler performance measurement,
  925. in particular in the area of minicomputers, workstations, PC's and microprocesors.
  926. * It apparently satisfies a need for an easy-to-use integer benchmark;
  927. * it gives a first performance indication which is more meaningful than MIPS numbers which,
  928. in their literal meaning (million instructions per second), cannot be used across different
  929. instruction sets (e.g. RISC vs. CISC).
  930. * With the increasing use of the benchmark, it seems necessary to reconsider the benchmark and
  931. to check whether it can still fulfill this function.
  932. In Nuclei SDK, we provided code and Makefile for this ``dhrystone`` application.
  933. You can also optimize the ``COMMON_FLAGS`` defined in dhrystone application Makefile
  934. to get different score number.
  935. * **STDCLIB ?= newlib_small** is added in its Makefile to enable float value print
  936. * You can change ``Number_Of_Runs`` in ``dhry_1.c`` to increate or decrease
  937. number of iterations
  938. **How to run this application:**
  939. .. code-block:: shell
  940. # Assume that you can set up the Tools and Nuclei SDK environment
  941. # cd to the dhrystone directory
  942. cd application/baremetal/benchmark/dhrystone
  943. # Clean the application first
  944. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300fd ARCH_EXT=_zba_zbb_zbc_zbs clean
  945. # Build and upload the application
  946. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300fd ARCH_EXT=_zba_zbb_zbc_zbs upload
  947. **Expected output as below:**
  948. .. code-block:: console
  949. Nuclei SDK Build Time: May 6 2025, 16:29:34
  950. Download Mode: ILM
  951. CPU Frequency 16004874 Hz
  952. CPU HartID: 0
  953. Dhrystone Benchmark, Version 2.1 (Language: C)
  954. Program compiled without 'register' attribute
  955. Please give the number of runs through the benchmark:
  956. Execution starts, 500000 runs through Dhrystone
  957. Execution ends
  958. Final values of the variables used in the benchmark:
  959. Int_Glob: 5
  960. should be: 5
  961. Bool_Glob: 1
  962. should be: 1
  963. Ch_1_Glob: A
  964. should be: A
  965. Ch_2_Glob: B
  966. should be: B
  967. Arr_1_Glob[8]: 7
  968. should be: 7
  969. Arr_2_Glob[8][7]: 500010
  970. should be: Number_Of_Runs + 10
  971. Ptr_Glob->
  972. Ptr_Comp: -1879032528
  973. should be: (implementation-dependent)
  974. Discr: 0
  975. should be: 0
  976. Enum_Comp: 2
  977. should be: 2
  978. Int_Comp: 17
  979. should be: 17
  980. Str_Comp: DHRYSTONE PROGRAM, SOME STRING
  981. should be: DHRYSTONE PROGRAM, SOME STRING
  982. Next_Ptr_Glob->
  983. Ptr_Comp: -1879032528
  984. should be: (implementation-dependent), same as above
  985. Discr: 0
  986. should be: 0
  987. Enum_Comp: 1
  988. should be: 1
  989. Int_Comp: 18
  990. should be: 18
  991. Str_Comp: DHRYSTONE PROGRAM, SOME STRING
  992. should be: DHRYSTONE PROGRAM, SOME STRING
  993. Int_1_Loc: 5
  994. should be: 5
  995. Int_2_Loc: 13
  996. should be: 13
  997. Int_3_Loc: 7
  998. should be: 7
  999. Enum_Loc: 1
  1000. should be: 1
  1001. Str_1_Loc: DHRYSTONE PROGRAM, 1'ST STRING
  1002. should be: DHRYSTONE PROGRAM, 1'ST STRING
  1003. Str_2_Loc: DHRYSTONE PROGRAM, 2'ND STRING
  1004. should be: DHRYSTONE PROGRAM, 2'ND STRING
  1005. (*) User_Cycle for total run through Dhrystone with loops 500000:
  1006. 151000097
  1007. So the DMIPS/MHz can be calculated by:
  1008. 1000000/(User_Cycle/Number_Of_Runs)/1757 = 1.884608 DMIPS/MHz
  1009. CSV, Benchmark, Iterations, Cycles, DMIPS/MHz
  1010. CSV, Dhrystone, 500000, 151000097, 1.884
  1011. IPC = Instret/Cycle = 145000036/151000097 = 0.960
  1012. .. _design_app_dhrystone_v2.2:
  1013. dhrystone_v2.2
  1014. ~~~~~~~~~~~~~~
  1015. This `dhrystone_v2.2 benchmark application`_ is used to run DHRYSTONE Benchmark Software, whose version is v2.2.
  1016. In Nuclei SDK, we provided code and Makefile for this ``dhrystone`` application.
  1017. You can also optimize the ``COMMON_FLAGS`` defined in dhrystone application Makefile
  1018. to get different score number.
  1019. * **STDCLIB ?= newlib_small** is added in its Makefile to enable float value print
  1020. * ``Number_Of_Runs`` will increase itself if running time is too small
  1021. **How to run this application:**
  1022. .. code-block:: shell
  1023. # Assume that you can set up the Tools and Nuclei SDK environment
  1024. # cd to the dhrystone_v2.2 directory
  1025. cd application/baremetal/benchmark/dhrystone_v2.2
  1026. # Clean the application first
  1027. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300fd ARCH_EXT=_zba_zbb_zbc_zbs clean
  1028. # Build and upload the application
  1029. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300fd ARCH_EXT=_zba_zbb_zbc_zbs upload
  1030. **Expected output as below:**
  1031. .. code-block:: console
  1032. Nuclei SDK Build Time: May 6 2025, 16:22:34
  1033. Download Mode: ILM
  1034. CPU Frequency 16006184 Hz
  1035. CPU HartID: 0
  1036. Dhrystone Benchmark, Version C, Version 2.2
  1037. Program compiled without 'register' attribute
  1038. Using time(), HZ=1
  1039. Trying 50000 runs through Dhrystone:
  1040. Measured time too small to obtain meaningful results
  1041. Trying 500000 runs through Dhrystone:
  1042. Final values of the variables used in the benchmark:
  1043. Int_Glob: 5
  1044. should be: 5
  1045. Bool_Glob: 1
  1046. should be: 1
  1047. Ch_1_Glob: A
  1048. should be: A
  1049. Ch_2_Glob: B
  1050. should be: B
  1051. Arr_1_Glob[8]: 7
  1052. should be: 7
  1053. Arr_2_Glob[8][7]: 550010
  1054. should be: Number_Of_Runs + 10
  1055. Ptr_Glob->
  1056. Ptr_Comp: -1879032368
  1057. should be: (implementation-dependent)
  1058. Discr: 0
  1059. should be: 0
  1060. Enum_Comp: 2
  1061. should be: 2
  1062. Int_Comp: 17
  1063. should be: 17
  1064. Str_Comp: DHRYSTONE PROGRAM, SOME STRING
  1065. should be: DHRYSTONE PROGRAM, SOME STRING
  1066. Next_Ptr_Glob->
  1067. Ptr_Comp: -1879032368
  1068. should be: (implementation-dependent), same as above
  1069. Discr: 0
  1070. should be: 0
  1071. Enum_Comp: 1
  1072. should be: 1
  1073. Int_Comp: 18
  1074. should be: 18
  1075. Str_Comp: DHRYSTONE PROGRAM, SOME STRING
  1076. should be: DHRYSTONE PROGRAM, SOME STRING
  1077. Int_1_Loc: 5
  1078. should be: 5
  1079. Int_2_Loc: 13
  1080. should be: 13
  1081. Int_3_Loc: 7
  1082. should be: 7
  1083. Enum_Loc: 1
  1084. should be: 1
  1085. Str_1_Loc: DHRYSTONE PROGRAM, 1'ST STRING
  1086. should be: DHRYSTONE PROGRAM, 1'ST STRING
  1087. Str_2_Loc: DHRYSTONE PROGRAM, 2'ND STRING
  1088. should be: DHRYSTONE PROGRAM, 2'ND STRING
  1089. Microseconds for one run through Dhrystone: 14.0
  1090. Dhrystones per Second: 71429
  1091. (*) User_Cycle for total run through Dhrystone with loops 500000:
  1092. 128000082
  1093. So the DMIPS/MHz can be calculated by:
  1094. 1000000/(User_Cycle/Number_Of_Runs)/1757 = 2.223248 DMIPS/MHz
  1095. CSV, Benchmark, Iterations, Cycles, DMIPS/MHz
  1096. CSV, Dhrystone_v2.2, 500000, 128000082, 2.223
  1097. IPC = Instret/Cycle = 117500053/128000082 = 0.917
  1098. .. _design_app_whetstone:
  1099. whetstone
  1100. ~~~~~~~~~
  1101. This `whetstone benchmark application`_ is used to run C/C++ Whetstone Benchmark Software
  1102. (Single or Double Precision), whose version is roy@roylongbottom.org.uk, 6 November 1996.
  1103. The Fortran Whetstone programs were the first general purpose benchmarks that set industry
  1104. standards of computer system performance. Whetstone programs also addressed the question
  1105. of the efficiency of different programming languages, an important issue not covered by
  1106. more contemporary standard benchmarks.
  1107. In Nuclei SDK, we provided code and Makefile for this ``whetstone`` application.
  1108. You can also optimize the ``COMMON_FLAGS`` defined in whetstone application Makefile
  1109. to get different score number.
  1110. * **STDCLIB ?= newlib_small** is added in its Makefile to enable float value print
  1111. * Extra **LDFLAGS := -lm** is added in its Makefile to include the math library
  1112. **How to run this application:**
  1113. .. code-block:: shell
  1114. # Assume that you can set up the Tools and Nuclei SDK environment
  1115. # cd to the whetstone directory
  1116. cd application/baremetal/benchmark/whetstone
  1117. # Clean the application first
  1118. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300fd clean
  1119. # Build and upload the application
  1120. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300fd upload
  1121. **Expected output as below:**
  1122. .. code-block:: console
  1123. Nuclei SDK Build Time: May 6 2025, 16:31:23
  1124. Download Mode: ILM
  1125. CPU Frequency 15984885 Hz
  1126. CPU HartID: 0
  1127. ##########################################
  1128. Double Precision C Whetstone Benchmark Opt 3 32 Bit
  1129. Calibrate
  1130. 0.37 Seconds 1 Passes (x 100)
  1131. Use 8 passes (x 100)
  1132. Double Precision C/C++ Whetstone Benchmark
  1133. Loop content Result MFLOPS MOPS Seconds
  1134. N1 floating point -1.12441415430187974 12.486 0.012
  1135. N2 floating point -1.12239951147853168 16.874 0.064
  1136. N3 if then else 1.00000000000000000 0.000 0.000
  1137. N4 fixed point 12.00000000000000000 120.022 0.021
  1138. N5 sin,cos etc. 0.49907428465337039 0.402 1.654
  1139. N6 floating point 0.99999988495142078 9.600 0.449
  1140. N7 assignments 3.00000000000000000 71.982 0.021
  1141. N8 exp,sqrt etc. 0.75095530233199781 0.423 0.704
  1142. MWIPS 27.355 2.925
  1143. MWIPS/MHz 1.711 2.925
  1144. CSV, Benchmark, MWIPS/MHz
  1145. CSV, Whetstone, 1.711
  1146. IPC = Instret/Cycle = 35858111/49362436 = 0.726
  1147. .. _design_app_whetstone_v1.2:
  1148. whetstone_v1.2
  1149. ~~~~~~~~~~~~~~
  1150. This `whetstone_v1.2 benchmark application`_ is used to run C Converted Whetstone
  1151. Single or Double Precision Benchmark Version 1.2 22 March 1998, which has different
  1152. algorithm to this version `whetstone benchmark application`_ (they are incomparable).
  1153. In Nuclei SDK, we provided code and Makefile for this ``whetstone_v1.2`` application.
  1154. You can also optimize the ``COMMON_FLAGS`` defined in whetstone application Makefile
  1155. to get different score number.
  1156. * **STDCLIB ?= newlib_small** is added in its Makefile to enable float value print
  1157. * Extra **LDFLAGS := -lm** is added in its Makefile to include the math library
  1158. **How to run this application:**
  1159. .. code-block:: shell
  1160. # Assume that you can set up the Tools and Nuclei SDK environment
  1161. # cd to the whetstone_v1.2 directory
  1162. cd application/baremetal/benchmark/whetstone_v1.2
  1163. # Clean the application first
  1164. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300fd clean
  1165. # Build and upload the application
  1166. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300fd upload
  1167. **Expected output as below:**
  1168. .. code-block:: console
  1169. Nuclei SDK Build Time: May 6 2025, 16:11:48
  1170. Download Mode: ILM
  1171. CPU Frequency 15984885 Hz
  1172. CPU HartID: 0
  1173. ##########################################
  1174. Single Precision C Whetstone Benchmark Version 1.2 22 March 1998
  1175. Nuclei SDK Build Time: May 6 2025, 16:13:56
  1176. Download Mode: ILM
  1177. CPU Frequency 16004874 Hz
  1178. CPU HartID: 0
  1179. ##########################################
  1180. Double Precision C Whetstone Benchmark Version 1.2 22 March 1998
  1181. Loops: 50000, Iterations: 1, Duration: 70 sec.
  1182. C Converted Double Precision Whetstones: 71.4 MIPS
  1183. CSV, Benchmark, MWIPS/MHz
  1184. CSV, Whetstone_v1.2, 4.462
  1185. IPC = Instret/Cycle = 704074177/1133874283 = 0.620
  1186. .. _design_app_demo_smode_eclic:
  1187. demo_smode_eclic
  1188. ~~~~~~~~~~~~~~~~
  1189. This `demo_smode_eclic application`_ is used to demostrate how to use
  1190. the ECLIC API and Interrupt in supervisor mode with TEE.
  1191. .. note::
  1192. * It doesn't work with gd32vf103 processor.
  1193. * It needs Nuclei CPU configured with TEE feature and S-Mode ECLIC
  1194. * In this application's Makefile, we provided comments in Makefile about optimization
  1195. for code size, please refer to chapter :ref:`design_app_demo_eclic` for details.
  1196. * Need to enable TEE in <Device.h> if TEE present in CPU.
  1197. * The timer interrupt and timer software interrupt are used
  1198. * The timer interrupt is registered as non-vector interrupt
  1199. * The timer software interrupt is registered as vector interrupt,
  1200. and we enable its preemptive feature by using ``SAVE_IRQ_CSR_CONTEXT_S``
  1201. and ``RESTORE_IRQ_CSR_CONTEXT_S`` in timer software interrupt handler
  1202. * The timer interrupt is triggered periodically
  1203. * The timer software interrupt is triggered in timer interrupt handler using
  1204. ``SysTimer_SetHartSWIRQ`` function
  1205. * Interrupts occur in supervisor mode to which it drops from machine mode, and you can
  1206. observe the difference from :ref:`design_app_demo_eclic` by console output
  1207. * In the application code, there is a macro called ``SWIRQ_INTLEVEL_HIGHER`` to
  1208. control the timer software interrupt working feature:
  1209. - If **SWIRQ_INTLEVEL_HIGHER=1**, the timer software interrupt level is higher than
  1210. timer interrupt level, so when timer software interrupt is triggered, then timer
  1211. software interrupt will be processed immediately, and timer interrupt will be preempted
  1212. by timer software interrupt.
  1213. - If **SWIRQ_INTLEVEL_HIGHER=0**, the timer software interrupt level is lower than
  1214. timer interrupt level, so when timer software interrupt is triggered, then timer
  1215. software interrupt will be processed after timer interrupt, and timer interrupt will
  1216. not be preempted by timer software interrupt.
  1217. **How to run this application:**
  1218. .. code-block:: shell
  1219. # Assume that you can set up the Tools and Nuclei SDK environment
  1220. # cd to the demo_smode_eclic directory
  1221. cd application/baremetal/demo_smode_eclic
  1222. # MUST: Your CPU configuration must has TEE configured
  1223. # Since Nuclei SDK 0.7.0, if you are sure CFG_HAS_TEE is not defined in cpufeature.h, but you have TEE
  1224. # you can pass extra make variable XLCFG_TEE=1 during make command to tell sdk
  1225. # the TEE present, it will define CFG_HAS_TEE
  1226. # Change macro SWIRQ_INTLEVEL_HIGHER value in demo_smode_eclic.c
  1227. # to see different working mode of this demo
  1228. # Clean the application first
  1229. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300 clean
  1230. # Build and upload the application
  1231. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300 upload
  1232. **Expected output(SWIRQ_INTLEVEL_HIGHER=1) as below:**
  1233. .. code-block:: console
  1234. Nuclei SDK Build Time: Aug 5 2022, 15:05:52
  1235. Download Mode: ILM
  1236. CPU Frequency 15989145 Hz
  1237. Current sp is 0x9000ffa0, so it is in Machine Mode!
  1238. Drop to S-Mode now
  1239. [IN S-MODE ENTRY POINT] Hello Supervisor Mode!!!
  1240. Current sp is 0x90000f40, so it is in Supervisor Mode!
  1241. Initialize timer and start timer interrupt periodically
  1242. Current sp is 0x90000d80, so it is in Supervisor Mode!
  1243. -------------------
  1244. [IN S-MODE TIMER INTERRUPT]timer interrupt hit 0 times
  1245. [IN S-MODE TIMER INTERRUPT]trigger software interrupt
  1246. [IN S-MODE TIMER INTERRUPT]software interrupt will run during timer interrupt
  1247. [IN S-MODE SOFTWARE INTERRUPT]software interrupt hit 0 times
  1248. Current sp is 0x90000d10, so it is in Supervisor Mode!
  1249. [IN S-MODE SOFTWARE INTERRUPT]software interrupt end
  1250. [IN S-MODE TIMER INTERRUPT]timer interrupt end
  1251. Current sp is 0x90000d80, so it is in Supervisor Mode!
  1252. -------------------
  1253. [IN S-MODE TIMER INTERRUPT]timer interrupt hit 1 times
  1254. [IN S-MODE TIMER INTERRUPT]trigger software interrupt
  1255. [IN S-MODE TIMER INTERRUPT]software interrupt will run during timer interrupt
  1256. [IN S-MODE SOFTWARE INTERRUPT]software interrupt hit 1 times
  1257. Current sp is 0x90000d10, so it is in Supervisor Mode!
  1258. [IN S-MODE SOFTWARE INTERRUPT]software interrupt end
  1259. [IN S-MODE TIMER INTERRUPT]timer interrupt end
  1260. Current sp is 0x90000d80, so it is in Supervisor Mode!
  1261. -------------------
  1262. [IN S-MODE TIMER INTERRUPT]timer interrupt hit 2 times
  1263. [IN S-MODE TIMER INTERRUPT]trigger software interrupt
  1264. [IN S-MODE TIMER INTERRUPT]software interrupt will run during timer interrupt
  1265. [IN S-MODE SOFTWARE INTERRUPT]software interrupt hit 2 times
  1266. Current sp is 0x90000d10, so it is in Supervisor Mode!
  1267. [IN S-MODE SOFTWARE INTERRUPT]software interrupt end
  1268. [IN S-MODE TIMER INTERRUPT]timer interrupt end
  1269. Current sp is 0x90000d80, so it is in Supervisor Mode!
  1270. -------------------
  1271. [IN S-MODE TIMER INTERRUPT]timer interrupt hit 3 times
  1272. [IN S-MODE TIMER INTERRUPT]trigger software interrupt
  1273. [IN S-MODE TIMER INTERRUPT]software interrupt will run during timer interrupt
  1274. [IN S-MODE SOFTWARE INTERRUPT]software interrupt hit 3 times
  1275. Current sp is 0x90000d10, so it is in Supervisor Mode!
  1276. [IN S-MODE SOFTWARE INTERRUPT]software interrupt end
  1277. [IN S-MODE TIMER INTERRUPT]timer interrupt end
  1278. **Expected output(SWIRQ_INTLEVEL_HIGHER=0) as below:**
  1279. .. code-block:: console
  1280. Nuclei SDK Build Time: Aug 5 2022, 15:09:46
  1281. Download Mode: ILM
  1282. CPU Frequency 15989145 Hz
  1283. Current sp is 0x9000ffa0, so it is in Machine Mode!
  1284. Drop to S-Mode now
  1285. [IN S-MODE ENTRY POINT] Hello Supervisor Mode!!!
  1286. Current sp is 0x90000f50, so it is in Supervisor Mode!
  1287. Initialize timer and start timer interrupt periodically
  1288. Current sp is 0x90000d90, so it is in Supervisor Mode!
  1289. -------------------
  1290. [IN S-MODE TIMER INTERRUPT]timer interrupt hit 0 times
  1291. [IN S-MODE TIMER INTERRUPT]trigger software interrupt
  1292. [IN S-MODE TIMER INTERRUPT]software interrupt will run when timer interrupt finished
  1293. [IN S-MODE TIMER INTERRUPT]timer interrupt end
  1294. [IN S-MODE SOFTWARE INTERRUPT]software interrupt hit 0 times
  1295. Current sp is 0x90000ee0, so it is in Supervisor Mode!
  1296. [IN S-MODE SOFTWARE INTERRUPT]software interrupt end
  1297. Current sp is 0x90000d90, so it is in Supervisor Mode!
  1298. -------------------
  1299. [IN S-MODE TIMER INTERRUPT]timer interrupt hit 1 times
  1300. [IN S-MODE TIMER INTERRUPT]trigger software interrupt
  1301. [IN S-MODE TIMER INTERRUPT]software interrupt will run when timer interrupt finished
  1302. [IN S-MODE TIMER INTERRUPT]timer interrupt end
  1303. [IN S-MODE SOFTWARE INTERRUPT]software interrupt hit 1 times
  1304. Current sp is 0x90000ee0, so it is in Supervisor Mode!
  1305. [IN S-MODE SOFTWARE INTERRUPT]software interrupt end
  1306. Current sp is 0x90000d90, so it is in Supervisor Mode!
  1307. -------------------
  1308. [IN S-MODE TIMER INTERRUPT]timer interrupt hit 2 times
  1309. [IN S-MODE TIMER INTERRUPT]trigger software interrupt
  1310. [IN S-MODE TIMER INTERRUPT]software interrupt will run when timer interrupt finished
  1311. [IN S-MODE TIMER INTERRUPT]timer interrupt end
  1312. [IN S-MODE SOFTWARE INTERRUPT]software interrupt hit 2 times
  1313. Current sp is 0x90000ee0, so it is in Supervisor Mode!
  1314. [IN S-MODE SOFTWARE INTERRUPT]software interrupt end
  1315. Current sp is 0x90000d90, so it is in Supervisor Mode!
  1316. -------------------
  1317. [IN S-MODE TIMER INTERRUPT]timer interrupt hit 3 times
  1318. [IN S-MODE TIMER INTERRUPT]trigger software interrupt
  1319. [IN S-MODE TIMER INTERRUPT]software interrupt will run when timer interrupt finished
  1320. [IN S-MODE TIMER INTERRUPT]timer interrupt end
  1321. [IN S-MODE SOFTWARE INTERRUPT]software interrupt hit 3 times
  1322. Current sp is 0x90000ee0, so it is in Supervisor Mode!
  1323. [IN S-MODE SOFTWARE INTERRUPT]software interrupt end
  1324. .. _design_app_demo_smode_plic:
  1325. demo_smode_plic
  1326. ~~~~~~~~~~~~~~~
  1327. This `demo_smode_plic application`_ is a bare metal program demonstrating the
  1328. PLIC (Platform Level Interrupt Controller) functionality in RISC-V processor's
  1329. S-Mode (Supervisor Mode). The program shows how to switch from M-Mode to S-Mode
  1330. and handle UART interrupts in S-Mode.
  1331. .. note::
  1332. * Ensure hardware supports required processor features
  1333. * It needs Nuclei CPU configured with PLIC, S-Mode and PMP
  1334. * Proper definitions in <Device>.h
  1335. * Need to enable PLIC in <Device.h> if PLIC present in CPU
  1336. - ``__PMP_PRESENT=1`` and ``__PLIC_PRESENT=1``
  1337. This demo will demostrate the following features:
  1338. - Demonstrates M-Mode to S-Mode transition
  1339. - Configures PMP to allow S-Mode access to all address spaces
  1340. - Registers and handles UART interrupts in S-Mode
  1341. - Supports UART receive interrupt handling
  1342. **How to run this application:**
  1343. .. code-block:: shell
  1344. # Assume that you can set up the Tools and Nuclei SDK environment
  1345. # cd to the demo_smode_plic directory
  1346. cd application/baremetal/demo_smode_plic
  1347. # MUST: Your CPU configuration must has PLIC/PMP/SMode configured
  1348. # Since Nuclei SDK 0.7.0, if you are sure CFG_HAS_PLIC is not defined in cpufeature.h, but you have PLIC
  1349. # you can pass extra make variable XLCFG_PLIC=1 during make command to tell sdk
  1350. # the PLIC present, it will define CFG_HAS_PLIC
  1351. # Clean the application first
  1352. make SOC=evalsoc CORE=n900 clean
  1353. # Build and upload the application
  1354. make SOC=evalsoc CORE=n900 upload
  1355. .. code-block:: console
  1356. Nuclei SDK Build Time: Apr 28 2025, 15:06:30
  1357. Download Mode: ILM
  1358. CPU Frequency 50002329 Hz
  1359. CPU HartID: 0
  1360. Current sp is 0x9000ff80, so it is in Machine Mode!
  1361. Drop to S-Mode now
  1362. [IN S-MODE ENTRY POINT] Hello Supervisor Mode!!!
  1363. Current sp is 0x900010c0, so it is in Supervisor Mode!
  1364. You can press any key now to trigger uart receive interrupt
  1365. Enter uart0 interrupt, you just typed: 1
  1366. Enter uart0 interrupt, you just typed: 2
  1367. .. _design_app_demo_sstc:
  1368. demo_sstc
  1369. ~~~~~~~~~
  1370. This `demo_sstc application`_ is used to demostrate how to use
  1371. the ECLIC API and Interrupt in supervisor mode with TEE and SSTC.
  1372. This demo is similar with :ref:`design_app_demo_smode_eclic`
  1373. .. note::
  1374. * It doesn't work with gd32vf103 processor.
  1375. * It needs Nuclei CPU configured with TEE feature and S-Mode ECLIC and SSTC feature
  1376. **How to run this application:**
  1377. .. code-block:: shell
  1378. # Assume that you can set up the Tools and Nuclei SDK environment
  1379. # cd to the demo_sstc directory
  1380. cd application/baremetal/demo_sstc
  1381. # MUST: Your CPU configuration must has TEE and SSTC configured
  1382. # Assume you are using n300
  1383. # Clean the application first
  1384. make SOC=evalsoc CORE=n300 clean
  1385. # Build and upload the application
  1386. make SOC=evalsoc CORE=n300 upload
  1387. .. code-block:: console
  1388. Nuclei SDK Build Time: Feb 21 2025, 11:12:45
  1389. Download Mode: ILM
  1390. CPU Frequency 15987179 Hz
  1391. CPU HartID: 0
  1392. Current sp is 0x9000ff70, so it is in Machine Mode!
  1393. Drop to S-Mode now
  1394. [IN S-MODE ENTRY POINT] Hello Supervisor Mode!!!
  1395. Current sp is 0x90001040, so it is in Supervisor Mode!
  1396. Initialize timer and start timer interrupt periodically
  1397. Current sp is 0x90000f50, so it is in Supervisor Mode!
  1398. -------------------
  1399. [IN S-MODE TIMER INTERRUPT]timer interrupt hit 0 times
  1400. [IN S-MODE TIMER INTERRUPT]trigger software interrupt
  1401. [IN S-MODE TIMER INTERRUPT]software interrupt will run during timer interrupt
  1402. [IN S-MODE SOFTWARE INTERRUPT]software interrupt hit 0 times
  1403. Current sp is 0x90000e10, so it is in Supervisor Mode!
  1404. [IN S-MODE SOFTWARE INTERRUPT]software interrupt end
  1405. [IN S-MODE TIMER INTERRUPT]timer interrupt end
  1406. Current sp is 0x90000f50, so it is in Supervisor Mode!
  1407. -------------------
  1408. [IN S-MODE TIMER INTERRUPT]timer interrupt hit 1 times
  1409. [IN S-MODE TIMER INTERRUPT]trigger software interrupt
  1410. [IN S-MODE TIMER INTERRUPT]software interrupt will run during timer interrupt
  1411. [IN S-MODE SOFTWARE INTERRUPT]software interrupt hit 1 times
  1412. Current sp is 0x90000e10, so it is in Supervisor Mode!
  1413. [IN S-MODE SOFTWARE INTERRUPT]software interrupt end
  1414. [IN S-MODE TIMER INTERRUPT]timer interrupt end
  1415. Current sp is 0x90000f50, so it is in Supervisor Mode!
  1416. .. _design_app_demo_spmp:
  1417. demo_spmp
  1418. ~~~~~~~~~
  1419. This `demo_spmp application`_ is removed from ``0.8.0`` release since the ``sPMP``
  1420. hardware feature is upgraded to ``SMPU`` in nowadays Nuclei RISC-V CPU, please
  1421. refer to :ref:`design_app_demo_smpu`.
  1422. .. _design_app_demo_smpu:
  1423. demo_smpu
  1424. ~~~~~~~~~
  1425. ``SMPU`` is upgraded from ``sPMP`` to enable S-mode OS to limit the physical addresses accessible by
  1426. U-mode software on a hart. This `demo_smpu application`_ is used to demonstrate how to grant
  1427. physical memory privileges(read, write, execute) on each physical memory region by supervisor-mode control CSRs.
  1428. .. note::
  1429. * It doesn't work with gd32vf103 processor.
  1430. * It needs Nuclei CPU configured with TEE, PMP, SMPU feature
  1431. * Need to enable PMP in <Device.h> if PMP present in CPU.
  1432. * Need to enable TEE in <Device.h> if TEE present in CPU.
  1433. * Need to enable SMPU in <Device.h> if smpu present in CPU.
  1434. * The `demo_smpu application`_ has many common design with `demo_spmp application`_, and you should first
  1435. pay attention to Encoding of Permissions and Context Switching Optimization when changed to smpu
  1436. * Unlike sPMP, ``__set_SMPUSWITCHx`` should be called to activate the entries
  1437. * ``smpu_violation_fault_handler`` is registered, which is to execute when smpu violation
  1438. exception occurs
  1439. * The SMPU is checked before the PMA checks and PMP checks
  1440. * There're three config structures, ``pmp_config`` inits that M-mode grants full permission
  1441. of the whole address range on S and U mode; ``smpu_config_x`` sets protected executable
  1442. address range as 2^12 bytes; ``smpu_config_rw`` sets protected data range as 2^12 bytes,
  1443. and you can change the ``protection``, ``order``, ``base_addr`` according to your memory assignments
  1444. * SMPU has three kinds of rules: U-mode-only, S-mode-only, and Shared-Region rules. The S bit marks a rule
  1445. as S-mode-only when set and U-mode-only when unset
  1446. * ``protection`` of smpu_config_x and smpu_config_rw should be assigned according to ``2.4. Encoding of Permissions``
  1447. of Ssmpu spec
  1448. * Exception delegation from default M mode to S mode is also provided in this demo, when
  1449. it violates smpu check. When exception occurs, the print info including ``scause``, ``sepc``
  1450. can be observed by serial console, which explains the exception cause of smpu permission
  1451. violation, and shows which asm instruction triggers the violation
  1452. * In the application code, there is a macro called ``TRIGGER_SMPU_VIOLATION_MODE`` to control the
  1453. smpu working feature:
  1454. - If **TRIGGER_SMPU_VIOLATION_MODE=INSTRUCTION_SMPU_EXCEPTION**, the unallowed memory is to
  1455. execute, which triggers ``Instruction SMPU fault``, whose scause.EXCCODE = 12
  1456. - If **TRIGGER_SMPU_VIOLATION_MODE=LOAD_SMPU_EXCEPTION**, the unallowed memory is to read,
  1457. which triggers ``Load SMPU fault``, whose scause.EXCODE = 13
  1458. - If **TRIGGER_SMPU_VIOLATION_MODE=STORE_SMPU_EXCEPTION**, the unallowed memory is to write,
  1459. which triggers ``Store/AMO SMPU fault``, whose scause.EXCODE = 15
  1460. - If **TRIGGER_SMPU_VIOLATION_MODE=EXECUTE_SHARED_DATA_REGION_EXCEPTION**, the shared R/W data region
  1461. is to execute, which triggers ``Instruction SMPU fault``
  1462. - If **TRIGGER_SMPU_VIOLATION_MODE=WRITE_READONLY_SHARED_DATA_EXCEPTION**, the shared Read-only data region
  1463. is to write, which triggers ``Store/AMO SMPU fault``
  1464. - If **TRIGGER_SMPU_VIOLATION_MODE=SHARE_CODE_DATA_REGION**, the shared code region is to execute, and the shared
  1465. R/W data region is to read and write, both of which is allowed
  1466. - If **TRIGGER_SMPU_VIOLATION_MODE=RUN_WITH_ENTRY_INACTIVE**, the code region and data reigon is set to inaccessible,
  1467. but disable corresponpding entries, so the rules doesn't take effect and execution and read/write succeed
  1468. **How to run this application:**
  1469. .. code-block::shell
  1470. # Assume that you can set up the Tools and Nuclei SDK environment
  1471. # cd to the demo_smpu directory
  1472. cd application/baremetal/demo_smpu
  1473. # MUST: Your CPU configuration must has TEE configured
  1474. # Since Nuclei SDK 0.7.0, if you are sure CFG_HAS_SMPU is not defined in cpufeature.h, but you have SMPU
  1475. # you can pass extra make variable XLCFG_SMPU=1 during make command to tell sdk
  1476. # the SMPU present, it will define CFG_HAS_SMPU
  1477. # Change macro TRIGGER_SMPU_VIOLATION_MODE value in demo_smpu.c
  1478. # to see different working mode of this demo
  1479. # Clean the application first
  1480. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300 clean
  1481. # Build and upload the application
  1482. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300 upload
  1483. **Expected output(TRIGGER_SMPU_VIOLATION_MODE=INSTRUCTION_SMPU_EXCEPTION) as below:**
  1484. .. code-block:: console
  1485. Nuclei SDK Build Time: Jun 18 2024, 18:36:40
  1486. Download Mode: ILM
  1487. CPU Frequency 16058613 Hz
  1488. CPU HartID: 0
  1489. ------smpu demo with trigger condition 0------
  1490. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x0, order_out: 32
  1491. Get smpu entry: index 0, prot_out: 0x9b, addr_out: 0x80004000, order_out: 12
  1492. Get smpu entry: index 1, prot_out: 0x9b, addr_out: 0x90000000, order_out: 12
  1493. Attempting to fetch instruction from protected address 0x0x80004000
  1494. Instruction SMPU fault occurs, cause: 0x1000000c, epc: 0x80004000
  1495. **Expected output(TRIGGER_SMPU_VIOLATION_MODE=LOAD_SMPU_EXCEPTION) as below:**
  1496. .. code-block:: console
  1497. Nuclei SDK Build Time: Jun 18 2024, 18:39:13
  1498. Download Mode: ILM
  1499. CPU Frequency 16068116 Hz
  1500. CPU HartID: 0
  1501. ------smpu demo with trigger condition 1------
  1502. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x0, order_out: 32
  1503. Get smpu entry: index 0, prot_out: 0x9c, addr_out: 0x80004000, order_out: 12
  1504. Get smpu entry: index 1, prot_out: 0x9c, addr_out: 0x90000000, order_out: 12
  1505. Attempting to fetch instruction from protected address 0x0x80004000
  1506. ----protected_execute succeed!----
  1507. Attempting to read protected_data[0] at 0x90000000
  1508. Load SMPU fault occurs, cause: 0x1000000d, epc: 0x8000608c
  1509. **Expected output(TRIGGER_SMPU_VIOLATION_MODE=STORE_SMPU_EXCEPTION) as below:**
  1510. .. code-block:: console
  1511. Nuclei SDK Build Time: Jun 18 2024, 18:40:00
  1512. Download Mode: ILM
  1513. CPU Frequency 16057630 Hz
  1514. CPU HartID: 0
  1515. ------smpu demo with trigger condition 2------
  1516. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x0, order_out: 32
  1517. Get smpu entry: index 0, prot_out: 0x9c, addr_out: 0x80004000, order_out: 12
  1518. Get smpu entry: index 1, prot_out: 0x99, addr_out: 0x90000000, order_out: 12
  1519. Attempting to fetch instruction from protected address 0x0x80004000
  1520. ----protected_execute succeed!----
  1521. Attempting to read protected_data[0] at 0x90000000
  1522. protected_data[0]: 0xAA succeed
  1523. Attempting to write protected_data[0] at 0x90000000
  1524. Store/AMO SMPU fault occurs, cause: 0x1000000f, epc: 0x800060b2
  1525. **Expected output(TRIGGER_SMPU_VIOLATION_MODE=EXECUTE_SHARED_DATA_REGION_EXCEPTION) as below:**
  1526. .. code-block:: console
  1527. Nuclei SDK Build Time: Jun 18 2024, 18:40:39
  1528. Download Mode: ILM
  1529. CPU Frequency 16057630 Hz
  1530. CPU HartID: 0
  1531. ------smpu demo with trigger condition 3------
  1532. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x0, order_out: 32
  1533. Get smpu entry: index 0, prot_out: 0x1e, addr_out: 0x80004000, order_out: 12
  1534. Get smpu entry: index 1, prot_out: 0x1e, addr_out: 0x90000000, order_out: 12
  1535. Attempting to fetch instruction from protected address 0x0x80004000
  1536. Instruction SMPU fault occurs, cause: 0x1000000c, epc: 0x80004000
  1537. **Expected output(TRIGGER_SMPU_VIOLATION_MODE=WRITE_READONLY_SHARED_DATA_EXCEPTION) as below:**
  1538. .. code-block:: console
  1539. Nuclei SDK Build Time: Jun 18 2024, 18:41:17
  1540. Download Mode: ILM
  1541. CPU Frequency 16057630 Hz
  1542. CPU HartID: 0
  1543. ------smpu demo with trigger condition 4------
  1544. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x0, order_out: 32
  1545. Get smpu entry: index 0, prot_out: 0x9a, addr_out: 0x80004000, order_out: 12
  1546. Get smpu entry: index 1, prot_out: 0x9f, addr_out: 0x90000000, order_out: 12
  1547. Attempting to fetch instruction from protected address 0x0x80004000
  1548. ----protected_execute succeed!----
  1549. Attempting to read protected_data[0] at 0x90000000
  1550. protected_data[0]: 0xAA succeed
  1551. Attempting to write protected_data[0] at 0x90000000
  1552. Store/AMO SMPU fault occurs, cause: 0x1000000f, epc: 0x800060b2
  1553. **Expected output(TRIGGER_SMPU_VIOLATION_MODE=SHARE_CODE_DATA_REGION) as below:**
  1554. .. code-block:: console
  1555. Nuclei SDK Build Time: Jun 18 2024, 18:41:46
  1556. Download Mode: ILM
  1557. CPU Frequency 16068116 Hz
  1558. CPU HartID: 0
  1559. ------smpu demo with trigger condition 5------
  1560. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x0, order_out: 32
  1561. Get smpu entry: index 0, prot_out: 0x9a, addr_out: 0x80004000, order_out: 12
  1562. Get smpu entry: index 1, prot_out: 0x1e, addr_out: 0x90000000, order_out: 12
  1563. Attempting to fetch instruction from protected address 0x0x80004000
  1564. ----protected_execute succeed!----
  1565. Attempting to read protected_data[0] at 0x90000000
  1566. protected_data[0]: 0xAA succeed
  1567. Attempting to write protected_data[0] at 0x90000000
  1568. Won't run here if violates rules check!
  1569. **(Default)Expected output(TRIGGER_SMPU_VIOLATION_MODE=RUN_WITH_ENTRY_INACTIVE) as below:**
  1570. .. code-block:: console
  1571. Nuclei SDK Build Time: Jun 18 2024, 18:42:19
  1572. Download Mode: ILM
  1573. CPU Frequency 16057630 Hz
  1574. CPU HartID: 0
  1575. ------smpu demo with trigger condition 6------
  1576. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x0, order_out: 32
  1577. Get smpu entry: index 0, prot_out: 0x18, addr_out: 0x80004000, order_out: 12
  1578. Get smpu entry: index 1, prot_out: 0x18, addr_out: 0x90000000, order_out: 12
  1579. Attempting to fetch instruction from protected address 0x0x80004000
  1580. ----protected_execute succeed!----
  1581. Attempting to read protected_data[0] at 0x90000000
  1582. protected_data[0]: 0xAA succeed
  1583. Attempting to write protected_data[0] at 0x90000000
  1584. Won't run here if violates rules check!
  1585. .. _design_app_demo_profiling:
  1586. demo_profiling
  1587. ~~~~~~~~~~~~~~
  1588. This `demo_profiling application`_ is used to demonstrate how to use gprof or gcov
  1589. in Nuclei Studio.
  1590. This application itself is modified based on an opensource aes application, we add
  1591. gprof and gcov collection code to ``main.c``, it will dump gprof and gcov data in
  1592. console when main part code is executed.
  1593. .. note::
  1594. * **WARNING** GCC 14 with nuclei sdk code coverage not working, need to modify ``Components/profiling/gcov.c``, changes need to be made like this https://github.com/Nuclei-Software/nuclei-sdk/commit/5aaae0d5a7
  1595. * Introduced in Nuclei SDK 0.6.0, worked with Nuclei Studio >= 2024.02
  1596. * Using gprof or gcov introduces instrument code into the original program,
  1597. necessitating additional memory to store the collected data. This results in
  1598. a slight increase in the program's memory footprint compared to its uninstrumented counterpart.
  1599. * It cannot be directly used in command line mode, you should use it in Nuclei Studio.
  1600. * Please check ``README.md`` about gcov and gprof support in https://github.com/Nuclei-Software/nuclei-sdk/tree/master/Components/profiling
  1601. Import or download Nuclei SDK 0.6.0 or later release NPK in Nuclei Studio, and then create a
  1602. project called ``demo_profiling`` based on ``app-nsdk_demo_profiling`` using
  1603. ``Create Nuclei RISC-V C/C++ Project`` Wizard as below:
  1604. .. figure:: /asserts/images/create_demo_profiling_example.png
  1605. :width: 80 %
  1606. :align: center
  1607. :alt: Create demo profiling example
  1608. And when example is created, assume you want to profiling the ``application`` folder, since
  1609. it is the core algorithm of this example, then you just need to do the following steps:
  1610. - Right click on the ``application`` folder, and click ``Properities``, and add extra options
  1611. in ``C/C++ Build`` -> ``Settings`` -> ``GNU RISC-V Cross C Compiler`` -> ``Miscellaneous`` -> ``Other compiler flags``.
  1612. - If you want to do gprof, you need to add ``-pg`` option.
  1613. - If you want to do gcov, you need to add ``-coverage`` option.
  1614. - Open ``main.c``, and find ``TODO`` item, and comment ``gprof_collect(2);`` or ``gcov_collect(2);`` based on
  1615. gprof or gcov you want to collect.
  1616. - If you want to collect gprof data, you also need to modify ``nuclei_sdk/Components/profiling/gprof_stub.c``,
  1617. if you code already has a 1ms period timer interrupt, you should copy code in ``eclic_mtip_handler`` to do
  1618. executing sampling, otherwise you can uncomment ``#define SAMPLE_USING_SYSTIMER``
  1619. Here I want to collect both gprof and gcov, so I modify it like below:
  1620. .. figure:: /asserts/images/add_profiling_options_in_nuclei_studio.png
  1621. :width: 80 %
  1622. :align: center
  1623. :alt: Add profiling options in Nuclei Studio
  1624. .. figure:: /asserts/images/modify_profiling_example_code.png
  1625. :width: 80 %
  1626. :align: center
  1627. :alt: Modify profiling example code
  1628. And then compile this example code, and run it using hardware or qemu, qemu is just function model,
  1629. so it didn't provide correct timing information.
  1630. When program runs, it will dump gprof and gcov data in console, and you can copy all the output as
  1631. a file called ``prof.log``, and use ``gprof_parse.py`` to parse the data, and generate a
  1632. gcov and gprof binary files.
  1633. .. figure:: /asserts/images/parse_profiling_log.png
  1634. :width: 80 %
  1635. :align: center
  1636. :alt: Parse profiling log and generate gcda and gmon.out files
  1637. Then you can double click ``gmon.out`` and ``aes.gcda`` to check the gprof and gcov view in Nuclei Studio
  1638. like below:
  1639. .. figure:: /asserts/images/gprof_gcov_view_in_nuclei_studio.png
  1640. :width: 80 %
  1641. :align: center
  1642. :alt: Gprof and gcov view in Nuclei Studio
  1643. About GProf view, please click https://help.eclipse.org/latest/topic/org.eclipse.linuxtools.gprof.docs/Linux_Tools_Project/GProf/User_Guide/GProf-View.html
  1644. to learn more.
  1645. About Gcov view, please click https://help.eclipse.org/latest/topic/org.eclipse.linuxtools.gcov.docs/Linux_Tools_Project/GCov/User_Guide/Gcov-main-view.html
  1646. to learn more.
  1647. .. _design_app_demo_pmp:
  1648. demo_pmp
  1649. ~~~~~~~~
  1650. This `demo_pmp application`_ is used to demonstrate how to grant physical memory privileges
  1651. (read, write, execute) on each physical memory region by machine mode control CSRs.
  1652. .. note::
  1653. * It doesn't work with gd32vf103 processor.
  1654. * It needs Nuclei CPU configured with PMP feature
  1655. * Need to enable PMP in <Device.h> if PMP present in CPU.
  1656. * ``pmp_violation_fault_handler`` is registered, which is to execute when pmp violation
  1657. exception occurs
  1658. * There're two config structures, ``pmp_config_x`` sets protected executable address range
  1659. as 2^12 bytes; ``pmp_config_rw`` sets protected readable/writable address range as 2^12
  1660. bytes, and you can change the ``protection``, ``order``, ``base_addr`` according to your
  1661. memory assignments
  1662. * When exception occurs, the print info including ``mcause``, ``mepc`` can be observed
  1663. by serial console, which explains the exception cause of PMP permission violation, and
  1664. shows which asm instruction triggers the violation
  1665. * In the application code, there is a macro called ``TRIGGER_PMP_VIOLATION_MODE`` to control the
  1666. PMP working feature:
  1667. - If **TRIGGER_PMP_VIOLATION_MODE=INSTRUCTION_FETCH_EXCEPTION**, the unallowed memory is to
  1668. execute, which triggers ``Instruction access fault``, whose mcause.EXCCODE = 1 and mdcause = 1
  1669. - If **TRIGGER_PMP_VIOLATION_MODE=LOAD_EXCEPTION**, the unallowed memory is to read,
  1670. which triggers ``Load access fault``, whose mcause.EXCODE = 5 and mdcause = 1
  1671. - If **TRIGGER_PMP_VIOLATION_MODE=STORE_EXCEPTION**, the unallowed memory is to write,
  1672. which triggers ``Store/AMO access fault``, whose mcause.EXCODE = 7 and mdcause = 1
  1673. - If **TRIGGER_PMP_VIOLATION_MODE=RUN_WITH_NO_PMP_CHECK**, no violation occurs
  1674. **How to run this application:**
  1675. .. code-block::shell
  1676. # Assume that you can set up the Tools and Nuclei SDK environment
  1677. # cd to the demo_pmp directory
  1678. cd application/baremetal/demo_pmp
  1679. # MUST: Your CPU configuration must has PMP configured
  1680. # Change macro __PMP_PRESENT to 1 in <Device.h>
  1681. #define __PMP_PRESENT 1
  1682. # Change macro TRIGGER_PMP_VIOLATION_MODE value in demo_pmp.c
  1683. # to see different working mode of this demo
  1684. # Clean the application first
  1685. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300 clean
  1686. # Build and upload the application
  1687. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300 upload
  1688. **Expected output(TRIGGER_PMP_VIOLATION_MODE=INSTRUCTION_FETCH_EXCEPTION) as below:**
  1689. .. code-block:: console
  1690. Nuclei SDK Build Time: Aug 15 2022, 15:45:57
  1691. Download Mode: ILM
  1692. CPU Frequency 16006184 Hz
  1693. ------PMP demo with trigger condition 0------
  1694. Get pmp entry: index 0, prot_out: 0x9b, addr_out: 0x80004000, order_out: 12
  1695. Get pmp entry: index 1, prot_out: 0x9b, addr_out: 0x90000000, order_out: 12
  1696. Attempting to fetch instruction from protected address
  1697. Instruction access fault occurs, cause: 0x30000001, epc: 0x80004000
  1698. From disassembly code, MEPC refers to
  1699. .. code-block:: console
  1700. 80004000: 90002537 lui a0,0x90002
  1701. **Expected output(TRIGGER_PMP_VIOLATION_MODE=LOAD_EXCEPTION) as below:**
  1702. .. code-block:: console
  1703. Nuclei SDK Build Time: Aug 15 2022, 15:45:57
  1704. Download Mode: ILM
  1705. CPU Frequency 16006184 Hz
  1706. ------PMP demo with trigger condition 1------
  1707. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x80004000, order_out: 12
  1708. Get pmp entry: index 1, prot_out: 0x9a, addr_out: 0x90000000, order_out: 12
  1709. Attempting to fetch instruction from protected address
  1710. ----protected_execute succeed!----
  1711. Attempting to read protected_data[0]
  1712. Load access fault occurs, cause: 0x30000005, epc: 0x80004022
  1713. From disassembly code, MEPC refers to
  1714. .. code-block:: console
  1715. 80004022: 00044583 lbu a1,0(s0) # 90000000 <_sp+0xffff0000>
  1716. **Expected output(TRIGGER_PMP_VIOLATION_MODE=STORE_EXCEPTION) as below:**
  1717. .. code-block:: console
  1718. Nuclei SDK Build Time: Aug 15 2022, 15:45:57
  1719. Download Mode: ILM
  1720. CPU Frequency 15998320 Hz
  1721. ------PMP demo with trigger condition 2------
  1722. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x80004000, order_out: 12
  1723. Get pmp entry: index 1, prot_out: 0x99, addr_out: 0x90000000, order_out: 12
  1724. Attempting to fetch instruction from protected address
  1725. ----protected_execute succeed!----
  1726. Attempting to read protected_data[0]
  1727. protected_data[0]: 0xAA succeed
  1728. Attempting to write protected_data[0]
  1729. Store/AMO access fault occurs, cause: 0x30000007, epc: 0x80004044
  1730. From disassembly code, MEPC refers to
  1731. .. code-block:: console
  1732. 80004044: 00f40023 sb a5,0(s0)
  1733. **(Default)Expected output(TRIGGER_PMP_VIOLATION_MODE=RUN_WITH_NO_PMP_CHECK) as below:**
  1734. .. code-block:: console
  1735. Nuclei SDK Build Time: Aug 15 2022, 15:45:57
  1736. Download Mode: ILM
  1737. CPU Frequency 16006184 Hz
  1738. ------PMP demo with trigger condition 3------
  1739. Get pmp entry: index 0, prot_out: 0x1f, addr_out: 0x80004000, order_out: 12
  1740. Get pmp entry: index 1, prot_out: 0x1b, addr_out: 0x90000000, order_out: 12
  1741. Attempting to fetch instruction from protected address
  1742. ----protected_execute succeed!----
  1743. Attempting to read protected_data[0]
  1744. protected_data[0]: 0xAA succeed
  1745. Attempting to write protected_data[0]
  1746. Won't run here if violates L R\W\X permission check!
  1747. .. _design_app_demo_cidu:
  1748. demo_cidu
  1749. ~~~~~~~~~
  1750. This `demo_cidu application`_ is used to demonstrate External Interrupt Distribution
  1751. (external interrupt broadcast/first come first claim), Inter Core interrupt and Semaphore
  1752. of Cluster Interrupt Distribution Unit (CIDU).
  1753. This demo requires the SMP cores share the same RAM and ROM, for example, in current
  1754. evalsoc/demosoc system, ilm/dlm are private resource for cpu, only the DDR/SRAM memory are shared resource
  1755. for all the cpu.
  1756. .. note::
  1757. * It doesn't work with gd32vf103 processor.
  1758. * It needs Nuclei SMP CPU configured with CIDU feature
  1759. * It needs Nuclei EvalSoC's uart and its interrupt, if you want to port it, you need to port uart driver of your SoC
  1760. * Need to enable CIDU in <Device.h> if CIDU present in cluster.
  1761. * Multicore SoC is needed.
  1762. * ``UART0`` receive is used as external interrupt, registered as ``eclic_uart0_int_handler``, which is the best choice
  1763. for evalsoc/demosoc and is easy to trigger by writing the serial terminal
  1764. * ``UART0`` receive interrupt can be broadcast to all the cores or some, and also first coming first claim
  1765. mode will ensure only the first responding core handle the interrupt service routine(ISR)
  1766. * Inter core interrupt shows likes this: core3 sends interrupt to core2, core2 sends interrupt to core1,
  1767. core1 sends interrupt to core0, and core0 sends interrupt to core3, registered as ``eclic_inter_core_int_handler``,
  1768. supposing the SoC is four cores, and etc.
  1769. * To demonstrate it will handle properly if multiple cores send interrupt to one core simultaneously,
  1770. besides core2, core0 also sends interrupt to core1, supposing the SoC is four core
  1771. * To protect ``UART0`` resource when multicores want to access it(call ``printf``), semaphore is configured, which needs to
  1772. be acquired successfully before accessing ``UART0``, and release it after job done
  1773. * ``ENABLE_FIRST_COME_FIRST_CLAIM_MODE`` is defined by default, you can comment it to just use broadcast mode
  1774. **How to run this application:**
  1775. .. code-block:: shell
  1776. # Assume that you can set up the Tools and Nuclei SDK environment
  1777. # Use Nuclei UX900 SMP 2/4/8(4/8 is better) Core RISC-V processor as example
  1778. # application needs to run in ddr memory not in ilm memory
  1779. # cd to the demo_cidu directory
  1780. cd application/baremetal/demo_cidu
  1781. # Since Nuclei SDK 0.7.0, if you are sure CFG_HAS_IDU is not defined in cpufeature.h, but you have CIDU
  1782. # you can pass extra make variable XLCFG_CIDU=1 during make command to tell sdk
  1783. # the cidu present, it will define CFG_HAS_IDU
  1784. # Clean the application first
  1785. make SOC=evalsoc BOARD=nuclei_fpga_eval SMP=4 CORE=ux900 clean
  1786. # Build and upload the application
  1787. make SOC=evalsoc BOARD=nuclei_fpga_eval SMP=4 CORE=ux900 upload
  1788. **Expected output(inter core interrupt) as below:**
  1789. .. code-block:: console
  1790. Nuclei SDK Build Time: Feb 10 2023, 18:39:17
  1791. Download Mode: SRAM
  1792. CPU Frequency 100602675 Hz
  1793. CPU HartID: 0
  1794. Core 3 has received interrupt from core 0
  1795. Core 1 has received interrupt from core 0
  1796. Core 2 has received interrupt from core 3
  1797. Core 1 has received interrupt from core 2
  1798. Core 0 has received interrupt from core 1
  1799. From output, each core sends interrupt in order, and core 1 has received interrupts from
  1800. both core 0 and core 2.
  1801. **Expected output(write anything to the serial terminal, enable first come first claim mode) as below:**
  1802. .. code-block:: console
  1803. Nuclei SDK Build Time: Feb 10 2023, 18:44:45
  1804. Download Mode: SRAM
  1805. CPU Frequency 100612833 Hz
  1806. CPU HartID: 0
  1807. Core 3 has received interrupt from core 0
  1808. Core 1 has received interrupt from core 0
  1809. Core 2 has received interrupt from core 3
  1810. Core 1 has received interrupt from core 2
  1811. Core 0 has received interrupt from core 1
  1812. Core 2 enters uart0_receive_handler
  1813. Core 1 enters uart0_receive_handler
  1814. Core 2 wants to process rx input
  1815. Core 2 processed input:d
  1816. Core 3 enters uart0_receive_handler
  1817. Core 0 enters uart0_receive_handler
  1818. Core 3 wants to process rx input
  1819. Core 3 enters uart0_receive_handler
  1820. Core 1 enters uart0_receive_handler
  1821. Core 3 wants to process rx input
  1822. Core 3 processed input:q
  1823. Core 0 enters uart0_receive_handler
  1824. Core 2 enters uart0_receive_handler
  1825. Core 0 wants to process rx input
  1826. Core 0 enters uart0_receive_handler
  1827. Core 1 enters uart0_receive_handler
  1828. Core 0 wants to process rx input
  1829. Core 0 processed input:s
  1830. Core 3 enters uart0_receive_handler
  1831. Core 2 enters uart0_receive_handler
  1832. Core 3 wants to process rx input
  1833. Core 1 enters uart0_receive_handler
  1834. Core 2 enters uart0_receive_handler
  1835. Core 0 enters uart0_receive_handler
  1836. Core 1 wants to process rx input
  1837. Core 1 processed input:g
  1838. Core 3 enters uart0_receive_handler
  1839. Core 3 wants to process rx input
  1840. From output, though setting interrupt broadcasted to all(all the core enters the ISR), while only one core (the first one)
  1841. can claim the the interrupt(first come first claim) then process the uart0 input, others quit when find interrupt has been claimed.
  1842. **Expected output(write anything to the serial terminal, disable first come first claim mode) as below:**
  1843. .. code-block:: console
  1844. Nuclei SDK Build Time: Feb 10 2023, 18:48:47
  1845. Download Mode: SRAM
  1846. CPU Frequency 100602675 Hz
  1847. CPU HartID: 0
  1848. Core 3 has received interrupt from core 0
  1849. Core 1 has received interrupt from core 0
  1850. Core 2 has received interrupt from core 3
  1851. Core 1 has received interrupt from core 2
  1852. Core 0 has received interrupt from core 1
  1853. Core 2 enters uart0_receive_handler
  1854. Core 0 enters uart0_receive_handler
  1855. Core 2 wants to process rx input
  1856. Core 2 processed input:q
  1857. Core 0 wants to process rx input
  1858. Core 1 enters uart0_receive_handler
  1859. Core 1 wants to process rx input
  1860. Core 3 enters uart0_receive_handler
  1861. Core 3 wants to process rx input
  1862. Core 3 enters uart0_receive_handler
  1863. Core 0 enters uart0_receive_handler
  1864. Core 1 enters uart0_receive_handler
  1865. Core 2 enters uart0_receive_handler
  1866. Core 0 wants to process rx input
  1867. Core 0 processed input:w
  1868. Core 1 wants to process rx input
  1869. Core 3 wants to process rx input
  1870. Core 2 wants to process rx input
  1871. Core 2 enters uart0_receive_handler
  1872. Core 0 enters uart0_receive_handler
  1873. Core 1 enters uart0_receive_handler
  1874. Core 1 wants to process rx input
  1875. Core 1 processed input:e
  1876. Core 0 wants to process rx input
  1877. Core 2 wants to process rx input
  1878. Core 3 enters uart0_receive_handler
  1879. Core 3 wants to process rx input
  1880. Core 3 enters uart0_receive_handler
  1881. Core 1 enters uart0_receive_handler
  1882. Core 3 wants to process rx input
  1883. Core 3 processed input:r
  1884. Core 0 enters uart0_receive_handler
  1885. Core 1 wants to process rx input
  1886. Core 0 wants to process rx input
  1887. Core 2 enters uart0_receive_handler
  1888. Core 2 wants to process rx input
  1889. From output, all the core enters the ISR(means broadcasted), while only one core can process
  1890. the uart0 input(semaphore used), when semaphore released, other core wants to handle the ISR job(means claim mode disabled),
  1891. but process nothing (keyboard input has been received and rx interrupt pending cleared) because it has been processed.
  1892. .. _design_app_demo_cache:
  1893. demo_cache
  1894. ~~~~~~~~~~
  1895. .. note::
  1896. * It doesn't work with gd32vf103 processor.
  1897. * It needs Nuclei CPU configured with CCM feature
  1898. This `demo_cache application`_ is used to demonstrate how to understand cache mechanism.
  1899. This demo requires DCache, ICache and CCM(Cache Control and Maintenance), and needs to run in DDR/SRAM memory,
  1900. because cache will bypass when run in ilm, data in dlm(private resource for cpu).
  1901. .. note::
  1902. * Need to enable DCache, ICACHE, CCM in <Device.h> if present in CPU.
  1903. * An arrary( ``ROW_SIZE`` * ``COL_SIZE`` ) called ``array_test`` is created to access its first element ``array_test[0][0]``
  1904. * Firstly, enable and invalidate all DCache, update ``array_test`` by writing a consant, the cache miss happens and will update ``array_test``'s
  1905. mapping value in DCache, read out ``array_test[0][0]``; then disable the Dcache, init array_test in the ddr memory to different constant,
  1906. read out ``array_test[0][0]``; after that, enable the DCache flushes DCache to ddr memory, read out ``array_test[0][0]``, and compare these ``array_test[0][0]`` value
  1907. * Again disable the Dcache, init array_test in the ddr memory, read out ``array_test[0][0]``; then enable the DCache, read out ``array_test[0][0]``,
  1908. and compare with the one before
  1909. * **For further understanding**, if the CPU has configured ``HPM`` (Hardware Performance Monitor), observe the cache miss count by recording the cache miss
  1910. of updating array_test with DCache invalid, then compared to updating array_test with keeping DCache valid; also, compare the cache miss
  1911. count of updating array_test row by row with column by column
  1912. * ``BIG_ROW_SIZE`` can be defined to make the array size ``2048*64`` bytes, which is big to see the cache miss gap(performance gap) between
  1913. updating ``array_test`` row by row and column by column
  1914. * In our evalsoc/demosoc, cache line size is 64 bytes generally, so ``array_test``'s ``COL_SIZE`` is 64 bytes for calculating the cache miss manually and easily
  1915. * When ``HPM`` used, because there's global variables in ``HPM_START`` and ``HPM_END`` , **these will bring 3 cache miss itself** (not considering cached)
  1916. * You can manage ICache apis like DCache, which skipped in this demo for less similar code
  1917. * Different compile optimization level such as -O2/-O0 effects cache miss
  1918. .. note::
  1919. * There's ``printf`` hidden in ``HPM_END``, if there is another HPM_END before it, the ``printf`` will bring some cache miss
  1920. **How to run this application:**
  1921. .. code-block:: shell
  1922. # Assume that you can set up the Tools and Nuclei SDK environment
  1923. # Use Nuclei UX900 Core RISC-V processor as example
  1924. # application needs to run in ddr memory not in ilm memory
  1925. # cd to the demo_cache directory
  1926. cd application/baremetal/demo_cache
  1927. # Since Nuclei SDK 0.7.0, if you are sure CFG_HAS_IOCC is not defined in cpufeature.h, but you have CCM
  1928. # you can pass extra make variable XLCFG_CCM=1 during make command to tell sdk
  1929. # the ccm present, it will define CFG_HAS_IOCC
  1930. # Clean the application first
  1931. make SOC=evalsoc BOARD=nuclei_fpga_eval CORE=ux900 DOWNLOAD=sram CCM_EN=1 clean
  1932. # Build and upload the application
  1933. make SOC=evalsoc BOARD=nuclei_fpga_eval CORE=ux900 DOWNLOAD=sram CCM_EN=1 upload
  1934. **Expected output(DISABLE_NMSIS_HPM defined) as below:**
  1935. .. code-block:: console
  1936. Nuclei SDK Build Time: Jul 22 2025, 18:05:53
  1937. Download Mode: DDR
  1938. CPU Frequency 49993154 Hz
  1939. CPU HartID: 0
  1940. Benchmark initialized
  1941. DCache Linesize is 64 bytes, ways is 2, setperway is 512, total size is 65536 bytes
  1942. array_test 10 * 64 bytes
  1943. ------Update array in memory------
  1944. ------Update array to all 0xab in cache: array_update_by_row------
  1945. CSV, array_update_by_row_cycle, 766
  1946. -------Keep DCache valid, do array_update_by_row again-------
  1947. CSV, array_update_by_row_cycle, 136
  1948. -------Invalidate all the Dcache-------
  1949. ------Update array to all 0xab in cache: array_update_by_col ------
  1950. CSV, array_update_by_col_cycle, 441
  1951. Read out array_test[0][0] 0xab in cache, then disable DCache
  1952. ------Init array in memory to all 0x34------
  1953. Read out array_test[0][0] 0x34 in memory, then enable Dcache
  1954. After cache flushed to memory, array_test[0][0] in memory is 0xab
  1955. ------Again init array in memory to all 0x34, then enable DCache------
  1956. Read out array_test[0][0] 0x34 in memory
  1957. Read out array_test[0][0] 0xab in cache, when mapped value in memory has changed
  1958. From output, ``array_test`` is updated in memory to all 0xab, and **cached in DCache** when miss happens,
  1959. then disable DCache, init array_test just in memory to all 0x34, **after cache flushed to memory**,
  1960. ``array_test`` in memory is all 0xab same with ``array_test`` in DCache. **Disable DCache and init array_test
  1961. again**, ``array_test`` now (all 0x34) differs with cached array_test (all 0xab) after DCache enabled.
  1962. **Expected output(DISABLE_NMSIS_HPM undefined and CFG_HAS_HPM defined in cpufeature.h) as below:**
  1963. .. code-block:: console
  1964. Nuclei SDK Build Time: Jul 22 2025, 17:42:24
  1965. Download Mode: DDR
  1966. CPU Frequency 49993154 Hz
  1967. CPU HartID: 0
  1968. Benchmark initialized
  1969. DCache Linesize is 64 bytes, ways is 2, setperway is 512, total size is 65536 bytes
  1970. array_test 10 * 64 bytes
  1971. ------Update array in memory------
  1972. High performance monitor initialized
  1973. ------Update array to all 0xab in cache: array_update_by_row------
  1974. CSV, array_update_by_row_cycle, 809
  1975. HPM4:0xf0000021, array_update_by_row_dcache_miss, 19
  1976. HPM3:0xf0000011, array_update_by_row_icache_miss, 36
  1977. -------Keep DCache valid, do array_update_by_row again-------
  1978. CSV, array_update_by_row_cycle, 147
  1979. HPM4:0xf0000021, array_update_by_row_dcache_miss, 0
  1980. HPM3:0xf0000011, array_update_by_row_icache_miss, 3
  1981. -------Invalidate all the Dcache-------
  1982. ------Update array to all 0xab in cache: array_update_by_col ------
  1983. CSV, array_update_by_col_cycle, 436
  1984. HPM4:0xf0000021, array_update_by_col_dcache_miss, 19
  1985. Read out array_test[0][0] 0xab in cache, then disable DCache
  1986. ------Init array in memory to all 0x34------
  1987. Read out array_test[0][0] 0x34 in memory, then enable Dcache
  1988. After cache flushed to memory, array_test[0][0] in memory is 0xab
  1989. ------Again init array in memory to all 0x34, then enable DCache------
  1990. Read out array_test[0][0] 0x34 in memory
  1991. Read out array_test[0][0] 0xab in cache, when mapped value in memory has changed
  1992. HPM4:0xf0000021, dcachemiss_readonebyte, 1
  1993. From output, ``HPM`` is enabled, cache miss is counted and ``array_test`` size is 10 * 64 bytes.
  1994. **At first, DCache is invalid**, the first time ``array_test`` update by row has 10 miss(HPM4 shows more,
  1995. because HPM4 and other execution it wraps bring some); **Keep DCache valid**, update array_test by row again,
  1996. cache miss decreases rapidly, which means ``array_test`` has already cached;
  1997. **Then invalidate all the Dcache**, array_test update by col seems has the same cache miss as update by row.
  1998. **Expected output(BIG_ROW_SIZE defined, DISABLE_NMSIS_HPM undefined and CFG_HAS_HPM defined in cpufeature.h) as below:**
  1999. .. code-block:: console
  2000. Nuclei SDK Build Time: Jul 22 2025, 17:50:49
  2001. Download Mode: DDR
  2002. CPU Frequency 50000363 Hz
  2003. CPU HartID: 0
  2004. Benchmark initialized
  2005. DCache Linesize is 64 bytes, ways is 2, setperway is 512, total size is 65536 bytes
  2006. array_test 2048 * 64 bytes
  2007. ------Update array in memory------
  2008. High performance monitor initialized
  2009. ------Update array to all 0xab in cache: array_update_by_row------
  2010. CSV, array_update_by_row_cycle, 155917
  2011. HPM4:0xf0000021, array_update_by_row_dcache_miss, 2068
  2012. HPM3:0xf0000011, array_update_by_row_icache_miss, 37
  2013. -------Keep DCache valid, do array_update_by_row again-------
  2014. CSV, array_update_by_row_cycle, 187584
  2015. HPM4:0xf0000021, array_update_by_row_dcache_miss, 2068
  2016. HPM3:0xf0000011, array_update_by_row_icache_miss, 4
  2017. -------Invalidate all the Dcache-------
  2018. ------Update array to all 0xab in cache: array_update_by_col ------
  2019. CSV, array_update_by_col_cycle, 620971
  2020. HPM4:0xf0000021, array_update_by_col_dcache_miss, 16405
  2021. Read out array_test[0][0] 0xab in cache, then disable DCache
  2022. ------Init array in memory to all 0x34------
  2023. Read out array_test[0][0] 0x34 in memory, then enable Dcache
  2024. After cache flushed to memory, array_test[0][0] in memory is 0xab
  2025. ------Again init array in memory to all 0x34, then enable DCache------
  2026. Read out array_test[0][0] 0x34 in memory
  2027. Read out array_test[0][0] 0xab in cache, when mapped value in memory has changed
  2028. HPM4:0xf0000021, dcachemiss_readonebyte, 1
  2029. From output, ``array_test`` size is enlarged to ``2048 * 64`` bytes, which is **two times the size of DCache (1024 * 64 bytes)**.
  2030. Cache miss brought by ``HPM`` itself ignored, array update by col has **8 times cache miss(16405) as the array update by row has(2068)**.
  2031. That's because when first byte access brings one cache misse, **one cache line(64 bytes in this demo) is fetched to cache**,
  2032. and it works best if other 63 cached bytes can be accessed before getting dirty as soon as possible, as update by row does, so the cache miss
  2033. equals nearly to ``ROW_SIZE``, while when updated by col, every byte in ``ROW_SIZE`` * ``COL_SIZE`` will cause a cache miss! which is cache-unfriendly.
  2034. What's more, considering ``array_test`` size is two times the size of DCache, the cached data has been kicked out when ``do array_update_by_row again``,
  2035. so the cache miss is nearly the same as the first time.
  2036. .. _design_app_demo_stack_check:
  2037. demo_stack_check
  2038. ~~~~~~~~~~~~~~~~
  2039. .. note::
  2040. * It doesn't work with gd32vf103 processor.
  2041. * It needs Nuclei CPU configured with stack check feature
  2042. This `demo_stack_check application`_ is used to demonstrate how to check stack overflow and underflow and track the ``sp``.
  2043. For now, this demo needs to run on **only 300 Series v4.2.0 or later**, which supports this ``Stack Check`` function.
  2044. .. note::
  2045. * The Stack Check can work as expected only when the stack downwardly grows.
  2046. * ``STACK_TOP``, ``STACK_BOTTOM``, ``STACK_SIZE`` refers to stack's high/low address and size in bytes, which gets from the linker script
  2047. * ``stack_corrupt_exception_handler`` is registered as exception handler to process stack overflow and underflow
  2048. * A simple recursive function of calculating factorial is reformed, which will consume stack more or less by the ``n`` input, thus may cause
  2049. overflow; a trick is used to cause underflow that when it iterates over, decrease the stack base value to make the underflow condition on purpose
  2050. * The ``sp`` has grown downwardly 0x50 bytes in the exception entry saving context, in this demo, add ``sp`` by 0x50 is the ``sp`` value that triggered overflow/underflow
  2051. * When it comes into exception and handle it over, the flow doesn't stop in it as usual, and ``pc`` continues to execute, which is on purpose to show
  2052. ``overflow``, ``underflow`` and ``track sp`` mode in one-time run
  2053. * In ``sp track mode``, logging is enabled in ``factorial``, to show the ``sp`` value change; and the BOUND won't track sp(won't change) if sp is bigger in the second run
  2054. .. note::
  2055. * Must set the BOUND and BASE before setting the check mode
  2056. * Reserve 0x200 bytes for exception stack push/pop
  2057. **How to run this application:**
  2058. .. code-block:: shell
  2059. # Assume that you can set up the Tools and Nuclei SDK environment
  2060. # Use Nuclei n300 Core RISC-V processor as example
  2061. # cd to the demo_stack_check directory
  2062. cd application/baremetal/demo_stack_check
  2063. # Clean the application first
  2064. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ddr CORE=n300 clean
  2065. # Build and upload the application
  2066. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ddr CORE=n300 upload
  2067. **Expected output as below:**
  2068. .. code-block:: console
  2069. Nuclei SDK Build Time: Oct 18 2023, 18:45:02
  2070. Download Mode: ILM
  2071. CPU Frequency 15996682 Hz
  2072. CPU HartID: 0
  2073. Stack's top high address: 0x90010000, stack's bottom low address: 0x9000fa00, stack size: 0x600
  2074. --------OVERFLOW CHECK MODE--------
  2075. BOUND register set to: 0x9000fa00
  2076. BASE register set to: 0x90010000
  2077. Stack overflow fault occurs at iteration 84, cause: 0x30000018, epc: 0x80000e90, sp: 0x9000f990
  2078. --------UNDERFLOW CHECK MODE--------
  2079. BASE register set to: 0x9000fd00
  2080. Stack underflow fault occurs at iteration 1, cause: 0x30000019, epc: 0x80000fd0, sp: 0x9000fd00
  2081. BASE register set to: 0x90010000
  2082. --------TRACK SP MODE--------
  2083. BOUND register set to: 0x90010000
  2084. Iterations: 1, stack bound: 0x9000fdc0
  2085. Iterations: 2, stack bound: 0x9000fd70
  2086. Iterations: 3, stack bound: 0x9000fd20
  2087. Iterations: 4, stack bound: 0x9000fcd0
  2088. Iterations: 5, stack bound: 0x9000fc80
  2089. Iterations: 6, stack bound: 0x9000fc30
  2090. Iterations: 7, stack bound: 0x9000fbe0
  2091. Iterations: 8, stack bound: 0x9000fb90
  2092. Iterations: 9, stack bound: 0x9000fb40
  2093. Iterations: 10, stack bound: 0x9000faf0
  2094. Iterations: 11, stack bound: 0x9000faa0
  2095. Iterations: 12, stack bound: 0x9000fa50
  2096. Iterations: 13, stack bound: 0x9000fa00
  2097. Iterations: 14, stack bound: 0x9000f9b0
  2098. Iterations: 15, stack bound: 0x9000f960
  2099. Iterations: 16, stack bound: 0x9000f910
  2100. Iterations: 17, stack bound: 0x9000f8c0
  2101. Iterations: 18, stack bound: 0x9000f870
  2102. Calculate factorial over, the max stack used downwards to: 0x9000f820
  2103. Rerun it. The BOUND won't track sp if sp is bigger:
  2104. Iterations: 1, stack bound: 0x9000f820
  2105. Iterations: 2, stack bound: 0x9000f820
  2106. Iterations: 3, stack bound: 0x9000f820
  2107. Iterations: 4, stack bound: 0x9000f820
  2108. Iterations: 5, stack bound: 0x9000f820
  2109. Stack check demo over!
  2110. .. _design_app_demo_pma:
  2111. demo_pma
  2112. ~~~~~~~~
  2113. This `demo_pma application`_ is used to demonstrate how to set memory region to different attribute(``Device``/``Non-Cacheable``/``Cacheable``)
  2114. .. note::
  2115. * PMA are split into three attributes: ``Device``/``Cacheable``/``Non-Cacheable``, which correspondingly the whole memory region are split into
  2116. * Take care to set the region type and address range, which maybe causing function or performance issue!
  2117. * ``NMSIS/Core/Include/core_feature_pma.h`` provides apis like ``PMA_DisableHwXXRegion``, ``PMA_EnableHwXXRegion`` to disable/enable
  2118. hardware-defined regions, but please take care to use it, because maybe the region you disable will go to ``Device``
  2119. (maybe covered by another bigger-range ``Device`` region!), then instruction fetch exception happens!
  2120. * Observe cycles taken when executing same task ``array_read_by_row``(read from ``array_test``, update into ``array_test_r``) by changing the same memory region to ``Non-Cacheable``/``Cacheable``
  2121. * Struct ``PMA_CONFIG`` is used to assign PMA, which consists of ``region_type`` ``region_base`` ``region_size`` ``region_enable``
  2122. * ``region_type`` could be ``PMA_REGION_TYPE_SECSHARE``, ``PMA_REGION_TYPE_NC``, ``PMA_REGION_TYPE_DEV``, ``PMA_REGION_TYPE_CA``
  2123. * ``region_base`` is base physical address, which needs to be 4K byte aligned
  2124. * ``region_size`` needs to be 4K byte aligned; the ``region_base`` should be integer multiples of ``region_size``
  2125. * ``region_enable`` enable(1) or disable(0) the region, could be ``PMA_REGION_ENA``, ``PMA_REGION_DIS``
  2126. * After ``pma_cfg`` is assigned, and give the ``entry_idx``, call ``PMA_SetRegion`` to take effect
  2127. * The ``entry_idx`` (0-n) depends on number of paired ``mattri(n)_mask`` and ``mattri(n)_base``, refer to Nuclei ISA specifications for max region entries
  2128. * The api will do aligning by 4KB(because region granularity is 4KB) to ``region_base`` and ``region_size`` forcely
  2129. * The regions can be overlapped as the priority: ``Non-Cacheable`` > ``Cacheable`` > ``Device``, , but especially be careful not to
  2130. overlap software's instruction/data sections by Device, or overlap Device(like uart) memory by Cacheable
  2131. * ``PMA_GetRegion`` could retrieve the region info detail
  2132. **How to run this application:**
  2133. .. code-block:: shell
  2134. # Assume that you can set up the Tools and Nuclei SDK environment
  2135. # Use Nuclei ux900 Core RISC-V processor as example
  2136. # cd to the demo_pma directory
  2137. cd application/baremetal/demo_pma
  2138. # Clean the application first
  2139. make SOC=evalsoc BOARD=nuclei_fpga_eval CORE=ux900 DOWNLOAD=sram CCM_EN=1 clean
  2140. # Build and upload the application
  2141. make SOC=evalsoc BOARD=nuclei_fpga_eval CORE=ux900 DOWNLOAD=sram CCM_EN=1 upload
  2142. **Expected output as below:**
  2143. .. code-block:: console
  2144. Nuclei SDK Build Time: May 23 2025, 15:02:30
  2145. Download Mode: SRAM
  2146. CPU Frequency 50005606 Hz
  2147. CPU HartID: 0
  2148. DCache Linesize is 64 bytes, ways is 2, setperway is 512, total size is 65536 bytes
  2149. array_test size: 64 * 64 bytes, addr: 0xa0013000
  2150. Set to NonCacheable region
  2151. Region type: 0x4,region base addr: 0xa0013000, region size: 0x1000, region status: 1
  2152. HPM4:0xf0000021, array_read_by_row_dcache_miss_noncacheable, 64
  2153. Set to Cacheable region
  2154. Region type: 0x0,region base addr: 0xa0013000, region size: 0x1000, region status: 1
  2155. HPM4:0xf0000021, array_read_by_row_dcache_miss_cacheable, 128
  2156. From output, considering ``array_read_by_row_dcache_miss_noncacheable`` counting the common part cache miss including ``array_test_r`` which belongs to Cacheable.
  2157. So ``array_read_by_row_dcache_miss_cacheable`` minus ``array_read_by_row_dcache_miss_noncacheable``, we get exactly the cache miss(here is the row number 64) that
  2158. ``array_test`` brings in Cacheable region, and it demonstrates ``array_test`` brings no cache miss in NonCacheable region as expected.
  2159. .. note::
  2160. * In Nuclei Evalsoc core ux900 for example, the sram/ddr memory locates originally in hardware-defined Cacheable region(which configured by rtl configuration stage),
  2161. So this demo first covers original attribute by ``NonCacheable``, then ``Cacheable`` (that's recovered)
  2162. * As the prority: ``Non-Cacheable`` > ``Cacheable`` > ``Device``, it can't cover original attribute(``Cacheable``) by ``Device``!
  2163. .. _design_app_demo_smpcc:
  2164. demo_smpcc
  2165. ~~~~~~~~~~
  2166. This `demo_smpcc application`_ is used to demonstrate how to fetch SMP-related information, how to use
  2167. cluster cache as cluster-local memory, and how to monitor cluster cache performance metrics (cache hit/miss rates, etc.)
  2168. This demo can be divided into 4 parts:
  2169. - **Part1**: Fetch SMP-related information
  2170. - **Part2**: Perform memory traversal on continuous DDR memory and calculate the consumed cycles.
  2171. Compare performance with and without Cluster Cache enabled.
  2172. - **Part3**: Configure a portion of Cluster Cache as CLM (Cluster Local Memory),
  2173. and perform the same memory traversal test on CLM.
  2174. - **Part4**: Calculate the hit and miss counts for the cluster cache during memory traversal.
  2175. .. note::
  2176. * We declare an array to perform memory traversal tests, and the array size is related to the cluster cache size.
  2177. The default max cluster cache size is 1MB; if your CPU cache is larger than 1MB, you should pass ``MAX_L2_SIZE_KB`` to adjust.
  2178. **How to run this application:**
  2179. .. code-block:: shell
  2180. # Assume that you can set up the Tools and Nuclei SDK environment
  2181. # Use Nuclei ux900 Core RISC-V processor as example
  2182. # And assume that the L2 cache of your CPU in not larger than 1MB
  2183. # cd to the demo_smpcc directory
  2184. cd application/baremetal/demo_smpcc
  2185. # Clean the application first
  2186. make SOC=evalsoc BOARD=nuclei_fpga_eval CORE=ux900 DOWNLOAD=ddr CCM_EN=1 clean
  2187. # Build and upload the application
  2188. make SOC=evalsoc BOARD=nuclei_fpga_eval CORE=ux900 DOWNLOAD=ddr CCM_EN=1 upload
  2189. # If the L2 cache size is larger than 1MB, you can pass the ``MAX_L2_SIZE_KB`` make variable in the make command
  2190. # e.g., to set the L2 cache size to 2MB
  2191. make SOC=evalsoc BOARD=nuclei_fpga_eval CORE=ux900 DOWNLOAD=ddr CCM_EN=1 MAX_L2_SIZE_KB=2048 all
  2192. **Expected output as below:**
  2193. Here is the result run on legacy Nuclei UX900 Core.
  2194. .. code-block:: console
  2195. Nuclei SDK Build Time: Dec 24 2025, 17:18:43
  2196. Download Mode: DDR
  2197. CPU Frequency 50001346 Hz
  2198. CPU HartID: 0
  2199. SMPCC version is 1.0.1
  2200. SMP & Cluster Cache Information:
  2201. SMP_CFG: CC_PRESENT=1 SMP_NUM=1 IOCP_NUM=0 PMON_NUM=4
  2202. L2CACHE: 2 MB(set=2048,way=16,lsize=64,ecc=0)
  2203. CSV, mem_traverse_wo_ccache, 188078
  2204. CSV, mem_traverse_with_ccache, 102482
  2205. CSV, mem_traverse_with_clm, 102504
  2206. Test with CCache flushed:
  2207. CSV, Data Read Count, 8194
  2208. CSV, Data Read Hit Count, 0
  2209. CSV, Data Read Miss Count, 8194
  2210. Test with CCache pre-filled:
  2211. CSV, Data Read Count, 8194
  2212. CSV, Data Read Hit Count, 8194
  2213. CSV, Data Read Miss Count, 0
  2214. End of SMPCC demo!
  2215. For the result run on recent Nuclei UX900 Core, L2 cache performance
  2216. has been monitored by PMUv2, the output is as below:
  2217. .. code-block:: console
  2218. Nuclei SDK Build Time: Dec 26 2025, 18:13:43
  2219. Download Mode: DDR
  2220. CPU Frequency 50322800 Hz
  2221. CPU HartID: 0
  2222. SMPCC version is 1.0.1
  2223. SMP & Cluster Cache Information:
  2224. SMP_CFG: CC_PRESENT=1 SMP_NUM=1 IOCP_NUM=0 PMON_NUM=4
  2225. L2CACHE: 2 MB(set=2048,way=16,lsize=64,ecc=1)
  2226. CSV, mem_traverse_wo_ccache, 149901
  2227. CSV, mem_traverse_with_ccache, 103487
  2228. CSV, mem_traverse_with_clm, 103523
  2229. Cluster Cache performance has been monitored by PMUv2!
  2230. High performance monitor initialized
  2231. Test with L2 Cache flushed:
  2232. HPM4:0xf00000b3, L2_read_miss, 8192
  2233. HPM3:0xf00000a3, L2_read_count, 8217
  2234. Test with L2 Cache pre-filled:
  2235. HPM4:0xf00000b3, L2_read_miss, 1
  2236. HPM3:0xf00000a3, L2_read_count, 8215
  2237. End of SMPCC demo!
  2238. .. _design_app_demo_ecc:
  2239. demo_ecc
  2240. ~~~~~~~~
  2241. This `demo_ecc application`_ demonstrates the ECC functionality of Nuclei RISC-V CPUs.
  2242. The ECC functionality supports detection and correction of single-bit errors, and raises an exception when a double-bit
  2243. error is detected. When error bits are 3 or more, the result is not guaranteed.
  2244. This demo tests different memory types based on the ``DOWNLOAD`` parameter in the ``make`` command. When ``DOWNLOAD=ilm``,
  2245. the demo tests ECC error injection on local memory; when ``DOWNLOAD=ddr`` or ``DOWNLOAD=sram``, the demo tests
  2246. ECC error injection on cache memory (L1 I/D Cache and L2 Cache if present).
  2247. **How to run this application:**
  2248. .. code-block:: shell
  2249. # Assume that you can set up the Tools and Nuclei SDK environment
  2250. # Use Nuclei ux900 Core RISC-V processor as example
  2251. # cd to the demo_ecc directory
  2252. cd application/baremetal/demo_ecc
  2253. # To inject ecc error into cache memory, you should test with DOWNLOAD=ddr or Download=sram
  2254. # Clean the application first
  2255. make SOC=evalsoc BOARD=nuclei_fpga_eval CORE=ux900 DOWNLOAD=ddr CCM_EN=1 clean
  2256. # Build and upload the application
  2257. make SOC=evalsoc BOARD=nuclei_fpga_eval CORE=ux900 DOWNLOAD=ddr CCM_EN=1 upload
  2258. # If you want to test ecc error injection on local memory, you should test with DOWNLOAD=ilm
  2259. make SOC=evalsoc BOARD=nuclei_fpga_eval CORE=ux900 DOWNLOAD=ilm upload
  2260. **Expected output as below:**
  2261. Here is the result when ``DOWNLOAD=ddr``. (The result of ``DOWNLOAD=sram`` is similar)
  2262. .. code-block:: console
  2263. Nuclei SDK Build Time: Jan 8 2026, 15:56:56
  2264. Download Mode: DDR
  2265. CPU Frequency 50322800 Hz
  2266. CPU HartID: 0
  2267. ECC supported:
  2268. ICache ECC: yes
  2269. DCache ECC: yes
  2270. ILM ECC: yes
  2271. DLM ECC: yes
  2272. CCache ECC: yes
  2273. ECC single bit error has occured on ICache Data RAM!
  2274. ECC double bit error has occured on ICache Data RAM!
  2275. ECC single bit error has occured on ICache Tag RAM!
  2276. ECC double bit error has occured on ICache Tag RAM!
  2277. ECC single bit error has occured on DCache Data RAM!
  2278. ECC double bit error has occured on DCache Data RAM!
  2279. ECC single bit error has occured on DCache Tag RAM!
  2280. ECC double bit error has occured on DCache Tag RAM!
  2281. ECC single bit error has occured on CCache Data RAM!
  2282. ECC double bit error has occured on CCache Data RAM!
  2283. ECC single bit error has occured on CCache Tag RAM!
  2284. ECC double bit error has occured on CCache Tag RAM!
  2285. ECC demo passed.
  2286. Here is the result when ``DOWNLOAD=ilm``.
  2287. .. code-block:: console
  2288. Nuclei SDK Build Time: Jan 8 2026, 15:56:49
  2289. Download Mode: ILM
  2290. CPU Frequency 50322800 Hz
  2291. CPU HartID: 0
  2292. ECC supported:
  2293. ICache ECC: yes
  2294. DCache ECC: yes
  2295. ILM ECC: yes
  2296. DLM ECC: yes
  2297. CCache ECC: yes
  2298. ECC single bit error has occured on ILM!
  2299. ECC double bit error has occured on ILM!
  2300. ECC single bit error has occured on DLM!
  2301. ECC double bit error has occured on DLM!
  2302. ECC demo passed.
  2303. FreeRTOS applications
  2304. ---------------------
  2305. .. _design_app_freertos_demo:
  2306. demo
  2307. ~~~~
  2308. This `freertos demo application`_ is to show basic freertos task functions.
  2309. * Two freertos tasks are created
  2310. * A software timer is created
  2311. In Nuclei SDK, we provided code and Makefile for this ``freertos demo`` application.
  2312. * **RTOS = FreeRTOS** is added in its Makefile to include FreeRTOS service
  2313. * The **configTICK_RATE_HZ** in ``FreeRTOSConfig.h`` is set to 100, you can change it
  2314. to other number according to your requirement.
  2315. **How to run this application:**
  2316. .. code-block:: shell
  2317. # Assume that you can set up the Tools and Nuclei SDK environment
  2318. # cd to the freertos demo directory
  2319. cd application/freertos/demo
  2320. # Clean the application first
  2321. make SOC=gd32vf103 clean
  2322. # Build and upload the application
  2323. make SOC=gd32vf103 upload
  2324. **Expected output as below:**
  2325. .. code-block:: console
  2326. Nuclei SDK Build Time: Feb 21 2020, 14:56:00
  2327. Download Mode: FLASHXIP
  2328. CPU Frequency 109058823 Hz
  2329. Before StartScheduler
  2330. Enter to task_1
  2331. task1 is running 0.....
  2332. Enter to task_2
  2333. task2 is running 0.....
  2334. timers Callback 0
  2335. timers Callback 1
  2336. task1 is running 1.....
  2337. task2 is running 1.....
  2338. timers Callback 2
  2339. timers Callback 3
  2340. task1 is running 2.....
  2341. task2 is running 2.....
  2342. timers Callback 4
  2343. timers Callback 5
  2344. task1 is running 3.....
  2345. task2 is running 3.....
  2346. timers Callback 6
  2347. timers Callback 7
  2348. task1 is running 4.....
  2349. task2 is running 4.....
  2350. timers Callback 8
  2351. timers Callback 9
  2352. task1 is running 5.....
  2353. task2 is running 5.....
  2354. timers Callback 10
  2355. timers Callback 11
  2356. .. _design_app_freertos_smpdemo:
  2357. smpdemo
  2358. ~~~~~~~
  2359. This `freertos smpdemo application`_ is to show basic freertos smp task functions.
  2360. * x freertos tasks(different priorities) are created if your cpu has x cores according to the ``SMP=x`` settings
  2361. * A software timer is created
  2362. * Need to run using **DOWNLOAD=sram** mode
  2363. In Nuclei SDK, we provided code and Makefile for this ``freertos smpdemo`` application.
  2364. * **RTOS = FreeRTOS** is added in its Makefile to include FreeRTOS service
  2365. * The **configTICK_RATE_HZ** in ``FreeRTOSConfig.h`` is set to 100, you can change it
  2366. to other number according to your requirement.
  2367. **How to run this application:**
  2368. .. code-block:: shell
  2369. # Assume that you can set up the Tools and Nuclei SDK environment
  2370. # cd to the freertos demo directory
  2371. cd application/freertos/smpdemo
  2372. # This need to run on NX900 SMPx2 CPU
  2373. # Clean the application first
  2374. make clean
  2375. # Build and upload the application
  2376. make upload
  2377. **Expected output as below:**
  2378. .. code-block:: console
  2379. Nuclei SDK Build Time: May 28 2024, 13:17:41
  2380. Download Mode: SRAM
  2381. CPU Frequency 50322800 Hz
  2382. CPU HartID: 0
  2383. Startup FreeRTOS SMP on hartid 0
  2384. Enter to task 1
  2385. task 1 prio 1 is running 0 on hart 0.....
  2386. Enter to task 0
  2387. task 0 prio 0 is running 0 on hart 0.....
  2388. task 1 prio 1 is running 1 on hart 1.....
  2389. task 0 prio 0 is running 1 on hart 0.....
  2390. task 1 prio 1 is running 2 on hart 1.....
  2391. task 0 prio 0 is running 2 on hart 0.....
  2392. task 1 prio 1 is running 3 on hart 1.....
  2393. task 0 prio 0 is running 3 on hart 0.....
  2394. task 1 prio 1 is running 4 on hart 1.....
  2395. task 0 prio 0 is running 4 on hart 0.....
  2396. task 1 prio 1 is running 5 on hart 0.....
  2397. timers Callback 0 on hart 1
  2398. task 0 prio 0 is running 5 on hart 1.....
  2399. task 1 prio 1 is running 6 on hart 1.....
  2400. task 0 prio 0 is running 6 on hart 0.....
  2401. task 1 prio 1 is running 7 on hart 1.....
  2402. task 0 prio 0 is running 7 on hart 0.....
  2403. task 1 prio 1 is running 8 on hart 1.....
  2404. task 0 prio 0 is running 8 on hart 0.....
  2405. task 1 prio 1 is running 9 on hart 1.....
  2406. task 0 prio 0 is running 9 on hart 0.....
  2407. task 1 prio 1 is running 10 on hart 0.....
  2408. timers Callback 1 on hart 1
  2409. UCOSII applications
  2410. -------------------
  2411. .. _design_app_ucosii_demo:
  2412. demo
  2413. ~~~~
  2414. This `ucosii demo application`_ is show basic ucosii task functions.
  2415. * 4 tasks are created
  2416. * 1 task is created first, and then create 3 other tasks and then suspend itself
  2417. In Nuclei SDK, we provided code and Makefile for this ``ucosii demo`` application.
  2418. * **RTOS = UCOSII** is added in its Makefile to include UCOSII service
  2419. * The **OS_TICKS_PER_SEC** in ``os_cfg.h`` is by default set to 50, you can change it
  2420. to other number according to your requirement.
  2421. .. note:
  2422. * For Nuclei SDK release > v0.2.2, the UCOSII source code is replaced using the
  2423. version from https://github.com/SiliconLabs/uC-OS2/, and application development
  2424. for UCOSII is also changed, the ``app_cfg.h``, ``os_cfg.h`` and ``app_hooks.c`` files
  2425. are required in application source code.
  2426. **How to run this application:**
  2427. .. code-block:: shell
  2428. # Assume that you can set up the Tools and Nuclei SDK environment
  2429. # cd to the ucosii demo directory
  2430. cd application/ucosii/demo
  2431. # Clean the application first
  2432. make SOC=gd32vf103 clean
  2433. # Build and upload the application
  2434. make SOC=gd32vf103 upload
  2435. **Expected output as below:**
  2436. .. code-block:: console
  2437. Nuclei SDK Build Time: Feb 21 2020, 15:00:35
  2438. Download Mode: FLASHXIP
  2439. CPU Frequency 108524271 Hz
  2440. Start ucosii...
  2441. create start task success
  2442. start all task...
  2443. task3 is running... 1
  2444. task2 is running... 1
  2445. task1 is running... 1
  2446. task3 is running... 2
  2447. task2 is running... 2
  2448. task3 is running... 3
  2449. task2 is running... 3
  2450. task1 is running... 2
  2451. task3 is running... 4
  2452. task2 is running... 4
  2453. task3 is running... 5
  2454. task2 is running... 5
  2455. task1 is running... 3
  2456. task3 is running... 6
  2457. task2 is running... 6
  2458. task3 is running... 7
  2459. task2 is running... 7
  2460. task1 is running... 4
  2461. task3 is running... 8
  2462. task2 is running... 8
  2463. task3 is running... 9
  2464. task2 is running... 9
  2465. task1 is running... 5
  2466. task3 is running... 10
  2467. task2 is running... 10
  2468. task3 is running... 11
  2469. task2 is running... 11
  2470. task1 is running... 6
  2471. task3 is running... 12
  2472. task2 is running... 12
  2473. RT-Thread applications
  2474. ----------------------
  2475. .. _design_app_rtthread_demo:
  2476. demo
  2477. ~~~~
  2478. This `rt-thread demo application`_ is show basic rt-thread thread functions.
  2479. * main function is a pre-created thread by RT-Thread
  2480. * main thread will create 5 test threads using the same function ``thread_entry``
  2481. In Nuclei SDK, we provided code and Makefile for this ``rtthread demo`` application.
  2482. * **RTOS = RTThread** is added in its Makefile to include RT-Thread service
  2483. * The **RT_TICK_PER_SECOND** in ``rtconfig.h`` is by default set to `100`, you can change it
  2484. to other number according to your requirement.
  2485. **How to run this application:**
  2486. .. code-block:: shell
  2487. # Assume that you can set up the Tools and Nuclei SDK environment
  2488. # cd to the rtthread demo directory
  2489. cd application/rtthread/demo
  2490. # Clean the application first
  2491. make SOC=gd32vf103 clean
  2492. # Build and upload the application
  2493. make SOC=gd32vf103 upload
  2494. **Expected output as below:**
  2495. .. code-block:: console
  2496. Nuclei SDK Build Time: Apr 14 2020, 10:14:30
  2497. Download Mode: FLASHXIP
  2498. CPU Frequency 108270000 Hz
  2499. \ | /
  2500. - RT - Thread Operating System
  2501. / | \ 3.1.3 build Apr 14 2020
  2502. 2006 - 2019 Copyright by rt-thread team
  2503. Main thread count: 0
  2504. thread 0 count: 0
  2505. thread 1 count: 0
  2506. thread 2 count: 0
  2507. thread 3 count: 0
  2508. thread 4 count: 0
  2509. thread 0 count: 1
  2510. thread 1 count: 1
  2511. thread 2 count: 1
  2512. thread 3 count: 1
  2513. thread 4 count: 1
  2514. Main thread count: 1
  2515. thread 0 count: 2
  2516. thread 1 count: 2
  2517. thread 2 count: 2
  2518. thread 3 count: 2
  2519. thread 4 count: 2
  2520. thread 0 count: 3
  2521. thread 1 count: 3
  2522. thread 2 count: 3
  2523. thread 3 count: 3
  2524. thread 4 count: 3
  2525. Main thread count: 2
  2526. thread 0 count: 4
  2527. thread 1 count: 4
  2528. .. _design_app_rtthread_msh:
  2529. msh
  2530. ~~~
  2531. This `rt-thread msh application`_ demonstrates msh shell in serial console which is a component of rt-thread.
  2532. * ``MSH_CMD_EXPORT(nsdk, msh nuclei sdk demo)`` exports a command ``nsdk`` to msh shell
  2533. In Nuclei SDK, we provided code and Makefile for this ``rtthread msh`` application.
  2534. * **RTOS = RTThread** is added in its Makefile to include RT-Thread service
  2535. * **RTTHREAD_MSH := 1** is added in its Makefile to include RT-Thread msh component
  2536. * The **RT_TICK_PER_SECOND** in ``rtconfig.h`` is by default set to `100`, you can change it
  2537. to other number according to your requirement.
  2538. * To run this application in :ref:`design_soc_evalsoc`, the SoC clock frequency must be above 16MHz,
  2539. if run in 8MHz, uart read is not correct due to bit error in uart rx process.
  2540. **How to run this application:**
  2541. .. code-block:: shell
  2542. # Assume that you can set up the Tools and Nuclei SDK environment
  2543. # cd to the rtthread msh directory
  2544. cd application/rtthread/msh
  2545. # Clean the application first
  2546. make SOC=gd32vf103 clean
  2547. # Build and upload the application
  2548. make SOC=gd32vf103 upload
  2549. **Expected output as below:**
  2550. .. code-block:: console
  2551. Nuclei SDK Build Time: Dec 23 2020, 16:39:21
  2552. Download Mode: FLASHXIP
  2553. CPU Frequency 108810000 Hz
  2554. \ | /
  2555. - RT - Thread Operating System
  2556. / | \ 3.1.3 build Dec 23 2020
  2557. 2006 - 2019 Copyright by rt-thread team
  2558. Hello RT-Thread!
  2559. msh >help
  2560. RT-Thread shell commands:
  2561. list_timer - list timer in system
  2562. list_mailbox - list mail box in system
  2563. list_sem - list semaphore in system
  2564. list_thread - list thread
  2565. version - show RT-Thread version information
  2566. ps - List threads in the system.
  2567. help - RT-Thread shell help.
  2568. nsdk - msh nuclei sdk demo
  2569. msh >ps
  2570. thread pri status sp stack size max used left tick error
  2571. -------- --- ------- ---------- ---------- ------ ---------- ---
  2572. tshell 6 ready 0x00000178 0x00001000 09% 0x00000008 000
  2573. tidle 7 ready 0x00000078 0x0000018c 30% 0x00000020 000
  2574. main 2 suspend 0x000000b8 0x00000200 35% 0x00000013 000
  2575. msh >nsdk
  2576. Hello Nuclei SDK!
  2577. msh >
  2578. .. _design_app_rtthread_demo_smode:
  2579. demo_smode
  2580. ~~~~~~~~~~
  2581. This `rt-thread demo smode application`_ is show how to use rt-thread in S-Mode.
  2582. It is similar to the normal rt-thread demo, but rt-thread itself is running in S-Mode,
  2583. so we have to do some PMP and TEE configuration in M-Mode before go to S-Mode.
  2584. The main feature required is the TEE, and SSTC is also preferred.
  2585. **How to run this application:**
  2586. .. code-block:: shell
  2587. # Assume that you can set up the Tools and Nuclei SDK environment
  2588. # cd to the rtthread demo_smode directory
  2589. cd application/rtthread/demo_smode
  2590. # Clean the application first
  2591. # Assume you are using n300
  2592. make SOC=evalsoc CORE=n300 clean
  2593. # Build and upload the application
  2594. make SOC=evalsoc CORE=n300 upload
  2595. **Expected output as below:**
  2596. .. code-block:: console
  2597. Nuclei SDK Build Time: Feb 21 2025, 11:12:24
  2598. Download Mode: ILM
  2599. CPU Frequency 16005857 Hz
  2600. CPU HartID: 0
  2601. Set ECLIC Timer S-Mode Interrupt and Software Timer S-Mode Interrupt to be executed in S-Mode
  2602. Drop to S-Mode to prepare RT-Thread Environment
  2603. \ | /
  2604. - RT - Thread Operating System
  2605. / | \ 3.1.5 build Feb 21 2025
  2606. 2006 - 2020 Copyright by rt-thread team
  2607. Main thread count: 0
  2608. thread 0 count: 0
  2609. thread 1 count: 0
  2610. thread 2 count: 0
  2611. thread 3 count: 0
  2612. thread 4 count: 0
  2613. thread 0 count: 1
  2614. thread 1 count: 1
  2615. thread 2 count: 1
  2616. thread 3 count: 1
  2617. thread 4 count: 1
  2618. Main thread count: 1
  2619. thread 0 count: 2
  2620. thread 1 count: 2
  2621. thread 2 count: 2
  2622. thread 3 count: 2
  2623. thread 4 count: 2
  2624. thread 0 count: 3
  2625. thread 1 count: 3
  2626. thread 2 count: 3
  2627. thread 3 count: 3
  2628. thread 4 count: 3
  2629. Main thread count: 2
  2630. ThreadX applications
  2631. --------------------
  2632. .. _design_app_threadx_demo:
  2633. demo
  2634. ~~~~
  2635. This `threadx demo application`_ is show basic ThreadX thread functions.
  2636. This threadx demo is modified based on https://github.com/eclipse-threadx/threadx/blob/v6.4.1_rel/samples/demo_threadx.c
  2637. In Nuclei SDK, we provided code and Makefile for this ``threadx demo`` application.
  2638. * **RTOS = ThreadX** is added in its Makefile to include ThreadX service
  2639. * The **TX_INCLUDE_USER_DEFINE_FILE** macro is defined in Makefile, so you can include customized user configuration
  2640. file ``tx_user.h``
  2641. **How to run this application:**
  2642. .. code-block:: shell
  2643. # Assume that you can set up the Tools and Nuclei SDK environment
  2644. # cd to the threadx demo directory
  2645. cd application/threadx/demo
  2646. # Clean the application first
  2647. make SOC=evalsoc clean
  2648. # Build and upload the application
  2649. make SOC=evalsoc upload
  2650. **Expected output as below:**
  2651. .. code-block:: console
  2652. Nuclei SDK Build Time: May 28 2024, 13:26:41
  2653. Download Mode: ILM
  2654. CPU Frequency 50322800 Hz
  2655. CPU HartID: 0
  2656. thread 6_7 is running, current is 6, thread 6 counter 1, thread 7 counter 1
  2657. thread 6_7 is running, current is 7, thread 6 counter 2, thread 7 counter 1
  2658. thread 6_7 is running, current is 6, thread 6 counter 2, thread 7 counter 2
  2659. thread 6_7 is running, current is 7, thread 6 counter 3, thread 7 counter 2
  2660. thread 6_7 is running, current is 6, thread 6 counter 3, thread 7 counter 3
  2661. thread 6_7 is running, current is 7, thread 6 counter 4, thread 7 counter 3
  2662. thread 6_7 is running, current is 6, thread 6 counter 4, thread 7 counter 4
  2663. thread 6_7 is running, current is 7, thread 6 counter 5, thread 7 counter 4
  2664. .. _design_app_threadx_smpdemo:
  2665. smpdemo
  2666. ~~~~~~~
  2667. This `threadx smpdemo application`_ is show basic ThreadX-SMP thread functions.
  2668. This threadx smp demo is modified based on https://github.com/eclipse-threadx/threadx/blob/v6.4.1_rel/ports_smp/linux/gnu/example_build/sample_threadx.c
  2669. In Nuclei SDK, we provided code and Makefile for this ``threadx smpdemo`` application to demostrate ThreadX SMP Kernel ability.
  2670. * **RTOS = ThreadX** is added in its Makefile to include ThreadX service
  2671. * **SMP := 2**: it can be 2 or other smp cpu count number, such as 4, 8, etc.
  2672. **TX_THREAD_SMP_MAX_CORES** in ``OS/ThreadX/ports_smp/nuclei/tx_port.h`` will use this ``SMP_CPU_CNT`` defined via ``SoC/evalsoc/build.mk``
  2673. to control threadx smp max core numbers.
  2674. * The **TX_INCLUDE_USER_DEFINE_FILE** macro is defined in Makefile, so you can include customized user configuration
  2675. file ``tx_user.h``
  2676. **How to run this application:**
  2677. .. code-block:: shell
  2678. # Assume that you can set up the Tools and Nuclei SDK environment
  2679. # cd to the threadx smpdemo directory
  2680. cd application/threadx/smpdemo
  2681. # by default, it required ux900fd SMPx2 CPU with ECLIC
  2682. # Clean the application first
  2683. make SOC=evalsoc clean
  2684. # Build and upload the application
  2685. make SOC=evalsoc upload
  2686. **Expected output as below:**
  2687. .. code-block:: console
  2688. Nuclei SDK Build Time: Dec 9 2025, 15:31:52
  2689. Download Mode: SRAM
  2690. CPU Frequency 50330009 Hz
  2691. CPU HartID: 0
  2692. **** ThreadX SMP Linux Demonstration **** (c) 1996-2020 Microsoft Corporation
  2693. thread 0 events sent 1, thread 0 cpu 0
  2694. thread 1 messages sent: 1035, thread 1 cpu 1
  2695. thread 2 messages received: 1530, thread 2 cpu 1
  2696. thread 3 obtained semaphore: 2, thread 3 cpu 1
  2697. thread 4 obtained semaphore: 1, thread 4 cpu 1
  2698. thread 5 events received: 1, thread 5 cpu 1
  2699. thread 6 mutex obtained: 2, thread 6 cpu 1
  2700. thread 7 mutex obtained: 2, thread 7 cpu 1
  2701. **** ThreadX SMP Linux Demonstration **** (c) 1996-2020 Microsoft Corporation
  2702. thread 0 events sent 2, thread 0 cpu 0
  2703. thread 1 messages sent: 10110, thread 1 cpu 1
  2704. thread 2 messages received: 10597, thread 2 cpu 1
  2705. thread 3 obtained semaphore: 5, thread 3 cpu 1
  2706. thread 4 obtained semaphore: 5, thread 4 cpu 1
  2707. thread 5 events received: 2, thread 5 cpu 1
  2708. thread 6 mutex obtained: 6, thread 6 cpu 1
  2709. thread 7 mutex obtained: 5, thread 7 cpu 1
  2710. **** ThreadX SMP Linux Demonstration **** (c) 1996-2020 Microsoft Corporation
  2711. thread 0 events sent 3, thread 0 cpu 1
  2712. thread 1 messages sent: 19285, thread 1 cpu 0
  2713. thread 2 messages received: 19719, thread 2 cpu 0
  2714. thread 3 obtained semaphore: 9, thread 3 cpu 0
  2715. thread 4 obtained semaphore: 9, thread 4 cpu 0
  2716. thread 5 events received: 3, thread 5 cpu 0
  2717. thread 6 mutex obtained: 10, thread 6 cpu 0
  2718. thread 7 mutex obtained: 9, thread 7 cpu 0
  2719. **** ThreadX SMP Linux Demonstration **** (c) 1996-2020 Microsoft Corporation
  2720. thread 0 events sent 4, thread 0 cpu 0
  2721. thread 1 messages sent: 28358, thread 1 cpu 1
  2722. thread 2 messages received: 28817, thread 2 cpu 1
  2723. thread 3 obtained semaphore: 13, thread 3 cpu 1
  2724. thread 4 obtained semaphore: 13, thread 4 cpu 1
  2725. thread 5 events received: 4, thread 5 cpu 1
  2726. thread 6 mutex obtained: 13, thread 6 cpu 1
  2727. thread 7 mutex obtained: 13, thread 7 cpu 1
  2728. .. _helloworld application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/helloworld
  2729. .. _cpuinfo application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/cpuinfo
  2730. .. _demo_timer application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_timer
  2731. .. _demo_clint_timer application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_clint_timer
  2732. .. _demo_eclic application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_eclic
  2733. .. _demo_eclic_stress application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_eclic_stress
  2734. .. _demo_plic application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_plic
  2735. .. _demo_dsp application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_dsp
  2736. .. _smphello application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/smphello
  2737. .. _lowpower application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/lowpower
  2738. .. _demo_nice application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_nice
  2739. .. _demo_vnice application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_vnice
  2740. .. _coremark benchmark application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/benchmark/coremark
  2741. .. _dhrystone benchmark application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/benchmark/dhrystone
  2742. .. _dhrystone_v2.2 benchmark application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/benchmark/dhrystone_v2.2
  2743. .. _whetstone benchmark application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/benchmark/whetstone
  2744. .. _whetstone_v1.2 benchmark application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/benchmark/whetstone_v1.2
  2745. .. _freertos demo application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/freertos/demo
  2746. .. _freertos smpdemo application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/freertos/smpdemo
  2747. .. _ucosii demo application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/ucosii/demo
  2748. .. _rt-thread demo application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/rtthread/demo
  2749. .. _rt-thread demo smode application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/rtthread/demo_smode
  2750. .. _rt-thread msh application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/rtthread/msh
  2751. .. _threadx demo application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/threadx/demo
  2752. .. _threadx smpdemo application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/threadx/smpdemo
  2753. .. _demo_smode_eclic application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_smode_eclic
  2754. .. _demo_eclic_umode application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_eclic_umode
  2755. .. _demo_smode_plic application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_smode_plic
  2756. .. _demo_sstc application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_sstc
  2757. .. _demo_spmp application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_spmp
  2758. .. _demo_smpu application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_smpu
  2759. .. _demo_pmp application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_pmp
  2760. .. _demo_profiling application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_profiling
  2761. .. _demo_cidu application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_cidu
  2762. .. _demo_cache application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_cache
  2763. .. _demo_stack_check application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_stack_check
  2764. .. _demo_pma application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_pma
  2765. .. _demo_smpcc application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_smpcc
  2766. .. _demo_ecc application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_ecc
  2767. .. _Nuclei User Extended Introduction: https://doc.nucleisys.com/nuclei_spec/isa/nice.html