app.rst 104 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656
  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#nuclei-customized-features
  93. **How to run this application:**
  94. .. code-block:: shell
  95. # Assume that you can set up the Tools and Nuclei SDK environment
  96. # cd to the helloworld directory
  97. cd application/baremetal/cpuinfo
  98. # Assume to run on UX900 SMPx8 CPU
  99. # Clean the application first
  100. make SOC=evalsoc DOWNLOAD=sram clean
  101. # Build and upload the application
  102. make SOC=evalsoc DOWNLOAD=sram upload
  103. **Expected output as below:**
  104. .. code-block:: console
  105. Nuclei SDK Build Time: May 28 2024, 13:36:12
  106. Download Mode: SRAM
  107. CPU Frequency 50322800 Hz
  108. CPU HartID: 0
  109. -----Nuclei RISC-V CPU Configuration Information-----
  110. MARCHID: 0x900
  111. MIMPID: 0x30900
  112. ISA: RV64 A B C D F I M S U Zc Xxlcz
  113. MCFG: ECLIC PLIC ICACHE DCACHE SMP ZC_XLCZ_EXT IREGION No-Safety-Mechanism DLEN=VLEN/2
  114. ICACHE: 64 KB(set=512,way=2,lsize=64,ecc=0)
  115. DCACHE: 64 KB(set=512,way=2,lsize=64,ecc=0)
  116. TLB: MainTLB(set=256,way=4,entry=1,ecc=0) ITLB(entry=16) DTLB(entry=16)
  117. IREGION: 0x18000000 128 MB
  118. Unit Size Address
  119. INFO 64KB 0x18000000
  120. DEBUG 64KB 0x18010000
  121. ECLIC 64KB 0x18020000
  122. TIMER 64KB 0x18030000
  123. SMP 64KB 0x18040000
  124. CIDU 64KB 0x18050000
  125. PLIC 64MB 0x1c000000
  126. SMP_CFG: CC_PRESENT=1 SMP_CORE_NUM=7 IOCP_NUM=0 PMON_NUM=4
  127. ECLIC: VERSION=0x0 NUM_INTERRUPT=71 CLICINTCTLBITS=3 MTH=0 NLBITS=3
  128. L2CACHE: 2 MB(set=2048,way=16,lsize=64,ecc=0)
  129. INFO-Detail:
  130. mpasize : 32
  131. -----End of Nuclei CPU INFO-----
  132. .. _design_app_demo_timer:
  133. demo_timer
  134. ~~~~~~~~~~
  135. This `demo_timer application`_ is used to demonstrate how to use
  136. the CORE TIMER API including the Timer Interrupt and Timer Software Interrupt in ECLIC interrupt mode.
  137. * Both interrupts are registered as non-vector interrupt.
  138. * First the timer interrupt will run for 5 times
  139. * Then the software timer interrupt will start to run for 5 times
  140. **How to run this application:**
  141. .. code-block:: shell
  142. # Assume that you can set up the Tools and Nuclei SDK environment
  143. # cd to the demo_timer directory
  144. cd application/baremetal/demo_timer
  145. # Clean the application first
  146. make SOC=gd32vf103 clean
  147. # Build and upload the application
  148. make SOC=gd32vf103 upload
  149. **Expected output as below:**
  150. .. code-block:: console
  151. Nuclei SDK Build Time: Feb 21 2020, 12:52:37
  152. Download Mode: FLASHXIP
  153. CPU Frequency 108794117 Hz
  154. init timer and start
  155. MTimer IRQ handler 1
  156. MTimer IRQ handler 2
  157. MTimer IRQ handler 3
  158. MTimer IRQ handler 4
  159. MTimer IRQ handler 5
  160. MTimer SW IRQ handler 1
  161. MTimer SW IRQ handler 2
  162. MTimer SW IRQ handler 3
  163. MTimer SW IRQ handler 4
  164. MTimer SW IRQ handler 5
  165. MTimer msip and mtip interrupt test finish and pass
  166. .. _design_app_demo_clint_timer:
  167. demo_clint_timer
  168. ~~~~~~~~~~~~~~~~
  169. This `demo_clint_timer application`_ is used to demonstrate how to use
  170. the CORE TIMER API including the Timer Interrupt and Timer Software Interrupt in CLINT interrupt mode.
  171. * Interrupt is set to working in CLINT interrupt mode
  172. * Both interrupts are registered as core interrupt.
  173. * First the timer interrupt will run for 5 times
  174. * Then the software timer interrupt will start to run for 5 times
  175. * **NOTE**: not able to working in qemu, and only works for evalsoc
  176. **How to run this application:**
  177. .. code-block:: shell
  178. # Assume that you can set up the Tools and Nuclei SDK environment
  179. # cd to the demo_timer directory
  180. cd application/baremetal/demo_clint_timer
  181. # Clean the application first
  182. make SOC=evalsoc clean
  183. # Build and upload the application
  184. make SOC=evalsoc upload
  185. **Expected output as below:**
  186. .. code-block:: console
  187. Nuclei SDK Build Time: Jul 25 2024, 10:39:39
  188. Download Mode: ILM
  189. CPU Frequency 16000614 Hz
  190. CPU HartID: 0
  191. init timer and start
  192. SysTimer IRQ handler 1
  193. SysTimer IRQ handler 2
  194. SysTimer IRQ handler 3
  195. SysTimer IRQ handler 4
  196. SysTimer IRQ handler 5
  197. SysTimer SW IRQ handler 1
  198. SysTimer SW IRQ handler 2
  199. SysTimer SW IRQ handler 3
  200. SysTimer SW IRQ handler 4
  201. SysTimer SW IRQ handler 5
  202. SysTimer MTIP and MSIP CLINT interrupt test finish and pass
  203. .. _design_app_demo_eclic:
  204. demo_eclic
  205. ~~~~~~~~~~
  206. This `demo_eclic application`_ is used to demonstrate how to use
  207. the ECLIC API and Interrupt is working in ECLIC interrupt mode.
  208. .. note::
  209. In this application's Makefile, we provided comments in Makefile about optimize
  210. for code size.
  211. If you want to optimize this application for code size, you can set the ``COMMON_FLAGS``
  212. variable to the following values, we recommend to use ``-Os -flto``.
  213. .. list-table:: Code size optimization for demo_eclic on RV-STAR target
  214. :widths: 60 20 20 20 20
  215. :header-rows: 1
  216. * - COMMON_FLAGS
  217. - text(bytes)
  218. - data(bytes)
  219. - bss(bytes)
  220. - total(bytes)
  221. * -
  222. - 13724
  223. - 112
  224. - 2266
  225. - 16102
  226. * - -flto
  227. - 13598
  228. - 112
  229. - 2266
  230. - 15976
  231. * - -Os
  232. - 9690
  233. - 112
  234. - 2264
  235. - 12066
  236. * - -Os -flto
  237. - 9132
  238. - 112
  239. - 2264
  240. - 11508
  241. * - -Os -msave-restore -fno-unroll-loops
  242. - 9714
  243. - 112
  244. - 2264
  245. - 12090
  246. * - -Os -msave-restore -fno-unroll-loops -flto
  247. - 9204
  248. - 112
  249. - 2264
  250. - 11580
  251. * The timer interrupt and timer software interrupt are used
  252. * The timer interrupt is registered as non-vector interrupt
  253. * The timer software interrupt is registered as vector interrupt,
  254. and we enable its preemptive feature by using ``SAVE_IRQ_CSR_CONTEXT``
  255. and ``RESTORE_IRQ_CSR_CONTEXT`` in timer software interrupt handler
  256. * The timer interrupt is triggered periodically
  257. * The timer software interrupt is triggered in timer interrupt handler using
  258. ``SysTimer_SetSWIRQ`` function
  259. * In the application code, there is a macro called ``SWIRQ_INTLEVEL_HIGHER`` to
  260. control the timer software interrupt working feature:
  261. - If **SWIRQ_INTLEVEL_HIGHER=1**, the timer software interrupt level is higher than
  262. timer interrupt level, so when timer software interrupt is triggered, then timer
  263. software interrupt will be processed immediately, and timer interrupt will be preempted
  264. by timer software interrupt.
  265. - If **SWIRQ_INTLEVEL_HIGHER=0**, the timer software interrupt level is lower than
  266. timer interrupt level, so when timer software interrupt is triggered, then timer
  267. software interrupt will be processed after timer interrupt, and timer interrupt will
  268. not be preempted by timer software interrupt.
  269. **How to run this application:**
  270. .. code-block:: shell
  271. # Assume that you can set up the Tools and Nuclei SDK environment
  272. # cd to the demo_eclic directory
  273. cd application/baremetal/demo_eclic
  274. # Change macro SWIRQ_INTLEVEL_HIGHER value in demo_eclic.c
  275. # to see different working mode of this demo
  276. # Clean the application first
  277. make SOC=gd32vf103 clean
  278. # Build and upload the application
  279. make SOC=gd32vf103 upload
  280. **Expected output(SWIRQ_INTLEVEL_HIGHER=1) as below:**
  281. .. code-block:: console
  282. Nuclei SDK Build Time: Feb 21 2020, 16:35:58
  283. Download Mode: FLASHXIP
  284. CPU Frequency 108794117 Hz
  285. Initialize timer and start timer interrupt periodically
  286. -------------------
  287. [IN TIMER INTERRUPT]timer interrupt hit 0 times
  288. [IN TIMER INTERRUPT]trigger software interrupt
  289. [IN TIMER INTERRUPT]software interrupt will run during timer interrupt
  290. [IN SOFTWARE INTERRUPT]software interrupt hit 0 times
  291. [IN SOFTWARE INTERRUPT]software interrupt end
  292. [IN TIMER INTERRUPT]timer interrupt end
  293. -------------------
  294. [IN TIMER INTERRUPT]timer interrupt hit 1 times
  295. [IN TIMER INTERRUPT]trigger software interrupt
  296. [IN TIMER INTERRUPT]software interrupt will run during timer interrupt
  297. [IN SOFTWARE INTERRUPT]software interrupt hit 1 times
  298. [IN SOFTWARE INTERRUPT]software interrupt end
  299. [IN TIMER INTERRUPT]timer interrupt end
  300. -------------------
  301. [IN TIMER INTERRUPT]timer interrupt hit 2 times
  302. [IN TIMER INTERRUPT]trigger software interrupt
  303. [IN TIMER INTERRUPT]software interrupt will run during timer interrupt
  304. [IN SOFTWARE INTERRUPT]software interrupt hit 2 times
  305. [IN SOFTWARE INTERRUPT]software interrupt end
  306. [IN TIMER INTERRUPT]timer interrupt end
  307. -------------------
  308. [IN TIMER INTERRUPT]timer interrupt hit 3 times
  309. [IN TIMER INTERRUPT]trigger software interrupt
  310. [IN TIMER INTERRUPT]software interrupt will run during timer interrupt
  311. [IN SOFTWARE INTERRUPT]software interrupt hit 3 times
  312. [IN SOFTWARE INTERRUPT]software interrupt end
  313. [IN TIMER INTERRUPT]timer interrupt end
  314. **Expected output(SWIRQ_INTLEVEL_HIGHER=0) as below:**
  315. .. code-block:: console
  316. Nuclei SDK Build Time: Feb 21 2020, 16:35:58
  317. Download Mode: FLASHXIP
  318. CPU Frequency 108794117 Hz
  319. Initialize timer and start timer interrupt periodically
  320. -------------------
  321. [IN TIMER INTERRUPT]timer interrupt hit 0 times
  322. [IN TIMER INTERRUPT]trigger software interrupt
  323. [IN TIMER INTERRUPT]software interrupt will run when timer interrupt finished
  324. [IN TIMER INTERRUPT]timer interrupt end
  325. [IN SOFTWARE INTERRUPT]software interrupt hit 0 times
  326. [IN SOFTWARE INTERRUPT]software interrupt end
  327. -------------------
  328. [IN TIMER INTERRUPT]timer interrupt hit 1 times
  329. [IN TIMER INTERRUPT]trigger software interrupt
  330. [IN TIMER INTERRUPT]software interrupt will run when timer interrupt finished
  331. [IN TIMER INTERRUPT]timer interrupt end
  332. [IN SOFTWARE INTERRUPT]software interrupt hit 1 times
  333. [IN SOFTWARE INTERRUPT]software interrupt end
  334. -------------------
  335. [IN TIMER INTERRUPT]timer interrupt hit 2 times
  336. [IN TIMER INTERRUPT]trigger software interrupt
  337. [IN TIMER INTERRUPT]software interrupt will run when timer interrupt finished
  338. [IN TIMER INTERRUPT]timer interrupt end
  339. [IN SOFTWARE INTERRUPT]software interrupt hit 2 times
  340. [IN SOFTWARE INTERRUPT]software interrupt end
  341. -------------------
  342. [IN TIMER INTERRUPT]timer interrupt hit 3 times
  343. [IN TIMER INTERRUPT]trigger software interrupt
  344. [IN TIMER INTERRUPT]software interrupt will run when timer interrupt finished
  345. [IN TIMER INTERRUPT]timer interrupt end
  346. [IN SOFTWARE INTERRUPT]software interrupt hit 3 times
  347. [IN SOFTWARE INTERRUPT]software interrupt end
  348. .. _design_app_demo_plic:
  349. demo_plic
  350. ~~~~~~~~~
  351. This `demo_plic application`_ is used to demonstrate how to use
  352. the PLIC API and Interrupt is working in CLINT/PLIC interrupt mode.
  353. .. note::
  354. This demo only works on evalsoc, and require PLIC module present.
  355. * This demo will show how to use plic external interrupt
  356. * This demo use uart rx interrupt
  357. * **NOTE**: not able to working in qemu
  358. **How to run this application:**
  359. .. code-block:: shell
  360. # Assume that you can set up the Tools and Nuclei SDK environment
  361. # cd to the demo_plic directory
  362. cd application/baremetal/demo_plic
  363. # For this case, if your bit has PLIC, and you are not using sdk generated by nuclei_gen
  364. # XLCFG_PLIC=1 will define CFG_HAS_PLIC macro
  365. make SOC=evalsoc XLCFG_PLIC=1 clean
  366. # Build and upload the application
  367. make SOC=evalsoc XLCFG_PLIC=1 upload
  368. .. code-block:: console
  369. Nuclei SDK Build Time: Jul 23 2024, 17:49:27
  370. Download Mode: ILM
  371. CPU Frequency 50000000 Hz
  372. CPU HartID: 0
  373. You can press any key now to trigger uart receive interrupt
  374. Enter uart0 interrupt, you just typed: 1
  375. Enter uart0 interrupt, you just typed: 2
  376. .. _design_app_demo_dsp:
  377. demo_dsp
  378. ~~~~~~~~
  379. This `demo_dsp application`_ is used to demonstrate how to NMSIS-DSP API.
  380. * Mainly show how we can use DSP library and header files.
  381. * It mainly demo the ``riscv_conv_xx`` functions and its reference functions
  382. * By default, the application will use NMSIS-DSP library with DSP enabled.
  383. .. note::
  384. * For other Nuclei Processor Core based SoC, please check whether it has DSP
  385. feature enabled to decide which kind of **NMSIS-DSP** library to use.
  386. * Even our NMSIS-DSP library with DSP disabled are also optimized, so it can
  387. also provide good performance in some functions.
  388. **How to run this application:**
  389. .. code-block:: shell
  390. # Assume that you can set up the Tools and Nuclei SDK environment
  391. # cd to the demo_dsp directory
  392. cd application/baremetal/demo_dsp
  393. # Clean the application first
  394. make SOC=gd32vf103 clean
  395. # Build and upload the application
  396. make SOC=gd32vf103 upload
  397. **Expected output as below:**
  398. .. code-block:: console
  399. Nuclei SDK Build Time: Jun 18 2020, 17:43:31
  400. Download Mode: FLASHXIP
  401. CPU Frequency 108270000 Hz
  402. CSV, riscv_conv_q31, 1225418
  403. CSV, ref_conv_q31, 2666240
  404. SUCCESS, riscv_conv_q31
  405. CSV, riscv_conv_q15, 289940
  406. CSV, ref_conv_q15, 311158
  407. SUCCESS, riscv_conv_q15
  408. CSV, riscv_conv_q7, 463
  409. CSV, ref_conv_q7, 846
  410. SUCCESS, riscv_conv_q7
  411. CSV, riscv_conv_fast_q15, 106293
  412. CSV, ref_conv_fast_q15, 247938
  413. SUCCESS, riscv_conv_fast_q15
  414. CSV, riscv_conv_fast_q31, 490539
  415. CSV, ref_conv_fast_q31, 2215917
  416. SUCCESS, riscv_conv_fast_q31
  417. CSV, riscv_conv_opt_q15, 217250
  418. CSV, ref_conv_opt_q15, 311162
  419. SUCCESS, riscv_conv_opt_q15
  420. CSV, riscv_conv_opt_q7, 714
  421. CSV, ref_conv_opt_q7, 842
  422. SUCCESS, riscv_conv_opt_q7
  423. CSV, riscv_conv_fast_opt_q15, 137252
  424. CSV, ref_conv_fast_opt_q15, 249958
  425. SUCCESS, riscv_conv_fast_opt_q15
  426. all test are passed. Well done!
  427. .. _design_app_lowpower:
  428. lowpower
  429. ~~~~~~~~
  430. This `lowpower application`_ is used to demonstrate how to use low-power feature of RISC-V
  431. processor.
  432. Timer interrupt is setup before enter to wfi mode, and global interrupt will be disabled,
  433. so interrupt handler will not be entered, and will directly resume to next pc of wfi.
  434. **How to run this application:**
  435. .. code-block:: shell
  436. # Assume that you can set up the Tools and Nuclei SDK environment
  437. # Assume your processor has enabled low-power feature
  438. # cd to the low-power directory
  439. cd application/baremetal/lowpower
  440. # Clean the application first
  441. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300 clean
  442. # Build and upload the application
  443. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300 upload
  444. **Expected output as below:**
  445. .. code-block:: console
  446. Nuclei SDK Build Time: Jun 9 2022, 11:23:14
  447. Download Mode: ILM
  448. CPU Frequency 15996354 Hz
  449. CSV, WFI Start/End, 178264/178289
  450. CSV, WFI Cost, 25
  451. .. _design_app_smphello:
  452. smphello
  453. ~~~~~~~~
  454. This `smphello application`_ is used to demonstrate how to use baremetal SMP feature.
  455. This demo requests the SMP cores share the same RAM and ROM, for example, in current
  456. evalsoc system, ilm/dlm are private resource for cpu, only the DDR/SRAM memory are shared
  457. resource for all the cpu.
  458. And `RVA` atomic extension is required to run this application, this extension is used
  459. to do spinlock in this example.
  460. .. note::
  461. * It doesn't work with gd32vf103 processor.
  462. * **MUST** Need to enable I/D Cache in <Device.h> if I/D Cache present in CPU.
  463. * It needs at least a 2-Core SMP CPU
  464. **How to run this application:**
  465. .. code-block:: shell
  466. # Assume that you can set up the Tools and Nuclei SDK environment
  467. # Use Nuclei UX900 SMP 2 Core RISC-V processor as example
  468. # application needs to run in ddr memory not in ilm memory
  469. # cd to the smphello directory
  470. cd application/baremetal/smphello
  471. # Clean the application first
  472. make SOC=evalsoc BOARD=nuclei_fpga_eval SMP=2 CORE=ux900 clean
  473. # Build and upload the application
  474. make SOC=evalsoc BOARD=nuclei_fpga_eval SMP=2 CORE=ux900 upload
  475. **Expected output as below:**
  476. .. code-block:: console
  477. Nuclei SDK Build Time: May 30 2022, 15:38:00
  478. Download Mode: SRAM
  479. CPU Frequency 15998648 Hz
  480. Hello world from hart 0
  481. Hello world from hart 1
  482. All harts boot successfully!
  483. .. _design_app_demo_nice:
  484. demo_nice
  485. ~~~~~~~~~
  486. .. note::
  487. * It doesn't work with gd32vf103 processor.
  488. * Need nice feature enabled, and Nuclei NICE hardware demo integrated such as evalsoc
  489. This `demo_nice application`_ is used to demonstrate how to Nuclei NICE feature.
  490. **NICE** is short for Nuclei Instruction Co-unit Extension, which is used to
  491. support extensive customization and specialization.
  492. **NICE** allows customers to create user-defined instructions, enabling the
  493. integrations of custom hardware co-units that improve domain-specific
  494. performance while reducing power consumption.
  495. For more about **NICE** feature, please click `Nuclei User Extended Introduction`_.
  496. * Mainly show how to use NICE intrinsic function with compiler.
  497. * It only works with Nuclei RISC-V Processor with the hardware NICE demo integrated.
  498. **How to run this application:**
  499. .. code-block:: shell
  500. # Assume that you can set up the Tools and Nuclei SDK environment
  501. # Use Nuclei UX900 RISC-V processor as example, hardware NICE demo integrated
  502. # cd to the demo_dsp directory
  503. cd application/baremetal/demo_nice
  504. # Clean the application first
  505. make SOC=evalsoc BOARD=nuclei_fpga_eval CORE=ux900 clean
  506. # Build and upload the application
  507. make SOC=evalsoc BOARD=nuclei_fpga_eval CORE=ux900 upload
  508. **Expected output as below:**
  509. .. code-block:: console
  510. Nuclei SDK Build Time: May 28 2024, 13:32:18
  511. Download Mode: ILM
  512. CPU Frequency 49999631 Hz
  513. CPU HartID: 0
  514. Nuclei Nice Acceleration Demonstration
  515. Warning: This demo required CPU to implement Nuclei provided NICE Demo instructions.
  516. Otherwise this example will trap to cpu core exception!
  517. 1. Print input matrix array
  518. the element of array is :
  519. 10 30 90
  520. 20 40 80
  521. 30 90 120
  522. 2. Do reference matrix column sum and row sum
  523. 3. Do nice matrix column sum and row sum
  524. 4. Compare reference and nice result
  525. 5) Reference result:
  526. the sum of each row is :
  527. 130 140 240
  528. the sum of each col is :
  529. 60 160 290
  530. 6) Nice result:
  531. the sum of each row is :
  532. 130 140 240
  533. the sum of each col is :
  534. 60 160 290
  535. 7) Compare reference vs nice: PASS
  536. 8. Performance summary
  537. normal:
  538. instret: 502, cycle: 502
  539. nice :
  540. instret: 177, cycle: 177
  541. .. _design_app_demo_vnice:
  542. demo_vnice
  543. ~~~~~~~~~~
  544. .. note::
  545. * It only works with Nuclei EvalSoC with Vector NICE demo instructions enabled.
  546. * Need vector nice feature enabled, and Nuclei NICE hardware demo integrated such as evalsoc
  547. This `demo_vnice application`_ is used to demonstrate how to Nuclei Vector NICE feature.
  548. **NICE** is short for Nuclei Instruction Co-unit Extension, which is used to
  549. support extensive customization and specialization.
  550. **How to run this application:**
  551. .. code-block:: shell
  552. # Assume that you can set up the Tools and Nuclei SDK environment
  553. # Use Nuclei UX900 + Vector Nice RISC-V processor as example, hardware NICE demo integrated
  554. # cd to the demo_dsp directory
  555. cd application/baremetal/demo_vnice
  556. # Clean the application first
  557. make SOC=evalsoc clean
  558. # Build and upload the application
  559. make SOC=evalsoc upload
  560. **Expected output as below:**
  561. .. code-block:: console
  562. Nuclei SDK Build Time: May 28 2024, 13:31:08
  563. Download Mode: ILM
  564. CPU Frequency 1000000716 Hz
  565. CPU HartID: 0
  566. 1. Set array_normal_in1 array_normal_in1 array_vnice_in1 array_vnice_in2
  567. 2. Do reference vector complex mul, store, load
  568. 3. Do vector nice complex mul, store, load
  569. 4. Compare reference and vnice result
  570. PASS
  571. 5. Performance summary
  572. normal:
  573. instret: 22546, cycle: 22546
  574. vnice :
  575. instret: 1010, cycle: 1010
  576. .. _design_app_coremark:
  577. coremark
  578. ~~~~~~~~
  579. This `coremark benchmark application`_ is used to run EEMBC CoreMark Software.
  580. EEMBC CoreMark Software is a product of EEMBC and is provided under the terms of the
  581. CoreMark License that is distributed with the official EEMBC COREMARK Software release.
  582. If you received this EEMBC CoreMark Software without the accompanying CoreMark License,
  583. you must discontinue use and download the official release from www.coremark.org.
  584. In Nuclei SDK, we provided code and Makefile for this ``coremark`` application.
  585. You can also optimize the ``COMMON_FLAGS`` defined in coremark application Makefile
  586. to get different score number.
  587. * By default, this application runs for 800 iterations, you can also change this in Makefile.
  588. e.g. Change this ``-DITERATIONS=800`` to value such as ``-DITERATIONS=5000``
  589. * macro **PERFORMANCE_RUN=1** is defined
  590. * **STDCLIB ?= newlib_small** is added in its Makefile to enable float value print
  591. * For different Nuclei CPU series, the benchmark options are different, currently
  592. you can pass ``CPU_SERIES=900`` to select benchmark options for 900 series, otherwise
  593. the benchmark options for 200/300/600/900 will be selected which is also the default value.
  594. .. note::
  595. * Since for each SoC platforms, the CPU frequency is different, so user need to change
  596. the ``ITERATIONS`` defined in Makefile to proper value to let the coremark run at least
  597. 10 seconds
  598. * For example, for the ``gd32vf103`` based boards supported in Nuclei SDK, we suggest
  599. to change ``-DITERATIONS=800`` to ``-DITERATIONS=5000``
  600. **How to run this application:**
  601. .. code-block:: shell
  602. # Assume that you can set up the Tools and Nuclei SDK environment
  603. # cd to the coremark directory
  604. cd application/baremetal/benchmark/coremark
  605. # change ITERATIONS value in Makefile for gd32vf103 based board to 5000
  606. # Clean the application first
  607. make SOC=gd32vf103 clean
  608. # Build and upload the application
  609. make SOC=gd32vf103 upload
  610. **Expected output as below:**
  611. .. code-block:: console
  612. Nuclei SDK Build Time: Mar 30 2020, 18:08:53
  613. Download Mode: FLASHXIP
  614. CPU Frequency 107190000 Hz
  615. Start to run coremark for 5000 iterations
  616. 2K performance run parameters for coremark.
  617. CoreMark Size : 666
  618. Total ticks : 1622809457
  619. Total time (secs): 15.139593
  620. Iterations/Sec : 330.259868
  621. Iterations : 5000
  622. Compiler version : GCC9.2.0
  623. Compiler flags : -O2 -flto -funroll-all-loops -finline-limit=600 -ftree-dominator-opts -fno-if-conversion2 -fselective-scheduling -fno-code-hoisting -fno-common -funroll-loops -finline-functions -falign-functions=4 -falign-jumps=4 -falign-loops=4
  624. Memory location : STACK
  625. seedcrc : 0xe9f5
  626. [0]crclist : 0xe714
  627. [0]crcmatrix : 0x1fd7
  628. [0]crcstate : 0x8e3a
  629. [0]crcfinal : 0xbd59
  630. Correct operation validated. See readme.txt for run and reporting rules.
  631. CoreMark 1.0 : 330.259868 / GCC9.2.0 -O2 -flto -funroll-all-loops -finline-limit=600 -ftree-dominator-opts -fno-if-conversion2 -fselective-scheduling -fno-code-hoisting -fno-common -funroll-loops -finline-functions -falign-functions=4 -falign-jumps=4 -falign-loops=4 / STACK
  632. Print Personal Added Addtional Info to Easy Visual Analysis
  633. (Iterations is: 5000
  634. (total_ticks is: 1622809457
  635. (*) Assume the core running at 1 MHz
  636. So the CoreMark/MHz can be caculated by:
  637. (Iterations*1000000/total_ticks) = 3.081076 CoreMark/MHz
  638. .. _design_app_dhrystone:
  639. dhrystone
  640. ~~~~~~~~~
  641. This `dhrystone benchmark application`_ is used to run DHRYSTONE Benchmark Software.
  642. The Dhrystone benchmark program has become a popular benchmark for CPU/compiler performance measurement,
  643. in particular in the area of minicomputers, workstations, PC's and microprocesors.
  644. * It apparently satisfies a need for an easy-to-use integer benchmark;
  645. * it gives a first performance indication which is more meaningful than MIPS numbers which,
  646. in their literal meaning (million instructions per second), cannot be used across different
  647. instruction sets (e.g. RISC vs. CISC).
  648. * With the increasing use of the benchmark, it seems necessary to reconsider the benchmark and
  649. to check whether it can still fulfill this function.
  650. In Nuclei SDK, we provided code and Makefile for this ``dhrystone`` application.
  651. You can also optimize the ``COMMON_FLAGS`` defined in dhrystone application Makefile
  652. to get different score number.
  653. * **STDCLIB ?= newlib_small** is added in its Makefile to enable float value print
  654. * You can change ``Number_Of_Runs`` in ``dhry_1.c`` line 134 to increate or decrease
  655. number of iterations
  656. **How to run this application:**
  657. .. code-block:: shell
  658. # Assume that you can set up the Tools and Nuclei SDK environment
  659. # cd to the dhrystone directory
  660. cd application/baremetal/benchmark/dhrystone
  661. # Clean the application first
  662. make SOC=gd32vf103 clean
  663. # Build and upload the application
  664. make SOC=gd32vf103 upload
  665. **Expected output as below:**
  666. .. code-block:: console
  667. Nuclei SDK Build Time: Feb 21 2020, 14:23:55
  668. Download Mode: FLASHXIP
  669. CPU Frequency 108801980 Hz
  670. Dhrystone Benchmark, Version 2.1 (Language: C)
  671. Program compiled without 'register' attribute
  672. Please give the number of runs through the benchmark:
  673. Execution starts, 500000 runs through Dhrystone
  674. Execution ends
  675. Final values of the variables used in the benchmark:
  676. Int_Glob: 5
  677. should be: 5
  678. Bool_Glob: 1
  679. should be: 1
  680. Ch_1_Glob: A
  681. should be: A
  682. Ch_2_Glob: B
  683. should be: B
  684. Arr_1_Glob[8]: 7
  685. should be: 7
  686. Arr_2_Glob[8][7]: 500010
  687. should be: Number_Of_Runs + 10
  688. Ptr_Glob->
  689. Ptr_Comp: 536883352
  690. should be: (implementation-dependent)
  691. Discr: 0
  692. should be: 0
  693. Enum_Comp: 2
  694. should be: 2
  695. Int_Comp: 17
  696. should be: 17
  697. Str_Comp: DHRYSTONE PROGRAM, SOME STRING
  698. should be: DHRYSTONE PROGRAM, SOME STRING
  699. Next_Ptr_Glob->
  700. Ptr_Comp: 536883352
  701. should be: (implementation-dependent), same as above
  702. Discr: 0
  703. should be: 0
  704. Enum_Comp: 1
  705. should be: 1
  706. Int_Comp: 18
  707. should be: 18
  708. Str_Comp: DHRYSTONE PROGRAM, SOME STRING
  709. should be: DHRYSTONE PROGRAM, SOME STRING
  710. Int_1_Loc: 5
  711. should be: 5
  712. Int_2_Loc: 13
  713. should be: 13
  714. Int_3_Loc: 7
  715. should be: 7
  716. Enum_Loc: 1
  717. should be: 1
  718. Str_1_Loc: DHRYSTONE PROGRAM, 1'ST STRING
  719. should be: DHRYSTONE PROGRAM, 1'ST STRING
  720. Str_2_Loc: DHRYSTONE PROGRAM, 2'ND STRING
  721. should be: DHRYSTONE PROGRAM, 2'ND STRING
  722. (*) User_Cycle for total run through Dhrystone with loops 500000:
  723. 223500116
  724. So the DMIPS/MHz can be caculated by:
  725. 1000000/(User_Cycle/Number_Of_Runs)/1757 = 1.273270 DMIPS/MHz
  726. .. _design_app_whetstone:
  727. whetstone
  728. ~~~~~~~~~
  729. This `whetstone benchmark application`_ is used to run C/C++ Whetstone Benchmark Software
  730. (Single or Double Precision).
  731. The Fortran Whetstone programs were the first general purpose benchmarks that set industry
  732. standards of computer system performance. Whetstone programs also addressed the question
  733. of the efficiency of different programming languages, an important issue not covered by
  734. more contemporary standard benchmarks.
  735. In Nuclei SDK, we provided code and Makefile for this ``whetstone`` application.
  736. You can also optimize the ``COMMON_FLAGS`` defined in whetstone application Makefile
  737. to get different score number.
  738. * **STDCLIB ?= newlib_small** is added in its Makefile to enable float value print
  739. * Extra **LDFLAGS := -lm** is added in its Makefile to include the math library
  740. **How to run this application:**
  741. .. code-block:: shell
  742. # Assume that you can set up the Tools and Nuclei SDK environment
  743. # cd to the whetstone directory
  744. cd application/baremetal/benchmark/whetstone
  745. # Clean the application first
  746. make SOC=gd32vf103 clean
  747. # Build and upload the application
  748. make SOC=gd32vf103 upload
  749. **Expected output as below:**
  750. .. code-block:: console
  751. Nuclei SDK Build Time: Feb 21 2020, 14:50:15
  752. Download Mode: FLASHXIP
  753. CPU Frequency 109069306 Hz
  754. ##########################################
  755. Single Precision C Whetstone Benchmark Opt 3 32 Bit
  756. Calibrate
  757. 1.96 Seconds 1 Passes (x 100)
  758. 9.81 Seconds 5 Passes (x 100)
  759. Use 5 passes (x 100)
  760. Single Precision C/C++ Whetstone Benchmark
  761. Loop content Result MFLOPS MOPS Seconds
  762. N1 floating point -1.12475013732910156 1.053 0.091
  763. N2 floating point -1.12274742126464844 1.053 0.638
  764. N3 if then else 1.00000000000000000 108527.617 0.000
  765. N4 fixed point 12.00000000000000000 5.630 0.280
  766. N5 sin,cos etc. 0.49909299612045288 0.109 3.829
  767. N6 floating point 0.99999982118606567 1.082 2.493
  768. N7 assignments 3.00000000000000000 419.794 0.002
  769. N8 exp,sqrt etc. 0.75110614299774170 0.075 2.492
  770. MWIPS 5.089 9.825
  771. MWIPS/MHz 0.046 9.825
  772. .. _design_app_demo_smode_eclic:
  773. demo_smode_eclic
  774. ~~~~~~~~~~~~~~~~
  775. This `demo_smode_eclic application`_ is used to demostrate how to use
  776. the ECLIC API and Interrupt in supervisor mode with TEE.
  777. .. note::
  778. * It doesn't work with gd32vf103 processor.
  779. * It needs Nuclei CPU configured with TEE feature and S-Mode ECLIC
  780. * In this application's Makefile, we provided comments in Makefile about optimization
  781. for code size, please refer to chapter :ref:`design_app_demo_eclic` for details.
  782. * Need to enable TEE in <Device.h> if TEE present in CPU.
  783. * The timer interrupt and timer software interrupt are used
  784. * The timer interrupt is registered as non-vector interrupt
  785. * The timer software interrupt is registered as vector interrupt,
  786. and we enable its preemptive feature by using ``SAVE_IRQ_CSR_CONTEXT_S``
  787. and ``RESTORE_IRQ_CSR_CONTEXT_S`` in timer software interrupt handler
  788. * The timer interrupt is triggered periodically
  789. * The timer software interrupt is triggered in timer interrupt handler using
  790. ``SysTimer_SetHartSWIRQ`` function
  791. * Interrupts occur in supervisor mode to which it drops from machine mode, and you can
  792. observe the difference from :ref:`design_app_demo_eclic` by console output
  793. * In the application code, there is a macro called ``SWIRQ_INTLEVEL_HIGHER`` to
  794. control the timer software interrupt working feature:
  795. - If **SWIRQ_INTLEVEL_HIGHER=1**, the timer software interrupt level is higher than
  796. timer interrupt level, so when timer software interrupt is triggered, then timer
  797. software interrupt will be processed immediately, and timer interrupt will be preempted
  798. by timer software interrupt.
  799. - If **SWIRQ_INTLEVEL_HIGHER=0**, the timer software interrupt level is lower than
  800. timer interrupt level, so when timer software interrupt is triggered, then timer
  801. software interrupt will be processed after timer interrupt, and timer interrupt will
  802. not be preempted by timer software interrupt.
  803. **How to run this application:**
  804. .. code-block:: shell
  805. # Assume that you can set up the Tools and Nuclei SDK environment
  806. # cd to the demo_smode_eclic directory
  807. cd application/baremetal/demo_smode_eclic
  808. # MUST: Your CPU configuration must has TEE configured
  809. # Since Nuclei SDK 0.7.0, if you are sure CFG_HAS_TEE is not defined in cpufeature.h, but you have TEE
  810. # you can pass extra make variable XLCFG_TEE=1 during make command to tell sdk
  811. # the TEE present, it will define CFG_HAS_TEE
  812. # Change macro SWIRQ_INTLEVEL_HIGHER value in demo_smode_eclic.c
  813. # to see different working mode of this demo
  814. # Clean the application first
  815. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300 clean
  816. # Build and upload the application
  817. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300 upload
  818. **Expected output(SWIRQ_INTLEVEL_HIGHER=1) as below:**
  819. .. code-block:: console
  820. Nuclei SDK Build Time: Aug 5 2022, 15:05:52
  821. Download Mode: ILM
  822. CPU Frequency 15989145 Hz
  823. Current sp is 0x9000ffa0, so it is in Machine Mode!
  824. Drop to S-Mode now
  825. [IN S-MODE ENTRY POINT] Hello Supervisor Mode!!!
  826. Current sp is 0x90000f40, so it is in Supervisor Mode!
  827. Initialize timer and start timer interrupt periodically
  828. Current sp is 0x90000d80, so it is in Supervisor Mode!
  829. -------------------
  830. [IN S-MODE TIMER INTERRUPT]timer interrupt hit 0 times
  831. [IN S-MODE TIMER INTERRUPT]trigger software interrupt
  832. [IN S-MODE TIMER INTERRUPT]software interrupt will run during timer interrupt
  833. [IN S-MODE SOFTWARE INTERRUPT]software interrupt hit 0 times
  834. Current sp is 0x90000d10, so it is in Supervisor Mode!
  835. [IN S-MODE SOFTWARE INTERRUPT]software interrupt end
  836. [IN S-MODE TIMER INTERRUPT]timer interrupt end
  837. Current sp is 0x90000d80, so it is in Supervisor Mode!
  838. -------------------
  839. [IN S-MODE TIMER INTERRUPT]timer interrupt hit 1 times
  840. [IN S-MODE TIMER INTERRUPT]trigger software interrupt
  841. [IN S-MODE TIMER INTERRUPT]software interrupt will run during timer interrupt
  842. [IN S-MODE SOFTWARE INTERRUPT]software interrupt hit 1 times
  843. Current sp is 0x90000d10, so it is in Supervisor Mode!
  844. [IN S-MODE SOFTWARE INTERRUPT]software interrupt end
  845. [IN S-MODE TIMER INTERRUPT]timer interrupt end
  846. Current sp is 0x90000d80, so it is in Supervisor Mode!
  847. -------------------
  848. [IN S-MODE TIMER INTERRUPT]timer interrupt hit 2 times
  849. [IN S-MODE TIMER INTERRUPT]trigger software interrupt
  850. [IN S-MODE TIMER INTERRUPT]software interrupt will run during timer interrupt
  851. [IN S-MODE SOFTWARE INTERRUPT]software interrupt hit 2 times
  852. Current sp is 0x90000d10, so it is in Supervisor Mode!
  853. [IN S-MODE SOFTWARE INTERRUPT]software interrupt end
  854. [IN S-MODE TIMER INTERRUPT]timer interrupt end
  855. Current sp is 0x90000d80, so it is in Supervisor Mode!
  856. -------------------
  857. [IN S-MODE TIMER INTERRUPT]timer interrupt hit 3 times
  858. [IN S-MODE TIMER INTERRUPT]trigger software interrupt
  859. [IN S-MODE TIMER INTERRUPT]software interrupt will run during timer interrupt
  860. [IN S-MODE SOFTWARE INTERRUPT]software interrupt hit 3 times
  861. Current sp is 0x90000d10, so it is in Supervisor Mode!
  862. [IN S-MODE SOFTWARE INTERRUPT]software interrupt end
  863. [IN S-MODE TIMER INTERRUPT]timer interrupt end
  864. **Expected output(SWIRQ_INTLEVEL_HIGHER=0) as below:**
  865. .. code-block:: console
  866. Nuclei SDK Build Time: Aug 5 2022, 15:09:46
  867. Download Mode: ILM
  868. CPU Frequency 15989145 Hz
  869. Current sp is 0x9000ffa0, so it is in Machine Mode!
  870. Drop to S-Mode now
  871. [IN S-MODE ENTRY POINT] Hello Supervisor Mode!!!
  872. Current sp is 0x90000f50, so it is in Supervisor Mode!
  873. Initialize timer and start timer interrupt periodically
  874. Current sp is 0x90000d90, so it is in Supervisor Mode!
  875. -------------------
  876. [IN S-MODE TIMER INTERRUPT]timer interrupt hit 0 times
  877. [IN S-MODE TIMER INTERRUPT]trigger software interrupt
  878. [IN S-MODE TIMER INTERRUPT]software interrupt will run when timer interrupt finished
  879. [IN S-MODE TIMER INTERRUPT]timer interrupt end
  880. [IN S-MODE SOFTWARE INTERRUPT]software interrupt hit 0 times
  881. Current sp is 0x90000ee0, so it is in Supervisor Mode!
  882. [IN S-MODE SOFTWARE INTERRUPT]software interrupt end
  883. Current sp is 0x90000d90, so it is in Supervisor Mode!
  884. -------------------
  885. [IN S-MODE TIMER INTERRUPT]timer interrupt hit 1 times
  886. [IN S-MODE TIMER INTERRUPT]trigger software interrupt
  887. [IN S-MODE TIMER INTERRUPT]software interrupt will run when timer interrupt finished
  888. [IN S-MODE TIMER INTERRUPT]timer interrupt end
  889. [IN S-MODE SOFTWARE INTERRUPT]software interrupt hit 1 times
  890. Current sp is 0x90000ee0, so it is in Supervisor Mode!
  891. [IN S-MODE SOFTWARE INTERRUPT]software interrupt end
  892. Current sp is 0x90000d90, so it is in Supervisor Mode!
  893. -------------------
  894. [IN S-MODE TIMER INTERRUPT]timer interrupt hit 2 times
  895. [IN S-MODE TIMER INTERRUPT]trigger software interrupt
  896. [IN S-MODE TIMER INTERRUPT]software interrupt will run when timer interrupt finished
  897. [IN S-MODE TIMER INTERRUPT]timer interrupt end
  898. [IN S-MODE SOFTWARE INTERRUPT]software interrupt hit 2 times
  899. Current sp is 0x90000ee0, so it is in Supervisor Mode!
  900. [IN S-MODE SOFTWARE INTERRUPT]software interrupt end
  901. Current sp is 0x90000d90, so it is in Supervisor Mode!
  902. -------------------
  903. [IN S-MODE TIMER INTERRUPT]timer interrupt hit 3 times
  904. [IN S-MODE TIMER INTERRUPT]trigger software interrupt
  905. [IN S-MODE TIMER INTERRUPT]software interrupt will run when timer interrupt finished
  906. [IN S-MODE TIMER INTERRUPT]timer interrupt end
  907. [IN S-MODE SOFTWARE INTERRUPT]software interrupt hit 3 times
  908. Current sp is 0x90000ee0, so it is in Supervisor Mode!
  909. [IN S-MODE SOFTWARE INTERRUPT]software interrupt end
  910. .. _design_app_demo_spmp:
  911. demo_spmp
  912. ~~~~~~~~~
  913. This `demo_spmp application`_ is used to demonstrate how to grant physical memory privileges
  914. (read, write, execute) on each physical memory region by supervisor-mode control CSRs.
  915. .. note::
  916. * It doesn't work with gd32vf103 processor.
  917. * It needs Nuclei CPU configured with TEE, PMP, sPMP feature
  918. * Need to enable PMP in <Device.h> if PMP present in CPU.
  919. * Need to enable TEE in <Device.h> if TEE present in CPU.
  920. * Need to enable SPMP in <Device.h> if SPMP present in CPU.
  921. * ``spmp_violation_fault_handler`` is registered, which is to execute when spmp violation
  922. exception occurs
  923. * The sPMP values are checked after the physical address to be accessed passes PMP checks
  924. * There're three config structures, ``pmp_config`` inits that M-mode grants full permission
  925. of the whole address range on S and U mode; ``spmp_config_x`` sets protected executable
  926. address range as 2^12 bytes; ``spmp_config_rw`` sets protected readable/writable address
  927. range as 2^12 bytes, and you can change the ``protection``, ``order``, ``base_addr`` according
  928. to your memory assignments
  929. * Exception delegation from default M mode to S mode is also provided in this demo, when
  930. it violates sPMP check.When exception occurs, the print info including ``scause``, ``sepc``
  931. can be observed by serial console, which explains the exception cause of SPMP permission
  932. violation, and shows which asm instruction triggers the violation
  933. * In the application code, there is a macro called ``TRIGGER_SPMP_VIOLATION_MODE`` to control the
  934. sPMP working feature:
  935. - If **TRIGGER_SPMP_VIOLATION_MODE=INSTRUCTION_FETCH_PAGE_EXCEPTION**, the unallowed memory is to
  936. execute, which triggers ``Instruction page fault``, whose scause.EXCCODE = 12 and sdcause = 6
  937. - If **TRIGGER_SPMP_VIOLATION_MODE=LOAD_PAGE_EXCEPTION**, the unallowed memory is to read,
  938. which triggers ``Load page fault``, whose scause.EXCODE = 13 and sdcause = 6
  939. - If **TRIGGER_SPMP_VIOLATION_MODE=STORE_PAGE_EXCEPTION**, the unallowed memory is to write,
  940. which triggers ``Store/AMO page fault``, whose scause.EXCODE = 15 and sdcause = 6
  941. - If **TRIGGER_SPMP_VIOLATION_MODE=EXECUTE_USERMODE_MEMORY_EXCEPTION**, the U-Mode accessiable
  942. memory is to execute, which triggers ``Instruction page fault``. By the way, S-mode can never
  943. execute instructions from user pages, regardless of the state of ``SUM(permit Supervisor User Memory access)``
  944. - If **TRIGGER_SPMP_VIOLATION_MODE=LOAD_USERMODE_MEMORY_EXCEPTION**, the the U-Mode accessiable
  945. memory is to read, which triggers ``Load page fault``. When SUM=1, read access is permitted
  946. - If **TRIGGER_SPMP_VIOLATION_MODE=STORE_USERMODE_MEMORY_EXCEPTION**, the the U-Mode accessiable
  947. memory is to write, which triggers ``Store/AMO page fault``. When SUM=1, write access is permitted
  948. - If **TRIGGER_SPMP_VIOLATION_MODE=RUN_WITH_NO_SPMP_CHECK**, supervisor mode access succeed, no
  949. violation occurs
  950. **How to run this application:**
  951. .. code-block::shell
  952. # Assume that you can set up the Tools and Nuclei SDK environment
  953. # cd to the demo_spmp directory
  954. cd application/baremetal/demo_spmp
  955. # MUST: Your CPU configuration must has TEE configured
  956. # Since Nuclei SDK 0.7.0, if you are sure CFG_HAS_SPMP is not defined in cpufeature.h, but you have sPMP
  957. # you can pass extra make variable XLCFG_SPMP=1 during make command to tell sdk
  958. # the SPMP present, it will define CFG_HAS_SPMP
  959. # Change macro TRIGGER_SPMP_VIOLATION_MODE value in demo_spmp.c
  960. # to see different working mode of this demo
  961. # Clean the application first
  962. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300 clean
  963. # Build and upload the application
  964. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300 upload
  965. **Expected output(TRIGGER_SPMP_VIOLATION_MODE=INSTRUCTION_FETCH_PAGE_EXCEPTION) as below:**
  966. .. code-block:: console
  967. Nuclei SDK Build Time: Aug 15 2022, 15:45:57
  968. Download Mode: ILM
  969. CPU Frequency 15997665 Hz
  970. ------sPMP demo with trigger condition 0------
  971. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x0, order_out: 32
  972. Get spmp entry: index 0, prot_out: 0x9b, addr_out: 0x80004000, order_out: 12
  973. Get spmp entry: index 1, prot_out: 0x9b, addr_out: 0x90000000, order_out: 12
  974. Attempting to fetch instruction from protected address
  975. Instruction page fault occurs, cause: 0x1000000c, epc: 0x80004000
  976. From disassembly code, SEPC refers to
  977. .. code-block:: console
  978. 80004000: 90002537 lui a0,0x90002
  979. **Expected output(TRIGGER_SPMP_VIOLATION_MODE=LOAD_PAGE_EXCEPTION) as below:**
  980. .. code-block:: console
  981. Nuclei SDK Build Time: Aug 15 2022, 15:45:57
  982. Download Mode: ILM
  983. CPU Frequency 16005529 Hz
  984. ------sPMP demo with trigger condition 1------
  985. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x0, order_out: 32
  986. Get spmp entry: index 0, prot_out: 0x9f, addr_out: 0x80004000, order_out: 12
  987. Get spmp entry: index 1, prot_out: 0x9a, addr_out: 0x90000000, order_out: 12
  988. Attempting to fetch instruction from protected address
  989. ----protected_execute succeed!----
  990. Attempting to read protected_data[0]
  991. Load page fault occurs, cause: 0x1000000d, epc: 0x80005026
  992. From disassembly code, SEPC refers to
  993. .. code-block:: console
  994. 80005026: 00044583 lbu a1,0(s0) # 90000000 <_sp+0xffff0000>
  995. **Expected output(TRIGGER_SPMP_VIOLATION_MODE=STORE_PAGE_EXCEPTION) as below:**
  996. .. code-block:: console
  997. Nuclei SDK Build Time: Aug 15 2022, 15:45:57
  998. Download Mode: ILM
  999. CPU Frequency 15997665 Hz
  1000. ------sPMP demo with trigger condition 2------
  1001. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x0, order_out: 32
  1002. Get spmp entry: index 0, prot_out: 0x9f, addr_out: 0x80004000, order_out: 12
  1003. Get spmp entry: index 1, prot_out: 0x99, addr_out: 0x90000000, order_out: 12
  1004. Attempting to fetch instruction from protected address
  1005. ----protected_execute succeed!----
  1006. Attempting to read protected_data[0]
  1007. protected_data[0]: 0xAA succeed
  1008. Attempting to write protected_data[0]
  1009. Store/AMO page fault occurs, cause: 0x1000000f, epc: 0x80005050
  1010. From disassembly code, SEPC refers to
  1011. .. code-block:: console
  1012. 80005050: 00f40023 sb a5,0(s0)
  1013. **Expected output(TRIGGER_SPMP_VIOLATION_MODE=EXECUTE_USERMODE_MEMORY_EXCEPTION) as below:**
  1014. .. code-block:: console
  1015. Nuclei SDK Build Time: Aug 15 2022, 15:45:57
  1016. Download Mode: ILM
  1017. CPU Frequency 15997665 Hz
  1018. ------sPMP demo with trigger condition 3------
  1019. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x0, order_out: 32
  1020. Get spmp entry: index 0, prot_out: 0xdf, addr_out: 0x80004000, order_out: 12
  1021. Get spmp entry: index 1, prot_out: 0x9b, addr_out: 0x90000000, order_out: 12
  1022. Attempting to fetch instruction from protected address
  1023. Instruction page fault occurs, cause: 0x1000000c, epc: 0x80004000
  1024. From disassembly code, SEPC refers to
  1025. .. code-block:: console
  1026. 80004000: 90002537 lui a0,0x90002
  1027. **Expected output(TRIGGER_SPMP_VIOLATION_MODE=LOAD_USERMODE_MEMORY_EXCEPTION) as below:**
  1028. .. code-block:: console
  1029. Nuclei SDK Build Time: Aug 15 2022, 15:45:57
  1030. Download Mode: ILM
  1031. CPU Frequency 16005529 Hz
  1032. ------sPMP demo with trigger condition 4------
  1033. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0, order_out: 32
  1034. Get spmp entry: index 0, prot_out: 0x9f, addr_out: 0x80004000, order_out: 12
  1035. Get spmp entry: index 1, prot_out: 0xd9, addr_out: 0x90000000, order_out: 12
  1036. Attempting to fetch instruction from protected address
  1037. ----protected_execute succeed!----
  1038. Attempting to read protected_data[0]
  1039. Load page fault occurs, cause: 0x1000000d, epc: 0x80005024
  1040. From disassembly code, SEPC refers to
  1041. .. code-block:: console
  1042. 80005024: 0007c583 lbu a1,0(a5) # 90000000 <_sp+0xffff0000>
  1043. **Expected output(TRIGGER_SPMP_VIOLATION_MODE=STORE_USERMODE_MEMORY_EXCEPTION) as below:**
  1044. .. code-block:: console
  1045. Nuclei SDK Build Time: Aug 15 2022, 15:45:57
  1046. Download Mode: ILM
  1047. CPU Frequency 15997665 Hz
  1048. ------sPMP demo with trigger condition 5------
  1049. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x0, order_out: 32
  1050. Get spmp entry: index 0, prot_out: 0x9f, addr_out: 0x80004000, order_out: 12
  1051. Get spmp entry: index 1, prot_out: 0xda, addr_out: 0x90000000, order_out: 12
  1052. Attempting to fetch instruction from protected address
  1053. ----protected_execute succeed!----
  1054. Attempting to write protected_data[0]
  1055. Store/AMO page fault occurs, cause: 0x1000000f, epc: 0x8000502e
  1056. From disassembly code, SEPC refers to
  1057. .. code-block:: console
  1058. 8000502e: 00e78023 sb a4,0(a5) # 90000000 <_sp+0xffff0000>
  1059. **(Default)Expected output(TRIGGER_SPMP_VIOLATION_MODE=RUN_WITH_NO_SPMP_CHECK) as below:**
  1060. .. code-block:: console
  1061. Nuclei SDK Build Time: Aug 15 2022, 15:45:57
  1062. Download Mode: ILM
  1063. CPU Frequency 15997665 Hz
  1064. ------sPMP demo with trigger condition 6------
  1065. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x0, order_out: 32
  1066. Get spmp entry: index 0, prot_out: 0x1f, addr_out: 0x80004000, order_out: 12
  1067. Get spmp entry: index 1, prot_out: 0x1b, addr_out: 0x90000000, order_out: 12
  1068. Attempting to fetch instruction from protected address
  1069. ----protected_execute succeed!----
  1070. Attempting to read protected_data[0]
  1071. protected_data[0]: 0xAA succeed
  1072. Attempting to write protected_data[0]
  1073. Won't run here if violates L U\R\W\X permission check!
  1074. .. _design_app_demo_smpu:
  1075. demo_smpu
  1076. ~~~~~~~~~
  1077. SMPU is upgraded from sPMP to enable S-mode OS to limit the physical addresses accessible by
  1078. U-mode software on a hart. This `demo_smpu application`_ is used to demonstrate how to grant
  1079. physical memory privileges(read, write, execute) on each physical memory region by supervisor-mode control CSRs.
  1080. .. note::
  1081. * It doesn't work with gd32vf103 processor.
  1082. * It needs Nuclei CPU configured with TEE, PMP, SMPU feature
  1083. * Need to enable PMP in <Device.h> if PMP present in CPU.
  1084. * Need to enable TEE in <Device.h> if TEE present in CPU.
  1085. * Need to enable SMPU in <Device.h> if smpu present in CPU.
  1086. * The `demo_smpu application`_ has many common design with `demo_spmp application`_, and you should first
  1087. pay attention to Encoding of Permissions and Context Switching Optimization when changed to smpu
  1088. * Unlike sPMP, ``__set_SMPUSWITCHx`` should be called to activate the entries
  1089. * ``smpu_violation_fault_handler`` is registered, which is to execute when smpu violation
  1090. exception occurs
  1091. * The SMPU is checked before the PMA checks and PMP checks
  1092. * There're three config structures, ``pmp_config`` inits that M-mode grants full permission
  1093. of the whole address range on S and U mode; ``smpu_config_x`` sets protected executable
  1094. address range as 2^12 bytes; ``smpu_config_rw`` sets protected data range as 2^12 bytes,
  1095. and you can change the ``protection``, ``order``, ``base_addr`` according to your memory assignments
  1096. * SMPU has three kinds of rules: U-mode-only, S-mode-only, and Shared-Region rules. The S bit marks a rule
  1097. as S-mode-only when set and U-mode-only when unset
  1098. * ``protection`` of smpu_config_x and smpu_config_rw should be assigned according to ``2.4. Encoding of Permissions``
  1099. of Ssmpu spec
  1100. * Exception delegation from default M mode to S mode is also provided in this demo, when
  1101. it violates smpu check. When exception occurs, the print info including ``scause``, ``sepc``
  1102. can be observed by serial console, which explains the exception cause of smpu permission
  1103. violation, and shows which asm instruction triggers the violation
  1104. * In the application code, there is a macro called ``TRIGGER_SMPU_VIOLATION_MODE`` to control the
  1105. smpu working feature:
  1106. - If **TRIGGER_SMPU_VIOLATION_MODE=INSTRUCTION_SMPU_EXCEPTION**, the unallowed memory is to
  1107. execute, which triggers ``Instruction SMPU fault``, whose scause.EXCCODE = 12
  1108. - If **TRIGGER_SMPU_VIOLATION_MODE=LOAD_SMPU_EXCEPTION**, the unallowed memory is to read,
  1109. which triggers ``Load SMPU fault``, whose scause.EXCODE = 13
  1110. - If **TRIGGER_SMPU_VIOLATION_MODE=STORE_SMPU_EXCEPTION**, the unallowed memory is to write,
  1111. which triggers ``Store/AMO SMPU fault``, whose scause.EXCODE = 15
  1112. - If **TRIGGER_SMPU_VIOLATION_MODE=EXECUTE_SHARED_DATA_REGION_EXCEPTION**, the shared R/W data region
  1113. is to execute, which triggers ``Instruction SMPU fault``
  1114. - If **TRIGGER_SMPU_VIOLATION_MODE=WRITE_READONLY_SHARED_DATA_EXCEPTION**, the shared Read-only data region
  1115. is to write, which triggers ``Store/AMO SMPU fault``
  1116. - If **TRIGGER_SMPU_VIOLATION_MODE=SHARE_CODE_DATA_REGION**, the shared code region is to execute, and the shared
  1117. R/W data region is to read and write, both of which is allowed
  1118. - If **TRIGGER_SMPU_VIOLATION_MODE=RUN_WITH_ENTRY_INACTIVE**, the code region and data reigon is set to inaccessible,
  1119. but disable corresponpding entries, so the rules doesn't take effect and execution and read/write succeed
  1120. **How to run this application:**
  1121. .. code-block::shell
  1122. # Assume that you can set up the Tools and Nuclei SDK environment
  1123. # cd to the demo_smpu directory
  1124. cd application/baremetal/demo_smpu
  1125. # MUST: Your CPU configuration must has TEE configured
  1126. # Since Nuclei SDK 0.7.0, if you are sure CFG_HAS_SMPU is not defined in cpufeature.h, but you have SMPU
  1127. # you can pass extra make variable XLCFG_SMPU=1 during make command to tell sdk
  1128. # the SMPU present, it will define CFG_HAS_SMPU
  1129. # Change macro TRIGGER_SMPU_VIOLATION_MODE value in demo_smpu.c
  1130. # to see different working mode of this demo
  1131. # Clean the application first
  1132. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300 clean
  1133. # Build and upload the application
  1134. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300 upload
  1135. **Expected output(TRIGGER_SMPU_VIOLATION_MODE=INSTRUCTION_SMPU_EXCEPTION) as below:**
  1136. .. code-block:: console
  1137. Nuclei SDK Build Time: Jun 18 2024, 18:36:40
  1138. Download Mode: ILM
  1139. CPU Frequency 16058613 Hz
  1140. CPU HartID: 0
  1141. ------smpu demo with trigger condition 0------
  1142. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x0, order_out: 32
  1143. Get smpu entry: index 0, prot_out: 0x9b, addr_out: 0x80004000, order_out: 12
  1144. Get smpu entry: index 1, prot_out: 0x9b, addr_out: 0x90000000, order_out: 12
  1145. Attempting to fetch instruction from protected address 0x0x80004000
  1146. Instruction SMPU fault occurs, cause: 0x1000000c, epc: 0x80004000
  1147. **Expected output(TRIGGER_SMPU_VIOLATION_MODE=LOAD_SMPU_EXCEPTION) as below:**
  1148. .. code-block:: console
  1149. Nuclei SDK Build Time: Jun 18 2024, 18:39:13
  1150. Download Mode: ILM
  1151. CPU Frequency 16068116 Hz
  1152. CPU HartID: 0
  1153. ------smpu demo with trigger condition 1------
  1154. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x0, order_out: 32
  1155. Get smpu entry: index 0, prot_out: 0x9c, addr_out: 0x80004000, order_out: 12
  1156. Get smpu entry: index 1, prot_out: 0x9c, addr_out: 0x90000000, order_out: 12
  1157. Attempting to fetch instruction from protected address 0x0x80004000
  1158. ----protected_execute succeed!----
  1159. Attempting to read protected_data[0] at 0x90000000
  1160. Load SMPU fault occurs, cause: 0x1000000d, epc: 0x8000608c
  1161. **Expected output(TRIGGER_SMPU_VIOLATION_MODE=STORE_SMPU_EXCEPTION) as below:**
  1162. .. code-block:: console
  1163. Nuclei SDK Build Time: Jun 18 2024, 18:40:00
  1164. Download Mode: ILM
  1165. CPU Frequency 16057630 Hz
  1166. CPU HartID: 0
  1167. ------smpu demo with trigger condition 2------
  1168. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x0, order_out: 32
  1169. Get smpu entry: index 0, prot_out: 0x9c, addr_out: 0x80004000, order_out: 12
  1170. Get smpu entry: index 1, prot_out: 0x99, addr_out: 0x90000000, order_out: 12
  1171. Attempting to fetch instruction from protected address 0x0x80004000
  1172. ----protected_execute succeed!----
  1173. Attempting to read protected_data[0] at 0x90000000
  1174. protected_data[0]: 0xAA succeed
  1175. Attempting to write protected_data[0] at 0x90000000
  1176. Store/AMO SMPU fault occurs, cause: 0x1000000f, epc: 0x800060b2
  1177. **Expected output(TRIGGER_SMPU_VIOLATION_MODE=EXECUTE_SHARED_DATA_REGION_EXCEPTION) as below:**
  1178. .. code-block:: console
  1179. Nuclei SDK Build Time: Jun 18 2024, 18:40:39
  1180. Download Mode: ILM
  1181. CPU Frequency 16057630 Hz
  1182. CPU HartID: 0
  1183. ------smpu demo with trigger condition 3------
  1184. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x0, order_out: 32
  1185. Get smpu entry: index 0, prot_out: 0x1e, addr_out: 0x80004000, order_out: 12
  1186. Get smpu entry: index 1, prot_out: 0x1e, addr_out: 0x90000000, order_out: 12
  1187. Attempting to fetch instruction from protected address 0x0x80004000
  1188. Instruction SMPU fault occurs, cause: 0x1000000c, epc: 0x80004000
  1189. **Expected output(TRIGGER_SMPU_VIOLATION_MODE=WRITE_READONLY_SHARED_DATA_EXCEPTION) as below:**
  1190. .. code-block:: console
  1191. Nuclei SDK Build Time: Jun 18 2024, 18:41:17
  1192. Download Mode: ILM
  1193. CPU Frequency 16057630 Hz
  1194. CPU HartID: 0
  1195. ------smpu demo with trigger condition 4------
  1196. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x0, order_out: 32
  1197. Get smpu entry: index 0, prot_out: 0x9a, addr_out: 0x80004000, order_out: 12
  1198. Get smpu entry: index 1, prot_out: 0x9f, addr_out: 0x90000000, order_out: 12
  1199. Attempting to fetch instruction from protected address 0x0x80004000
  1200. ----protected_execute succeed!----
  1201. Attempting to read protected_data[0] at 0x90000000
  1202. protected_data[0]: 0xAA succeed
  1203. Attempting to write protected_data[0] at 0x90000000
  1204. Store/AMO SMPU fault occurs, cause: 0x1000000f, epc: 0x800060b2
  1205. **Expected output(TRIGGER_SMPU_VIOLATION_MODE=SHARE_CODE_DATA_REGION) as below:**
  1206. .. code-block:: console
  1207. Nuclei SDK Build Time: Jun 18 2024, 18:41:46
  1208. Download Mode: ILM
  1209. CPU Frequency 16068116 Hz
  1210. CPU HartID: 0
  1211. ------smpu demo with trigger condition 5------
  1212. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x0, order_out: 32
  1213. Get smpu entry: index 0, prot_out: 0x9a, addr_out: 0x80004000, order_out: 12
  1214. Get smpu entry: index 1, prot_out: 0x1e, addr_out: 0x90000000, order_out: 12
  1215. Attempting to fetch instruction from protected address 0x0x80004000
  1216. ----protected_execute succeed!----
  1217. Attempting to read protected_data[0] at 0x90000000
  1218. protected_data[0]: 0xAA succeed
  1219. Attempting to write protected_data[0] at 0x90000000
  1220. Won't run here if violates rules check!
  1221. **(Default)Expected output(TRIGGER_SMPU_VIOLATION_MODE=RUN_WITH_ENTRY_INACTIVE) as below:**
  1222. .. code-block:: console
  1223. Nuclei SDK Build Time: Jun 18 2024, 18:42:19
  1224. Download Mode: ILM
  1225. CPU Frequency 16057630 Hz
  1226. CPU HartID: 0
  1227. ------smpu demo with trigger condition 6------
  1228. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x0, order_out: 32
  1229. Get smpu entry: index 0, prot_out: 0x18, addr_out: 0x80004000, order_out: 12
  1230. Get smpu entry: index 1, prot_out: 0x18, addr_out: 0x90000000, order_out: 12
  1231. Attempting to fetch instruction from protected address 0x0x80004000
  1232. ----protected_execute succeed!----
  1233. Attempting to read protected_data[0] at 0x90000000
  1234. protected_data[0]: 0xAA succeed
  1235. Attempting to write protected_data[0] at 0x90000000
  1236. Won't run here if violates rules check!
  1237. .. _design_app_demo_profiling:
  1238. demo_profiling
  1239. ~~~~~~~~~~~~~~
  1240. This `demo_profiling application`_ is used to demonstrate how to use gprof or gcov
  1241. in Nuclei Studio.
  1242. This application itself is modified based on an opensource aes application, we add
  1243. gprof and gcov collection code to ``main.c``, it will dump gprof and gcov data in
  1244. console when main part code is executed.
  1245. .. note::
  1246. * Introduced in Nuclei SDK 0.5.1, worked with Nuclei Studio >= 2024.02
  1247. * Using gprof or gcov introduces instrument code into the original program,
  1248. necessitating additional memory to store the collected data. This results in
  1249. a slight increase in the program's memory footprint compared to its uninstrumented counterpart.
  1250. * It cannot be directly used in command line mode, you should use it in Nuclei Studio.
  1251. * Please check ``README.md`` about gcov and gprof support in https://github.com/Nuclei-Software/nuclei-sdk/tree/master/Components/profiling
  1252. Import or download Nuclei SDK 0.5.1 or later release NPK in Nuclei Studio, and then create a
  1253. project called ``demo_profiling`` based on ``app-nsdk_demo_profiling`` using
  1254. ``Create Nuclei RISC-V C/C++ Project`` Wizard as below:
  1255. .. figure:: /asserts/images/create_demo_profiling_example.png
  1256. :width: 80 %
  1257. :align: center
  1258. :alt: Create demo profiling example
  1259. And when example is created, assume you want to profiling the ``application`` folder, since
  1260. it is the core algorithm of this example, then you just need to do the following steps:
  1261. - Right click on the ``application`` folder, and click ``Properities``, and add extra options
  1262. in ``C/C++ Build`` -> ``Settings`` -> ``GNU RISC-V Cross C Compiler`` -> ``Miscellaneous`` -> ``Other compiler flags``.
  1263. - If you want to do gprof, you need to add ``-pg`` option.
  1264. - If you want to do gcov, you need to add ``-coverage`` option.
  1265. - Open ``main.c``, and find ``TODO`` item, and comment ``gprof_collect(2);`` or ``gcov_collect(2);`` based on
  1266. gprof or gcov you want to collect.
  1267. - If you want to collect gprof data, you also need to modify ``nuclei_sdk/Components/profiling/gprof_stub.c``,
  1268. if you code already has a 1ms period timer interrupt, you should copy code in ``eclic_mtip_handler`` to do
  1269. executing sampling, otherwise you can uncomment ``#define SAMPLE_USING_SYSTIMER``
  1270. Here I want to collect both gprof and gcov, so I modify it like below:
  1271. .. figure:: /asserts/images/add_profiling_options_in_nuclei_studio.png
  1272. :width: 80 %
  1273. :align: center
  1274. :alt: Add profiling options in Nuclei Studio
  1275. .. figure:: /asserts/images/modify_profiling_example_code.png
  1276. :width: 80 %
  1277. :align: center
  1278. :alt: Modify profiling example code
  1279. And then compile this example code, and run it using hardware or qemu, qemu is just function model,
  1280. so it didn't provide correct timing information.
  1281. When program runs, it will dump gprof and gcov data in console, and you can copy all the output as
  1282. a file called ``prof.log``, and use ``gprof_parse.py`` to parse the data, and generate a
  1283. gcov and gprof binary files.
  1284. .. figure:: /asserts/images/parse_profiling_log.png
  1285. :width: 80 %
  1286. :align: center
  1287. :alt: Parse profiling log and generate gcda and gmon.out files
  1288. Then you can double click ``gmon.out`` and ``aes.gcda`` to check the gprof and gcov view in Nuclei Studio
  1289. like below:
  1290. .. figure:: /asserts/images/gprof_gcov_view_in_nuclei_studio.png
  1291. :width: 80 %
  1292. :align: center
  1293. :alt: Gprof and gcov view in Nuclei Studio
  1294. 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
  1295. to learn more.
  1296. 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
  1297. to learn more.
  1298. .. _design_app_demo_pmp:
  1299. demo_pmp
  1300. ~~~~~~~~
  1301. This `demo_pmp application`_ is used to demonstrate how to grant physical memory privileges
  1302. (read, write, execute) on each physical memory region by machine mode control CSRs.
  1303. .. note::
  1304. * It doesn't work with gd32vf103 processor.
  1305. * It needs Nuclei CPU configured with PMP feature
  1306. * Need to enable PMP in <Device.h> if PMP present in CPU.
  1307. * ``pmp_violation_fault_handler`` is registered, which is to execute when pmp violation
  1308. exception occurs
  1309. * There're two config structures, ``pmp_config_x`` sets protected executable address range
  1310. as 2^12 bytes; ``pmp_config_rw`` sets protected readable/writable address range as 2^12
  1311. bytes, and you can change the ``protection``, ``order``, ``base_addr`` according to your
  1312. memory assignments
  1313. * When exception occurs, the print info including ``mcause``, ``mepc`` can be observed
  1314. by serial console, which explains the exception cause of PMP permission violation, and
  1315. shows which asm instruction triggers the violation
  1316. * In the application code, there is a macro called ``TRIGGER_PMP_VIOLATION_MODE`` to control the
  1317. PMP working feature:
  1318. - If **TRIGGER_PMP_VIOLATION_MODE=INSTRUCTION_FETCH_EXCEPTION**, the unallowed memory is to
  1319. execute, which triggers ``Instruction access fault``, whose mcause.EXCCODE = 1 and mdcause = 1
  1320. - If **TRIGGER_PMP_VIOLATION_MODE=LOAD_EXCEPTION**, the unallowed memory is to read,
  1321. which triggers ``Load access fault``, whose mcause.EXCODE = 5 and mdcause = 1
  1322. - If **TRIGGER_PMP_VIOLATION_MODE=STORE_EXCEPTION**, the unallowed memory is to write,
  1323. which triggers ``Store/AMO access fault``, whose mcause.EXCODE = 7 and mdcause = 1
  1324. - If **TRIGGER_PMP_VIOLATION_MODE=RUN_WITH_NO_PMP_CHECK**, no violation occurs
  1325. **How to run this application:**
  1326. .. code-block::shell
  1327. # Assume that you can set up the Tools and Nuclei SDK environment
  1328. # cd to the demo_pmp directory
  1329. cd application/baremetal/demo_pmp
  1330. # MUST: Your CPU configuration must has PMP configured
  1331. # Change macro __PMP_PRESENT to 1 in <Device.h>
  1332. #define __PMP_PRESENT 1
  1333. # Change macro TRIGGER_PMP_VIOLATION_MODE value in demo_pmp.c
  1334. # to see different working mode of this demo
  1335. # Clean the application first
  1336. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300 clean
  1337. # Build and upload the application
  1338. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm CORE=n300 upload
  1339. **Expected output(TRIGGER_PMP_VIOLATION_MODE=INSTRUCTION_FETCH_EXCEPTION) as below:**
  1340. .. code-block:: console
  1341. Nuclei SDK Build Time: Aug 15 2022, 15:45:57
  1342. Download Mode: ILM
  1343. CPU Frequency 16006184 Hz
  1344. ------PMP demo with trigger condition 0------
  1345. Get pmp entry: index 0, prot_out: 0x9b, addr_out: 0x80004000, order_out: 12
  1346. Get pmp entry: index 1, prot_out: 0x9b, addr_out: 0x90000000, order_out: 12
  1347. Attempting to fetch instruction from protected address
  1348. Instruction access fault occurs, cause: 0x30000001, epc: 0x80004000
  1349. From disassembly code, MEPC refers to
  1350. .. code-block:: console
  1351. 80004000: 90002537 lui a0,0x90002
  1352. **Expected output(TRIGGER_PMP_VIOLATION_MODE=LOAD_EXCEPTION) as below:**
  1353. .. code-block:: console
  1354. Nuclei SDK Build Time: Aug 15 2022, 15:45:57
  1355. Download Mode: ILM
  1356. CPU Frequency 16006184 Hz
  1357. ------PMP demo with trigger condition 1------
  1358. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x80004000, order_out: 12
  1359. Get pmp entry: index 1, prot_out: 0x9a, addr_out: 0x90000000, order_out: 12
  1360. Attempting to fetch instruction from protected address
  1361. ----protected_execute succeed!----
  1362. Attempting to read protected_data[0]
  1363. Load access fault occurs, cause: 0x30000005, epc: 0x80004022
  1364. From disassembly code, MEPC refers to
  1365. .. code-block:: console
  1366. 80004022: 00044583 lbu a1,0(s0) # 90000000 <_sp+0xffff0000>
  1367. **Expected output(TRIGGER_PMP_VIOLATION_MODE=STORE_EXCEPTION) as below:**
  1368. .. code-block:: console
  1369. Nuclei SDK Build Time: Aug 15 2022, 15:45:57
  1370. Download Mode: ILM
  1371. CPU Frequency 15998320 Hz
  1372. ------PMP demo with trigger condition 2------
  1373. Get pmp entry: index 0, prot_out: 0x9f, addr_out: 0x80004000, order_out: 12
  1374. Get pmp entry: index 1, prot_out: 0x99, addr_out: 0x90000000, order_out: 12
  1375. Attempting to fetch instruction from protected address
  1376. ----protected_execute succeed!----
  1377. Attempting to read protected_data[0]
  1378. protected_data[0]: 0xAA succeed
  1379. Attempting to write protected_data[0]
  1380. Store/AMO access fault occurs, cause: 0x30000007, epc: 0x80004044
  1381. From disassembly code, MEPC refers to
  1382. .. code-block:: console
  1383. 80004044: 00f40023 sb a5,0(s0)
  1384. **(Default)Expected output(TRIGGER_PMP_VIOLATION_MODE=RUN_WITH_NO_PMP_CHECK) as below:**
  1385. .. code-block:: console
  1386. Nuclei SDK Build Time: Aug 15 2022, 15:45:57
  1387. Download Mode: ILM
  1388. CPU Frequency 16006184 Hz
  1389. ------PMP demo with trigger condition 3------
  1390. Get pmp entry: index 0, prot_out: 0x1f, addr_out: 0x80004000, order_out: 12
  1391. Get pmp entry: index 1, prot_out: 0x1b, addr_out: 0x90000000, order_out: 12
  1392. Attempting to fetch instruction from protected address
  1393. ----protected_execute succeed!----
  1394. Attempting to read protected_data[0]
  1395. protected_data[0]: 0xAA succeed
  1396. Attempting to write protected_data[0]
  1397. Won't run here if violates L R\W\X permission check!
  1398. .. _design_app_demo_cidu:
  1399. demo_cidu
  1400. ~~~~~~~~~
  1401. This `demo_cidu application`_ is used to demonstrate External Interrupt Distribution
  1402. (external interrupt broadcast/first come first claim), Inter Core interrupt and Semaphore
  1403. of Cluster Interrupt Distribution Unit (CIDU).
  1404. This demo requests the SMP cores share the same RAM and ROM, for example, in current
  1405. evalsoc/demosoc system, ilm/dlm are private resource for cpu, only the DDR/SRAM memory are shared resource
  1406. for all the cpu.
  1407. .. note::
  1408. * It doesn't work with gd32vf103 processor.
  1409. * It needs Nuclei SMP CPU configured with CIDU feature
  1410. * It needs Nuclei EvalSoC's uart and its interrupt, if you want to port it, you need to port uart driver of your SoC
  1411. * Need to enable CIDU in <Device.h> if CIDU present in cluster.
  1412. * Multicore SoC is needed.
  1413. * ``UART0`` receive is used as external interrupt, registered as ``eclic_uart0_int_handler``, which is the best choice
  1414. for evalsoc/demosoc and is easy to trigger by writing the serial terminal
  1415. * ``UART0`` receive interrupt can be broadcast to all the cores or some, and also first coming first claim
  1416. mode will ensure only the first responding core handle the interrupt service routine(ISR)
  1417. * Inter core interrupt shows likes this: core3 sends interrupt to core2, core2 sends interrupt to core1,
  1418. core1 sends interrupt to core0, and core0 sends interrupt to core3, registered as ``eclic_inter_core_int_handler``,
  1419. supposing the SoC is four cores, and etc.
  1420. * To demonstrate it will handle properly if multiple cores send interrupt to one core simultaneously,
  1421. besides core2, core0 also sends interrupt to core1, supposing the SoC is four core
  1422. * To protect ``UART0`` resource when multicores want to access it(call ``printf``), semaphore is configured, which needs to
  1423. be acquired successfully before accessing ``UART0``, and release it after job done
  1424. * ``ENABLE_FIRST_COME_FIRST_CLAIM_MODE`` is defined by default, you can comment it to just use broadcast mode
  1425. **How to run this application:**
  1426. .. code-block:: shell
  1427. # Assume that you can set up the Tools and Nuclei SDK environment
  1428. # Use Nuclei UX900 SMP 2/4/8(4/8 is better) Core RISC-V processor as example
  1429. # application needs to run in ddr memory not in ilm memory
  1430. # cd to the demo_cidu directory
  1431. cd application/baremetal/demo_cidu
  1432. # Since Nuclei SDK 0.7.0, if you are sure CFG_HAS_IDU is not defined in cpufeature.h, but you have CIDU
  1433. # you can pass extra make variable XLCFG_CIDU=1 during make command to tell sdk
  1434. # the cidu present, it will define CFG_HAS_IDU
  1435. # Clean the application first
  1436. make SOC=evalsoc BOARD=nuclei_fpga_eval SMP=4 CORE=ux900 clean
  1437. # Build and upload the application
  1438. make SOC=evalsoc BOARD=nuclei_fpga_eval SMP=4 CORE=ux900 upload
  1439. **Expected output(inter core interrupt) as below:**
  1440. .. code-block:: console
  1441. Nuclei SDK Build Time: Feb 10 2023, 18:39:17
  1442. Download Mode: SRAM
  1443. CPU Frequency 100602675 Hz
  1444. CPU HartID: 0
  1445. Core 3 has received interrupt from core 0
  1446. Core 1 has received interrupt from core 0
  1447. Core 2 has received interrupt from core 3
  1448. Core 1 has received interrupt from core 2
  1449. Core 0 has received interrupt from core 1
  1450. From output, each core sends interrupt in order, and core 1 has received interrupts from
  1451. both core 0 and core 2.
  1452. **Expected output(write anything to the serial terminal, enable first come first claim mode) as below:**
  1453. .. code-block:: console
  1454. Nuclei SDK Build Time: Feb 10 2023, 18:44:45
  1455. Download Mode: SRAM
  1456. CPU Frequency 100612833 Hz
  1457. CPU HartID: 0
  1458. Core 3 has received interrupt from core 0
  1459. Core 1 has received interrupt from core 0
  1460. Core 2 has received interrupt from core 3
  1461. Core 1 has received interrupt from core 2
  1462. Core 0 has received interrupt from core 1
  1463. Core 2 enters uart0_receive_handler
  1464. Core 1 enters uart0_receive_handler
  1465. Core 2 wants to process rx input
  1466. Core 2 processed input:d
  1467. Core 3 enters uart0_receive_handler
  1468. Core 0 enters uart0_receive_handler
  1469. Core 3 wants to process rx input
  1470. Core 3 enters uart0_receive_handler
  1471. Core 1 enters uart0_receive_handler
  1472. Core 3 wants to process rx input
  1473. Core 3 processed input:q
  1474. Core 0 enters uart0_receive_handler
  1475. Core 2 enters uart0_receive_handler
  1476. Core 0 wants to process rx input
  1477. Core 0 enters uart0_receive_handler
  1478. Core 1 enters uart0_receive_handler
  1479. Core 0 wants to process rx input
  1480. Core 0 processed input:s
  1481. Core 3 enters uart0_receive_handler
  1482. Core 2 enters uart0_receive_handler
  1483. Core 3 wants to process rx input
  1484. Core 1 enters uart0_receive_handler
  1485. Core 2 enters uart0_receive_handler
  1486. Core 0 enters uart0_receive_handler
  1487. Core 1 wants to process rx input
  1488. Core 1 processed input:g
  1489. Core 3 enters uart0_receive_handler
  1490. Core 3 wants to process rx input
  1491. From output, though setting interrupt broadcasted to all(all the core enters the ISR), while only one core (the first one)
  1492. can claim the the interrupt(first come first claim) then process the uart0 input, others quit when find interrupt has been claimed.
  1493. **Expected output(write anything to the serial terminal, disable first come first claim mode) as below:**
  1494. .. code-block:: console
  1495. Nuclei SDK Build Time: Feb 10 2023, 18:48:47
  1496. Download Mode: SRAM
  1497. CPU Frequency 100602675 Hz
  1498. CPU HartID: 0
  1499. Core 3 has received interrupt from core 0
  1500. Core 1 has received interrupt from core 0
  1501. Core 2 has received interrupt from core 3
  1502. Core 1 has received interrupt from core 2
  1503. Core 0 has received interrupt from core 1
  1504. Core 2 enters uart0_receive_handler
  1505. Core 0 enters uart0_receive_handler
  1506. Core 2 wants to process rx input
  1507. Core 2 processed input:q
  1508. Core 0 wants to process rx input
  1509. Core 1 enters uart0_receive_handler
  1510. Core 1 wants to process rx input
  1511. Core 3 enters uart0_receive_handler
  1512. Core 3 wants to process rx input
  1513. Core 3 enters uart0_receive_handler
  1514. Core 0 enters uart0_receive_handler
  1515. Core 1 enters uart0_receive_handler
  1516. Core 2 enters uart0_receive_handler
  1517. Core 0 wants to process rx input
  1518. Core 0 processed input:w
  1519. Core 1 wants to process rx input
  1520. Core 3 wants to process rx input
  1521. Core 2 wants to process rx input
  1522. Core 2 enters uart0_receive_handler
  1523. Core 0 enters uart0_receive_handler
  1524. Core 1 enters uart0_receive_handler
  1525. Core 1 wants to process rx input
  1526. Core 1 processed input:e
  1527. Core 0 wants to process rx input
  1528. Core 2 wants to process rx input
  1529. Core 3 enters uart0_receive_handler
  1530. Core 3 wants to process rx input
  1531. Core 3 enters uart0_receive_handler
  1532. Core 1 enters uart0_receive_handler
  1533. Core 3 wants to process rx input
  1534. Core 3 processed input:r
  1535. Core 0 enters uart0_receive_handler
  1536. Core 1 wants to process rx input
  1537. Core 0 wants to process rx input
  1538. Core 2 enters uart0_receive_handler
  1539. Core 2 wants to process rx input
  1540. From output, all the core enters the ISR(means broadcasted), while only one core can process
  1541. the uart0 input(semaphore used), when semaphore released, other core wants to handle the ISR job(means claim mode disabled),
  1542. but process nothing (keyboard input has been received and rx interrupt pending cleared) because it has been processed.
  1543. .. _design_app_demo_cache:
  1544. demo_cache
  1545. ~~~~~~~~~~
  1546. .. note::
  1547. * It doesn't work with gd32vf103 processor.
  1548. * It needs Nuclei CPU configured with CCM feature
  1549. This `demo_cache application`_ is used to demonstrate how to understand cache mechanism.
  1550. This demo requests DCache, ICache and CCM(Cache Control and Maintenance), and needs to run in DDR/SRAM memory,
  1551. because cache will bypass when run in ilm, data in dlm(private resource for cpu).
  1552. .. note::
  1553. * Need to enable DCache, ICACHE, CCM in <Device.h> if present in CPU.
  1554. * An arrary( ``ROW_SIZE`` * ``COL_SIZE`` ) called ``array_test`` is created to access its first element ``array_test[0][0]``
  1555. * Firstly, enable and invalidate all DCache, update ``array_test`` by writing a consant, the cache miss happens and will update ``array_test``'s
  1556. mapping value in DCache, read out ``array_test[0][0]``; then disable the Dcache, init array_test in the ddr memory to different constant,
  1557. 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
  1558. * 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]``,
  1559. and compare with the one before
  1560. * **For further understanding**, if the CPU has configured ``HPM`` (Hardware Performance Monitor), observe the cache miss count by recording the cache miss
  1561. of updating array_test with DCache invalid, then compared to updating array_test with keeping DCache valid; also, compare the cache miss
  1562. count of updating array_test row by row with column by column
  1563. * ``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
  1564. updating ``array_test`` row by row and column by column
  1565. * 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
  1566. * When ``HPM`` used, because there's global variables in ``HPM_START`` and ``HPM_END`` , **these will bring 3 cache miss itself** (not considering cached)
  1567. * You can manage ICache apis like DCache, which skipped in this demo for less similar code
  1568. * Different compile optimization level such as -O2/-O0 effects cache miss
  1569. .. note::
  1570. * There's ``printf`` hidden in ``HPM_END``, if there is another HPM_END before it, the ``printf`` will bring about 10 or more cache miss
  1571. **How to run this application:**
  1572. .. code-block:: shell
  1573. # Assume that you can set up the Tools and Nuclei SDK environment
  1574. # Use Nuclei UX900 Core RISC-V processor as example
  1575. # application needs to run in ddr memory not in ilm memory
  1576. # cd to the demo_cache directory
  1577. cd application/baremetal/demo_cache
  1578. # Since Nuclei SDK 0.7.0, if you are sure CFG_HAS_IOCC is not defined in cpufeature.h, but you have CCM
  1579. # you can pass extra make variable XLCFG_CCM=1 during make command to tell sdk
  1580. # the ccm present, it will define CFG_HAS_IOCC
  1581. # Clean the application first
  1582. make SOC=evalsoc BOARD=nuclei_fpga_eval CORE=ux900 clean
  1583. # Build and upload the application
  1584. make SOC=evalsoc BOARD=nuclei_fpga_eval CORE=ux900 upload
  1585. **Expected output(DISABLE_NMSIS_HPM defined) as below:**
  1586. .. code-block:: console
  1587. Nuclei SDK Build Time: Feb 14 2023, 18:14:18
  1588. Download Mode: SRAM
  1589. CPU Frequency 100605952 Hz
  1590. CPU HartID: 0
  1591. DCache Linesize is 64 bytes, ways is 2, setperway is 512, total size is 65536 bytes
  1592. array_test 10 * 64 bytes
  1593. ------Update array in memory------
  1594. ------Update array to all 0xab in cache: array_update_by_row------
  1595. -------Keep DCache valid, do array_update_by_row again-------
  1596. -------Invalidate all the Dcache-------
  1597. ------Update array to all 0xab in cache: array_update_by_col ------
  1598. Read out array_test[0][0] 0xab in cache, then disable DCache
  1599. ------Init array in memory to all 0x34------
  1600. Read out array_test[0][0] 0x34 in memory, then enable Dcache
  1601. After cache flushed to memory, array_test[0][0] in memory is 0xab
  1602. ------Again init array in memory to all 0x34, then enable DCache------
  1603. Read out array_test[0][0] 0x34 in memory
  1604. Read out array_test[0][0] 0xab in cache, when mapped value in memory has changed
  1605. From output, ``array_test`` is updated in memory to all 0xab, and **cached in DCache** when miss happens,
  1606. then disable DCache, init array_test just in memory to all 0x34, **after cache flushed to memory**,
  1607. ``array_test`` in memory is all 0xab same with ``array_test`` in DCache. **Disable DCache and init array_test
  1608. again**, ``array_test`` now (all 0x34) differs with cached array_test (all 0xab) after DCache enabled.
  1609. **Expected output(DISABLE_NMSIS_HPM undefined) as below:**
  1610. .. code-block:: console
  1611. Nuclei SDK Build Time: Feb 14 2023, 18:19:17
  1612. Download Mode: SRAM
  1613. CPU Frequency 100612177 Hz
  1614. CPU HartID: 0
  1615. DCache Linesize is 64 bytes, ways is 2, setperway is 512, total size is 65536 bytes
  1616. array_test 10 * 64 bytes
  1617. ------Update array in memory------
  1618. High performance monitor initialized
  1619. ------Update array to all 0xab in cache: array_update_by_row------
  1620. HPM4:0xf0000021, array_update_by_row_dcache_miss, 13
  1621. -------Keep DCache valid, do array_update_by_row again-------
  1622. HPM4:0xf0000021, array_update_by_row_dcache_miss, 2
  1623. -------Invalidate all the Dcache-------
  1624. ------Update array to all 0xab in cache: array_update_by_col ------
  1625. HPM4:0xf0000021, array_update_by_col_dcache_miss, 12
  1626. Read out array_test[0][0] 0xab in cache, then disable DCache
  1627. ------Init array in memory to all 0x34------
  1628. Read out array_test[0][0] 0x34 in memory, then enable Dcache
  1629. After cache flushed to memory, array_test[0][0] in memory is 0xab
  1630. ------Again init array in memory to all 0x34, then enable DCache------
  1631. Read out array_test[0][0] 0x34 in memory
  1632. Read out array_test[0][0] 0xab in cache, when mapped value in memory has changed
  1633. HPM4:0xf0000021, dcachemiss_readonebyte, 4
  1634. From output, ``HPM`` is enabled, cache miss is counted and ``array_test`` size is 10 * 64 bytes.
  1635. **At first, DCache is invalid**, the first time ``array_test`` update by row has 10 miss(HPM4 shows 13,
  1636. because HPM itself brings in 3 miss); **Keep DCache valid**, update array_test by row again, cache miss
  1637. decreases to 2(``HPM`` itself brings in), which means ``array_test`` has already cached;
  1638. **Then invalidate all the Dcache**, array_test update by col seems has the same cache miss as update by row.
  1639. **Expected output(BIG_ROW_SIZE defined, DISABLE_NMSIS_HPM undefined) as below:**
  1640. .. code-block:: console
  1641. Nuclei SDK Build Time: Feb 14 2023, 18:22:17
  1642. Download Mode: SRAM
  1643. CPU Frequency 100612177 Hz
  1644. CPU HartID: 0
  1645. DCache Linesize is 64 bytes, ways is 2, setperway is 512, total size is 65536 bytes
  1646. array_test 2048 * 64 bytes
  1647. ------Update array in memory------
  1648. High performance monitor initialized
  1649. ------Update array to all 0xab in cache: array_update_by_row------
  1650. HPM4:0xf0000021, array_update_by_row_dcache_miss, 2052
  1651. -------Keep DCache valid, do array_update_by_row again-------
  1652. HPM4:0xf0000021, array_update_by_row_dcache_miss, 1301
  1653. -------Invalidate all the Dcache-------
  1654. ------Update array to all 0xab in cache: array_update_by_col ------
  1655. HPM4:0xf0000021, array_update_by_col_dcache_miss, 88336
  1656. Read out array_test[0][0] 0xab in cache, then disable DCache
  1657. ------Init array in memory to all 0x34------
  1658. Read out array_test[0][0] 0x34 in memory, then enable Dcache
  1659. After cache flushed to memory, array_test[0][0] in memory is 0xab
  1660. ------Again init array in memory to all 0x34, then enable DCache------
  1661. Read out array_test[0][0] 0x34 in memory
  1662. Read out array_test[0][0] 0xab in cache, when mapped value in memory has changed
  1663. HPM4:0xf0000021, dcachemiss_readonebyte, 4
  1664. From output, ``array_test`` size is enlarged to ``2048 * 64`` bytes, which is **two times the size of DCache (1024 * 64 bytes)**.
  1665. Cache miss brought by ``HPM`` itself ignored, array update by col has **43 times cache miss(88336) as the array update by row has(2052)**.
  1666. That's because when first byte access brings one cache misse, **one cache line(64 bytes in this demo) is fetched to cache**,
  1667. and it works best if other 63 cached bytes can be accessed before getting dirty as soon as possible, as update by row does.
  1668. .. _design_app_demo_stack_check:
  1669. demo_stack_check
  1670. ~~~~~~~~~~~~~~~~
  1671. .. note::
  1672. * It doesn't work with gd32vf103 processor.
  1673. * It needs Nuclei CPU configured with stack check feature
  1674. This `demo_stack_check application`_ is used to demonstrate how to check stack overflow and underflow and track the ``sp``.
  1675. For now, this demo needs to run on **only 300 Series v4.2.0 or later**, which supports this ``Stack Check`` function.
  1676. .. note::
  1677. * The Stack Check can work as expected only when the stack downwardly grows.
  1678. * ``STACK_TOP``, ``STACK_BOTTOM``, ``STACK_SIZE`` refers to stack's high/low address and size in bytes, which gets from the linker script
  1679. * ``stack_corrupt_exception_handler`` is registered as exception handler to process stack overflow and underflow
  1680. * A simple recursive function of calculating factorial is reformed, which will consume stack more or less by the ``n`` input, thus may cause
  1681. 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
  1682. * 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
  1683. * 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
  1684. ``overflow``, ``underflow`` and ``track sp`` mode in one-time run
  1685. * 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
  1686. .. note::
  1687. * Must set the BOUND and BASE before setting the check mode
  1688. * Reserve 0x200 bytes for exception stack push/pop
  1689. **How to run this application:**
  1690. .. code-block:: shell
  1691. # Assume that you can set up the Tools and Nuclei SDK environment
  1692. # Use Nuclei n300 Core RISC-V processor as example
  1693. # cd to the demo_stack_check directory
  1694. cd application/baremetal/demo_stack_check
  1695. # Clean the application first
  1696. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ddr CORE=n300 clean
  1697. # Build and upload the application
  1698. make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ddr CORE=n300 upload
  1699. **Expected output as below:**
  1700. .. code-block:: console
  1701. Nuclei SDK Build Time: Oct 18 2023, 18:45:02
  1702. Download Mode: ILM
  1703. CPU Frequency 15996682 Hz
  1704. CPU HartID: 0
  1705. Stack's top high address: 0x90010000, stack's bottom low address: 0x9000fa00, stack size: 0x600
  1706. --------OVERFLOW CHECK MODE--------
  1707. BOUND register set to: 0x9000fa00
  1708. BASE register set to: 0x90010000
  1709. Stack overflow fault occurs at iteration 84, cause: 0x30000018, epc: 0x80000e90, sp: 0x9000f990
  1710. --------UNDERFLOW CHECK MODE--------
  1711. BASE register set to: 0x9000fd00
  1712. Stack underflow fault occurs at iteration 1, cause: 0x30000019, epc: 0x80000fd0, sp: 0x9000fd00
  1713. BASE register set to: 0x90010000
  1714. --------TRACK SP MODE--------
  1715. BOUND register set to: 0x90010000
  1716. Iterations: 1, stack bound: 0x9000fdc0
  1717. Iterations: 2, stack bound: 0x9000fd70
  1718. Iterations: 3, stack bound: 0x9000fd20
  1719. Iterations: 4, stack bound: 0x9000fcd0
  1720. Iterations: 5, stack bound: 0x9000fc80
  1721. Iterations: 6, stack bound: 0x9000fc30
  1722. Iterations: 7, stack bound: 0x9000fbe0
  1723. Iterations: 8, stack bound: 0x9000fb90
  1724. Iterations: 9, stack bound: 0x9000fb40
  1725. Iterations: 10, stack bound: 0x9000faf0
  1726. Iterations: 11, stack bound: 0x9000faa0
  1727. Iterations: 12, stack bound: 0x9000fa50
  1728. Iterations: 13, stack bound: 0x9000fa00
  1729. Iterations: 14, stack bound: 0x9000f9b0
  1730. Iterations: 15, stack bound: 0x9000f960
  1731. Iterations: 16, stack bound: 0x9000f910
  1732. Iterations: 17, stack bound: 0x9000f8c0
  1733. Iterations: 18, stack bound: 0x9000f870
  1734. Calculate factorial over, the max stack used downwards to: 0x9000f820
  1735. Rerun it. The BOUND won't track sp if sp is bigger:
  1736. Iterations: 1, stack bound: 0x9000f820
  1737. Iterations: 2, stack bound: 0x9000f820
  1738. Iterations: 3, stack bound: 0x9000f820
  1739. Iterations: 4, stack bound: 0x9000f820
  1740. Iterations: 5, stack bound: 0x9000f820
  1741. Stack check demo over!
  1742. FreeRTOS applications
  1743. ---------------------
  1744. .. _design_app_freertos_demo:
  1745. demo
  1746. ~~~~
  1747. This `freertos demo application`_ is to show basic freertos task functions.
  1748. * Two freertos tasks are created
  1749. * A software timer is created
  1750. In Nuclei SDK, we provided code and Makefile for this ``freertos demo`` application.
  1751. * **RTOS = FreeRTOS** is added in its Makefile to include FreeRTOS service
  1752. * The **configTICK_RATE_HZ** in ``FreeRTOSConfig.h`` is set to 100, you can change it
  1753. to other number according to your requirement.
  1754. **How to run this application:**
  1755. .. code-block:: shell
  1756. # Assume that you can set up the Tools and Nuclei SDK environment
  1757. # cd to the freertos demo directory
  1758. cd application/freertos/demo
  1759. # Clean the application first
  1760. make SOC=gd32vf103 clean
  1761. # Build and upload the application
  1762. make SOC=gd32vf103 upload
  1763. **Expected output as below:**
  1764. .. code-block:: console
  1765. Nuclei SDK Build Time: Feb 21 2020, 14:56:00
  1766. Download Mode: FLASHXIP
  1767. CPU Frequency 109058823 Hz
  1768. Before StartScheduler
  1769. Enter to task_1
  1770. task1 is running 0.....
  1771. Enter to task_2
  1772. task2 is running 0.....
  1773. timers Callback 0
  1774. timers Callback 1
  1775. task1 is running 1.....
  1776. task2 is running 1.....
  1777. timers Callback 2
  1778. timers Callback 3
  1779. task1 is running 2.....
  1780. task2 is running 2.....
  1781. timers Callback 4
  1782. timers Callback 5
  1783. task1 is running 3.....
  1784. task2 is running 3.....
  1785. timers Callback 6
  1786. timers Callback 7
  1787. task1 is running 4.....
  1788. task2 is running 4.....
  1789. timers Callback 8
  1790. timers Callback 9
  1791. task1 is running 5.....
  1792. task2 is running 5.....
  1793. timers Callback 10
  1794. timers Callback 11
  1795. .. _design_app_freertos_smpdemo:
  1796. smpdemo
  1797. ~~~~~~~
  1798. This `freertos smpdemo application`_ is to show basic freertos smp task functions.
  1799. * x freertos tasks(different priorities) are created if your cpu has x cores according to the ``SMP=x`` settings
  1800. * A software timer is created
  1801. * Need to run using **DOWNLOAD=sram** mode
  1802. In Nuclei SDK, we provided code and Makefile for this ``freertos smpdemo`` application.
  1803. * **RTOS = FreeRTOS** is added in its Makefile to include FreeRTOS service
  1804. * The **configTICK_RATE_HZ** in ``FreeRTOSConfig.h`` is set to 100, you can change it
  1805. to other number according to your requirement.
  1806. **How to run this application:**
  1807. .. code-block:: shell
  1808. # Assume that you can set up the Tools and Nuclei SDK environment
  1809. # cd to the freertos demo directory
  1810. cd application/freertos/smpdemo
  1811. # This need to run on NX900 SMPx2 CPU
  1812. # Clean the application first
  1813. make clean
  1814. # Build and upload the application
  1815. make upload
  1816. **Expected output as below:**
  1817. .. code-block:: console
  1818. Nuclei SDK Build Time: May 28 2024, 13:17:41
  1819. Download Mode: SRAM
  1820. CPU Frequency 50322800 Hz
  1821. CPU HartID: 0
  1822. Startup FreeRTOS SMP on hartid 0
  1823. Enter to task 1
  1824. task 1 prio 1 is running 0 on hart 0.....
  1825. Enter to task 0
  1826. task 0 prio 0 is running 0 on hart 0.....
  1827. task 1 prio 1 is running 1 on hart 1.....
  1828. task 0 prio 0 is running 1 on hart 0.....
  1829. task 1 prio 1 is running 2 on hart 1.....
  1830. task 0 prio 0 is running 2 on hart 0.....
  1831. task 1 prio 1 is running 3 on hart 1.....
  1832. task 0 prio 0 is running 3 on hart 0.....
  1833. task 1 prio 1 is running 4 on hart 1.....
  1834. task 0 prio 0 is running 4 on hart 0.....
  1835. task 1 prio 1 is running 5 on hart 0.....
  1836. timers Callback 0 on hart 1
  1837. task 0 prio 0 is running 5 on hart 1.....
  1838. task 1 prio 1 is running 6 on hart 1.....
  1839. task 0 prio 0 is running 6 on hart 0.....
  1840. task 1 prio 1 is running 7 on hart 1.....
  1841. task 0 prio 0 is running 7 on hart 0.....
  1842. task 1 prio 1 is running 8 on hart 1.....
  1843. task 0 prio 0 is running 8 on hart 0.....
  1844. task 1 prio 1 is running 9 on hart 1.....
  1845. task 0 prio 0 is running 9 on hart 0.....
  1846. task 1 prio 1 is running 10 on hart 0.....
  1847. timers Callback 1 on hart 1
  1848. UCOSII applications
  1849. -------------------
  1850. .. _design_app_ucosii_demo:
  1851. demo
  1852. ~~~~
  1853. This `ucosii demo application`_ is show basic ucosii task functions.
  1854. * 4 tasks are created
  1855. * 1 task is created first, and then create 3 other tasks and then suspend itself
  1856. In Nuclei SDK, we provided code and Makefile for this ``ucosii demo`` application.
  1857. * **RTOS = UCOSII** is added in its Makefile to include UCOSII service
  1858. * The **OS_TICKS_PER_SEC** in ``os_cfg.h`` is by default set to 50, you can change it
  1859. to other number according to your requirement.
  1860. .. note:
  1861. * For Nuclei SDK release > v0.2.2, the UCOSII source code is replaced using the
  1862. version from https://github.com/SiliconLabs/uC-OS2/, and application development
  1863. for UCOSII is also changed, the ``app_cfg.h``, ``os_cfg.h`` and ``app_hooks.c`` files
  1864. are required in application source code.
  1865. **How to run this application:**
  1866. .. code-block:: shell
  1867. # Assume that you can set up the Tools and Nuclei SDK environment
  1868. # cd to the ucosii demo directory
  1869. cd application/ucosii/demo
  1870. # Clean the application first
  1871. make SOC=gd32vf103 clean
  1872. # Build and upload the application
  1873. make SOC=gd32vf103 upload
  1874. **Expected output as below:**
  1875. .. code-block:: console
  1876. Nuclei SDK Build Time: Feb 21 2020, 15:00:35
  1877. Download Mode: FLASHXIP
  1878. CPU Frequency 108524271 Hz
  1879. Start ucosii...
  1880. create start task success
  1881. start all task...
  1882. task3 is running... 1
  1883. task2 is running... 1
  1884. task1 is running... 1
  1885. task3 is running... 2
  1886. task2 is running... 2
  1887. task3 is running... 3
  1888. task2 is running... 3
  1889. task1 is running... 2
  1890. task3 is running... 4
  1891. task2 is running... 4
  1892. task3 is running... 5
  1893. task2 is running... 5
  1894. task1 is running... 3
  1895. task3 is running... 6
  1896. task2 is running... 6
  1897. task3 is running... 7
  1898. task2 is running... 7
  1899. task1 is running... 4
  1900. task3 is running... 8
  1901. task2 is running... 8
  1902. task3 is running... 9
  1903. task2 is running... 9
  1904. task1 is running... 5
  1905. task3 is running... 10
  1906. task2 is running... 10
  1907. task3 is running... 11
  1908. task2 is running... 11
  1909. task1 is running... 6
  1910. task3 is running... 12
  1911. task2 is running... 12
  1912. RT-Thread applications
  1913. ----------------------
  1914. .. _design_app_rtthread_demo:
  1915. demo
  1916. ~~~~
  1917. This `rt-thread demo application`_ is show basic rt-thread thread functions.
  1918. * main function is a pre-created thread by RT-Thread
  1919. * main thread will create 5 test threads using the same function ``thread_entry``
  1920. In Nuclei SDK, we provided code and Makefile for this ``rtthread demo`` application.
  1921. * **RTOS = RTThread** is added in its Makefile to include RT-Thread service
  1922. * The **RT_TICK_PER_SECOND** in ``rtconfig.h`` is by default set to `100`, you can change it
  1923. to other number according to your requirement.
  1924. **How to run this application:**
  1925. .. code-block:: shell
  1926. # Assume that you can set up the Tools and Nuclei SDK environment
  1927. # cd to the rtthread demo directory
  1928. cd application/rtthread/demo
  1929. # Clean the application first
  1930. make SOC=gd32vf103 clean
  1931. # Build and upload the application
  1932. make SOC=gd32vf103 upload
  1933. **Expected output as below:**
  1934. .. code-block:: console
  1935. Nuclei SDK Build Time: Apr 14 2020, 10:14:30
  1936. Download Mode: FLASHXIP
  1937. CPU Frequency 108270000 Hz
  1938. \ | /
  1939. - RT - Thread Operating System
  1940. / | \ 3.1.3 build Apr 14 2020
  1941. 2006 - 2019 Copyright by rt-thread team
  1942. Main thread count: 0
  1943. thread 0 count: 0
  1944. thread 1 count: 0
  1945. thread 2 count: 0
  1946. thread 3 count: 0
  1947. thread 4 count: 0
  1948. thread 0 count: 1
  1949. thread 1 count: 1
  1950. thread 2 count: 1
  1951. thread 3 count: 1
  1952. thread 4 count: 1
  1953. Main thread count: 1
  1954. thread 0 count: 2
  1955. thread 1 count: 2
  1956. thread 2 count: 2
  1957. thread 3 count: 2
  1958. thread 4 count: 2
  1959. thread 0 count: 3
  1960. thread 1 count: 3
  1961. thread 2 count: 3
  1962. thread 3 count: 3
  1963. thread 4 count: 3
  1964. Main thread count: 2
  1965. thread 0 count: 4
  1966. thread 1 count: 4
  1967. .. _design_app_rtthread_msh:
  1968. msh
  1969. ~~~
  1970. This `rt-thread msh application`_ demonstrates msh shell in serial console which is a component of rt-thread.
  1971. * ``MSH_CMD_EXPORT(nsdk, msh nuclei sdk demo)`` exports a command ``nsdk`` to msh shell
  1972. In Nuclei SDK, we provided code and Makefile for this ``rtthread msh`` application.
  1973. * **RTOS = RTThread** is added in its Makefile to include RT-Thread service
  1974. * **RTTHREAD_MSH := 1** is added in its Makefile to include RT-Thread msh component
  1975. * The **RT_TICK_PER_SECOND** in ``rtconfig.h`` is by default set to `100`, you can change it
  1976. to other number according to your requirement.
  1977. * To run this application in :ref:`design_soc_evalsoc`, the SoC clock frequency must be above 16MHz,
  1978. if run in 8MHz, uart read is not correct due to bit error in uart rx process.
  1979. **How to run this application:**
  1980. .. code-block:: shell
  1981. # Assume that you can set up the Tools and Nuclei SDK environment
  1982. # cd to the rtthread msh directory
  1983. cd application/rtthread/msh
  1984. # Clean the application first
  1985. make SOC=gd32vf103 clean
  1986. # Build and upload the application
  1987. make SOC=gd32vf103 upload
  1988. **Expected output as below:**
  1989. .. code-block:: console
  1990. Nuclei SDK Build Time: Dec 23 2020, 16:39:21
  1991. Download Mode: FLASHXIP
  1992. CPU Frequency 108810000 Hz
  1993. \ | /
  1994. - RT - Thread Operating System
  1995. / | \ 3.1.3 build Dec 23 2020
  1996. 2006 - 2019 Copyright by rt-thread team
  1997. Hello RT-Thread!
  1998. msh >help
  1999. RT-Thread shell commands:
  2000. list_timer - list timer in system
  2001. list_mailbox - list mail box in system
  2002. list_sem - list semaphore in system
  2003. list_thread - list thread
  2004. version - show RT-Thread version information
  2005. ps - List threads in the system.
  2006. help - RT-Thread shell help.
  2007. nsdk - msh nuclei sdk demo
  2008. msh >ps
  2009. thread pri status sp stack size max used left tick error
  2010. -------- --- ------- ---------- ---------- ------ ---------- ---
  2011. tshell 6 ready 0x00000178 0x00001000 09% 0x00000008 000
  2012. tidle 7 ready 0x00000078 0x0000018c 30% 0x00000020 000
  2013. main 2 suspend 0x000000b8 0x00000200 35% 0x00000013 000
  2014. msh >nsdk
  2015. Hello Nuclei SDK!
  2016. msh >
  2017. ThreadX applications
  2018. --------------------
  2019. .. _design_app_threadx_demo:
  2020. demo
  2021. ~~~~
  2022. This `threadx demo application`_ is show basic ThreadX thread functions.
  2023. This threadx demo is modified based on https://github.com/eclipse-threadx/threadx/blob/v6.4.1_rel/samples/demo_threadx.c
  2024. In Nuclei SDK, we provided code and Makefile for this ``threadx demo`` application.
  2025. * **RTOS = ThreadX** is added in its Makefile to include ThreadX service
  2026. * The **TX_INCLUDE_USER_DEFINE_FILE** macro is defined in Makefile, so you can include customized user configuration
  2027. file ``tx_user.h``
  2028. **How to run this application:**
  2029. .. code-block:: shell
  2030. # Assume that you can set up the Tools and Nuclei SDK environment
  2031. # cd to the threadx demo directory
  2032. cd application/threadx/demo
  2033. # Clean the application first
  2034. make SOC=evalsoc clean
  2035. # Build and upload the application
  2036. make SOC=evalsoc upload
  2037. **Expected output as below:**
  2038. .. code-block:: console
  2039. Nuclei SDK Build Time: May 28 2024, 13:26:41
  2040. Download Mode: ILM
  2041. CPU Frequency 50322800 Hz
  2042. CPU HartID: 0
  2043. thread 6_7 is running, current is 6, thread 6 counter 1, thread 7 counter 1
  2044. thread 6_7 is running, current is 7, thread 6 counter 2, thread 7 counter 1
  2045. thread 6_7 is running, current is 6, thread 6 counter 2, thread 7 counter 2
  2046. thread 6_7 is running, current is 7, thread 6 counter 3, thread 7 counter 2
  2047. thread 6_7 is running, current is 6, thread 6 counter 3, thread 7 counter 3
  2048. thread 6_7 is running, current is 7, thread 6 counter 4, thread 7 counter 3
  2049. thread 6_7 is running, current is 6, thread 6 counter 4, thread 7 counter 4
  2050. thread 6_7 is running, current is 7, thread 6 counter 5, thread 7 counter 4
  2051. .. _helloworld application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/helloworld
  2052. .. _cpuinfo application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/cpuinfo
  2053. .. _demo_timer application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_timer
  2054. .. _demo_clint_timer application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_clint_timer
  2055. .. _demo_eclic application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_eclic
  2056. .. _demo_plic application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_plic
  2057. .. _demo_dsp application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_dsp
  2058. .. _smphello application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/smphello
  2059. .. _lowpower application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/lowpower
  2060. .. _demo_nice application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_nice
  2061. .. _demo_vnice application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_vnice
  2062. .. _coremark benchmark application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/benchmark/coremark
  2063. .. _dhrystone benchmark application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/benchmark/dhrystone
  2064. .. _whetstone benchmark application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/benchmark/whetstone
  2065. .. _freertos demo application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/freertos/demo
  2066. .. _freertos smpdemo application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/freertos/smpdemo
  2067. .. _ucosii demo application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/ucosii/demo
  2068. .. _rt-thread demo application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/rtthread/demo
  2069. .. _rt-thread msh application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/rtthread/msh
  2070. .. _threadx demo application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/threadx/demo
  2071. .. _demo_smode_eclic application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_smode_eclic
  2072. .. _demo_spmp application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_spmp
  2073. .. _demo_smpu application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_smpu
  2074. .. _demo_pmp application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_pmp
  2075. .. _demo_profiling application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_profiling
  2076. .. _demo_cidu application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_cidu
  2077. .. _demo_cache application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_cache
  2078. .. _demo_stack_check application: https://github.com/Nuclei-Software/nuclei-sdk/tree/master/application/baremetal/demo_stack_check
  2079. .. _Nuclei User Extended Introduction: https://doc.nucleisys.com/nuclei_spec/isa/nice.html