quickstart.rst 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. .. _quickstart:
  2. Quick Startup
  3. =============
  4. .. _quickstart_using_nside:
  5. Use Nuclei SDK in Nuclei Studio
  6. -------------------------------
  7. .. caution::
  8. For Nuclei SDK 0.3.5 version and later ones, please use Nuclei Studio 2022.01 or
  9. Nuclei GNU Toolchain/OpenOCD/QEMU 2022.01.
  10. From **2020.08** release version of Nuclei Studio IDE, the nuclei-sdk **released**
  11. version will be deeply integrated with Nuclei Studio, and you can directly create
  12. nuclei-sdk project in Nuclei Studio IDE.
  13. You can download **Nuclei Studio IDE** from |nuclei_download_center|, and follow
  14. `Nuclei_Studio_User_Guide.pdf`_ to learn how to use it.
  15. But if you want to use latest source code of Nuclei SDK, please follow the rest
  16. part of this guide to build and run using Nuclei SDK Build System in Makefile.
  17. .. _quickstart_setup_tools_env:
  18. Setup Tools and Environment
  19. ---------------------------
  20. To start to use Nuclei SDK, you need to install the following tools:
  21. From **2020.10** release version of Nuclei Studio, you can directly use the prebuilt tools
  22. provided in Nuclei Studio(**strongly suggested**), please check :ref:`quickstart_setup_tools_env_nside`.
  23. If you want to use latest toolchain, you can follow guides below:
  24. * For Windows users, please check :ref:`quickstart_setup_tools_env_windows`
  25. * For Linux users, please check :ref:`quickstart_setup_tools_env_linux`
  26. .. _quickstart_setup_tools_env_nside:
  27. Use Prebuilt Tools in Nuclei Studio
  28. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  29. Since **2020.10** release version of Nuclei Studio, you just need to download the
  30. **Nuclei Studio IDE** from |nuclei_download_center| for your development OS, and
  31. no need to do the following steps below, the prebuilt tools are already included.
  32. For example:
  33. * In Windows, if you have extracted the Nuclei Studio IDE to ``D:\Software\NucleiStudio_IDE_202010``,
  34. then you can find the prebuilt tools in ``D:\Software\NucleiStudio_IDE_202010\NucleiStudio\toolchain``.
  35. * In Linux, if you have extracted the Nuclei Studio IDE to ``/home/labdev/NucleiStudio_IDE_202010``,
  36. then you can find the prebuilt tools in ``/home/labdev/NucleiStudio_IDE_202010/NucleiStudio/toolchain``.
  37. If you have downloaded and extracted the Nuclei Studio, then you can jump to :ref:`quickstart_get_set_nuclei_sdk`.
  38. .. _quickstart_setup_tools_env_windows:
  39. Install and Setup Tools in Windows
  40. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  41. Make sure you are using at least **Windows 7**, and then you can follow the following steps
  42. to download and install tools for you.
  43. 1. Create an ``Nuclei`` folder in your Windows Environment, such as ``D:\Software\Nuclei``
  44. 2. Download the following tools from |nuclei_download_center|, please check and follow
  45. the figure :ref:`figure_quickstart_1`.
  46. - **Nuclei RISC-V GNU Toolchain for Windows**, see number **1** in the figure :ref:`figure_quickstart_1`
  47. - **Nuclei OpenOCD for Windows**, see number **2** in the figure :ref:`figure_quickstart_1`
  48. - **Windows Build Tools**, see number **3** in the figure :ref:`figure_quickstart_1`
  49. .. _figure_quickstart_1:
  50. .. figure:: /asserts/images/nuclei_tools_download_win.png
  51. :width: 80 %
  52. :align: center
  53. :alt: Nuclei Tools need to be downloaded for Windows
  54. Nuclei Tools need to be downloaded for Windows
  55. 3. Setup tools in previously created ``Nuclei`` folder, create ``gcc``, ``openocd`` and ``build-tools`` folders.
  56. - **Nuclei RISC-V GNU Toolchain for Windows**
  57. Extract the download **gnu toolchain** into a temp folder, and copy the files into ``gcc`` folder,
  58. make sure the ``gcc`` directory structure looks like this figure :ref:`figure_quickstart_2`
  59. .. _figure_quickstart_2:
  60. .. figure:: /asserts/images/nuclei_tool_gcc_directory.png
  61. :width: 80 %
  62. :align: center
  63. :alt: Nuclei RISC-V GCC Toolchain directory structure of gcc
  64. Nuclei RISC-V GCC Toolchain directory structure of gcc
  65. - **Nuclei OpenOCD for Windows**
  66. Extract the download **openocd** tool into a temp folder, and copy the files into ``openocd`` folder,
  67. make sure the ``openocd`` directory structure looks like this figure :ref:`figure_quickstart_3`
  68. .. _figure_quickstart_3:
  69. .. figure:: /asserts/images/nuclei_tool_openocd_directory.png
  70. :width: 80 %
  71. :align: center
  72. :alt: Nuclei OpenOCD directory structure of openocd
  73. Nuclei OpenOCD directory structure of openocd
  74. - **Windows Build Tools**
  75. Extract the download **build-tools** tool into a temp folder, and copy the files into ``build-tools`` folder,
  76. make sure the ``build-tools`` directory structure looks like this figure :ref:`figure_quickstart_4`
  77. .. _figure_quickstart_4:
  78. .. figure:: /asserts/images/nuclei_tool_build-tools_directory.png
  79. :width: 80 %
  80. :align: center
  81. :alt: Nuclei Windows Build Tools directory structure of build-tools
  82. Nuclei Windows Build Tools directory structure of build-tools
  83. If you have setuped the prebuilt tools in Windows, then you can jump to :ref:`quickstart_get_set_nuclei_sdk`.
  84. .. _quickstart_setup_tools_env_linux:
  85. Install and Setup Tools in Linux
  86. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  87. Make sure you are using **Centos or Ubuntu 64 bit**, and then you can follow the following steps
  88. to download and install tools for you.
  89. 1. Create an ``Nuclei`` folder in your Linux Environment, such as ``~/Software/Nuclei``
  90. 2. Download the following tools from |nuclei_download_center|, please check and follow
  91. the figure :ref:`figure_quickstart_5`.
  92. - **Nuclei RISC-V GNU Toolchain for Linux**, for **CentOS or Ubuntu** click number **1**
  93. in the figure :ref:`figure_quickstart_5`
  94. - **Nuclei OpenOCD for Linux**, see number **2-1** for 64bit version in the figure :ref:`figure_quickstart_5`
  95. - **Make >= 3.82**: Install ``Make`` using ``sudo apt-get install make`` in Ubuntu,
  96. or ``sudo yum install make`` in CentOS.
  97. .. _figure_quickstart_5:
  98. .. figure:: /asserts/images/nuclei_tools_download_linux.png
  99. :width: 80 %
  100. :align: center
  101. :alt: Nuclei Tools need to be downloaded for Linux
  102. Nuclei Tools need to be downloaded for Linux
  103. 3. Setup tools in previously created ``Nuclei`` folder, create ``gcc`` and ``openocd`` folders.
  104. Please follow similar steps described in **Step 3** in :ref:`quickstart_setup_tools_env_windows`
  105. to extract and copy necessary files.
  106. .. note::
  107. * Only ``gcc`` and ``openocd`` are required for Linux.
  108. * Extract the downloaded Linux tools, not the windows version.
  109. If you have setuped the prebuilt tools in Linux, then you can jump to :ref:`quickstart_get_set_nuclei_sdk`.
  110. .. _quickstart_get_set_nuclei_sdk:
  111. Get and Setup Nuclei SDK
  112. ------------------------
  113. The source code of Nuclei SDK is maintained in |github| and |gitee|.
  114. * We mainly maintained github version, and gitee version is mirrored, just for fast access in China.
  115. * Check source code in |github_nuclei_sdk| or |gitee_nuclei_sdk| according to your network status.
  116. * Stable version of Nuclei SDK is maintained in **master** version, if you want release version of **Nuclei SDK**,
  117. please check in |github_nuclei_sdk_release|.
  118. **Here are the steps to clone the latest source code from Github:**
  119. * Make sure you have installed Git tool, see https://git-scm.com/download/
  120. * Then open your terminal, and make sure git command can be accessed
  121. * Run ``git clone https://github.com/Nuclei-Software/nuclei-sdk nuclei-sdk`` to clone source code
  122. into ``nuclei-sdk`` folder
  123. .. note::
  124. - If you have no access to github.com, you can also use command
  125. ``git clone https://gitee.com/Nuclei-Software/nuclei-sdk nuclei-sdk`` to clone from gitee.
  126. - If you have no internet access, you can also use pre-downloaded ``nuclei-sdk`` code,
  127. and use it.
  128. - If the backup repo is not up to date, you can import github repo in gitee by yourself, see
  129. https://gitee.com/projects/import/url
  130. * Create tool environment config file for Nuclei SDK
  131. - **Windows**
  132. If you want to use Nuclei SDK in **Windows Command Prompt** terminal, you need to
  133. create ``setup_config.bat`` in ``nuclei-sdk`` folder, and open this file
  134. your editor, and paste the following content, assuming you followed
  135. :ref:`quickstart_setup_tools_env`, and prebuilt tools located in
  136. ``D:\Software\NucleiStudio_IDE_202010\NucleiStudio\toolchain``,
  137. otherwise please use your correct tool root path.
  138. .. code-block:: bat
  139. set NUCLEI_TOOL_ROOT=D:\Software\NucleiStudio_IDE_202010\NucleiStudio\toolchain
  140. If you want to use Nuclei SDK in **Windows PowerShell** terminal, you need to create
  141. a ``setup_config.ps1`` in ``nuclei-sdk`` folder, and edit this file with content below
  142. if your prebuilt tools are located in ``D:\Software\NucleiStudio_IDE_202010\NucleiStudio\toolchain``:
  143. .. code-block:: ps1
  144. $NUCLEI_TOOL_ROOT="D:\Software\NucleiStudio_IDE_202009\NucleiStudio\toolchain"
  145. - **Linux**
  146. Create ``setup_config.sh`` in ``nuclei-sdk`` folder, and open this file
  147. your editor, and paste the following content, assuming you followed
  148. :ref:`quickstart_setup_tools_env` and prebuilt tools located in
  149. ``/home/labdev/NucleiStudio_IDE_202010/NucleiStudio/toolchain``,
  150. otherwise please use your correct tool root path.
  151. .. code-block:: shell
  152. NUCLEI_TOOL_ROOT=/home/labdev/NucleiStudio_IDE_202010/NucleiStudio/toolchain
  153. .. _quickstart_buildrundebug_app:
  154. Build, Run and Debug Sample Application
  155. ---------------------------------------
  156. Assume you have followed steps in :ref:`quickstart_get_set_nuclei_sdk` to clone
  157. source code and create files below:
  158. * ``setup_config.bat`` for run in **Windows Command Prompt** terminal
  159. * ``setup_config.ps1`` for run in **Windows PowerShell** terminal
  160. * ``setup_config.sh`` for run in **Linux Bash** terminal
  161. To build, run and debug application, you need to open command terminal in ``nuclei-sdk``
  162. folder.
  163. * For **Windows** users, you can open **Windows Command Prompt** terminal and cd to ``nuclei-sdk`` folder,
  164. then run the following commands to setup build environment for Nuclei SDK, the output will
  165. be similar as this screenshot :ref:`figure_quickstart_6`:
  166. .. code-block:: bat
  167. :linenos:
  168. setup.bat
  169. echo %PATH%
  170. where riscv-nuclei-elf-gcc openocd make rm
  171. make help
  172. .. _figure_quickstart_6:
  173. .. figure:: /asserts/images/nuclei_sdk_open_cmd.png
  174. :width: 80 %
  175. :align: center
  176. :alt: Setup Build Environment for Nuclei SDK in Windows Command Prompt
  177. Setup Build Environment for Nuclei SDK in Windows Command Prompt
  178. * For **Linux** users, you can open **Linux Bash** terminal and cd to ``nuclei-sdk`` folder,
  179. then run the following commands to setup build environment for Nuclei SDK, the output will
  180. be similar as this screenshot :ref:`figure_quickstart_7`:
  181. .. code-block:: shell
  182. :linenos:
  183. source setup.sh
  184. echo $PATH
  185. which riscv-nuclei-elf-gcc openocd make rm
  186. make help
  187. .. _figure_quickstart_7:
  188. .. figure:: /asserts/images/nuclei_sdk_open_shell.png
  189. :width: 80 %
  190. :align: center
  191. :alt: Setup Build Environment for Nuclei SDK in Linux Bash
  192. Setup Build Environment for Nuclei SDK in Linux Bash
  193. .. note::
  194. * Only first line ``setup.bat`` or ``source setup.sh`` are required before build, run or debug application.
  195. The ``setup.bat`` and ``setup.sh`` are just used to append Nuclei RISC-V GCC Toolchain, OpenOCD and Build-Tools
  196. binary paths into environment variable **PATH**
  197. * line 2-4 are just used to check whether build environment is setup correctly, especially the **PATH** of
  198. Nuclei Tools are setup correctly, so we can use the ``riscv-nuclei-elf-xxx``, ``openocd``, ``make`` and ``rm``
  199. tools
  200. * If you know how to append Nuclei RISC-V GCC Toolchain, OpenOCD and Build-Tools binary paths to **PATH** variable
  201. in your OS environment, you can also put the downloaded Nuclei Tools as you like, and no need to run ``setup.bat``
  202. or ``source setup.sh``
  203. * If you want to run in **Windows PowerShell**, please run ``. .\setup.ps1`` instead of ``setup.bat``, and
  204. ``setup_config.ps1`` must be created as described in :ref:`quickstart_get_set_nuclei_sdk`.
  205. Here for a quick startup, this guide will take board :ref:`design_board_gd32vf103v_rvstar`
  206. for example to demostrate how to setup hardware, build run and debug application in Windows.
  207. The demo application, we will take ``application/baremetal/helloworld`` for example.
  208. First of all, please reuse previously build environment command terminal.
  209. Run ``cd application/baremetal/helloworld`` to cd the ``helloworld`` example folder.
  210. Hardware Preparation
  211. ~~~~~~~~~~~~~~~~~~~~
  212. Please check :ref:`design_board` and find your board's page, and follow **Setup** section
  213. to setup your hardware, mainly **JTAG debugger driver setup and on-board connection setup**.
  214. * Power on the :ref:`design_board_gd32vf103v_rvstar` board, and use USB Type-C data cable to connect the board and your PC,
  215. make sure you have setup the JTAG driver correctly, and you can see JTAG port and serial port.
  216. * Open a UART terminal tool such as |teraterm| or |minicom|, and minitor the serial port of the Board,
  217. the UART baudrate is *115200 bps*
  218. * If you are building example for your own SoC and Board, please pass correct :ref:`develop_buildsystem_var_soc` and
  219. :ref:`develop_buildsystem_var_board` make variable. eg. If you SoC is ``demosoc`` and Board is ``nuclei_fpga_eval``,
  220. just pass ``SOC=demosoc BOARD=nuclei_fpga_eval`` to make instead of the one mentioned below. If your default board
  221. for this ``demosoc`` is ``nuclei_fpga_eval``, then you don't need to pass ``BOARD=nuclei_fpga_eval``.
  222. Build Application
  223. ~~~~~~~~~~~~~~~~~
  224. We need to build application for this board :ref:`design_board_gd32vf103v_rvstar` using this command line:
  225. .. code-block:: shell
  226. make SOC=gd32vf103 BOARD=gd32vf103v_rvstar all
  227. Here is the sample output of this command:
  228. .. code-block::
  229. Current Configuration: RISCV_ARCH=rv32imac RISCV_ABI=ilp32 SOC=gd32vf103 BOARD=gd32vf103v_rvstar CORE=n205 DOWNLOAD=flashxip
  230. "Assembling : " ../../../SoC/gd32vf103/Common/Source/GCC/intexc_gd32vf103.S
  231. "Assembling : " ../../../SoC/gd32vf103/Common/Source/GCC/startup_gd32vf103.S
  232. "Compiling : " ../../../SoC/gd32vf103/Board/gd32vf103v_rvstar/Source/gd32vf103v_rvstar.c
  233. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Drivers/gd32vf103_adc.c
  234. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Drivers/gd32vf103_bkp.c
  235. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Drivers/gd32vf103_can.c
  236. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Drivers/gd32vf103_crc.c
  237. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Drivers/gd32vf103_dac.c
  238. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Drivers/gd32vf103_dbg.c
  239. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Drivers/gd32vf103_dma.c
  240. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Drivers/gd32vf103_exmc.c
  241. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Drivers/gd32vf103_exti.c
  242. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Drivers/gd32vf103_fmc.c
  243. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Drivers/gd32vf103_fwdgt.c
  244. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Drivers/gd32vf103_gpio.c
  245. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Drivers/gd32vf103_i2c.c
  246. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Drivers/gd32vf103_pmu.c
  247. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Drivers/gd32vf103_rcu.c
  248. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Drivers/gd32vf103_rtc.c
  249. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Drivers/gd32vf103_spi.c
  250. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Drivers/gd32vf103_timer.c
  251. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Drivers/gd32vf103_usart.c
  252. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Drivers/gd32vf103_wwdgt.c
  253. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Stubs/close.c
  254. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Stubs/fstat.c
  255. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Stubs/gettimeofday.c
  256. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Stubs/isatty.c
  257. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Stubs/lseek.c
  258. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Stubs/read.c
  259. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Stubs/sbrk.c
  260. "Compiling : " ../../../SoC/gd32vf103/Common/Source/Stubs/write.c
  261. "Compiling : " ../../../SoC/gd32vf103/Common/Source/gd32vf103_soc.c
  262. "Compiling : " ../../../SoC/gd32vf103/Common/Source/system_gd32vf103.c
  263. "Compiling : " hello_world.c
  264. "Linking : " hello_world.elf
  265. text data bss dec hex filename
  266. 13022 112 2290 15424 3c40 hello_world.elf
  267. As you can see, that when the application is built successfully, the elf will be generated
  268. and will also print the size information of the ``hello_world.elf``.
  269. .. note::
  270. * In order to make sure that there is no application build before, you can run
  271. ``make SOC=gd32vf103 BOARD=gd32vf103v_rvstar clean`` to clean previously built
  272. objects and build dependency files.
  273. * About the make variable or option(**SOC**, **BOARD**) passed to make command, please refer
  274. to :ref:`develop_buildsystem`.
  275. Run Application
  276. ~~~~~~~~~~~~~~~
  277. If the application is built successfully for this board :ref:`design_board_gd32vf103v_rvstar`,
  278. then you can run it using this command line:
  279. .. code-block:: shell
  280. make SOC=gd32vf103 BOARD=gd32vf103v_rvstar upload
  281. Here is the sample output of this command:
  282. .. code-block::
  283. "Download and run hello_world.elf"
  284. riscv-nuclei-elf-gdb hello_world.elf -ex "set remotetimeout 240" \
  285. -ex "target remote | openocd -c \"gdb_port pipe; log_output openocd.log\" -f ../../../SoC/gd32vf103/Board/gd32vf103v_rvstar/openocd_gd32vf103.cfg" \
  286. --batch -ex "monitor halt" -ex "monitor halt" -ex "monitor flash protect 0 0 last off" -ex "load" -ex "monitor resume" -ex "monitor shutdown" -ex "quit"
  287. D:\Software\Nuclei\gcc\bin\riscv-nuclei-elf-gdb.exe: warning: Couldn't determine a path for the index cache directory.
  288. Nuclei OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev-00014-g0eae03214 (2019-12-12-07:43)
  289. Licensed under GNU GPL v2
  290. For bug reports, read
  291. http://openocd.org/doc/doxygen/bugs.html
  292. _start0800 () at ../../../SoC/gd32vf103/Common/Source/GCC/startup_gd32vf103.S:359
  293. 359 j 1b
  294. cleared protection for sectors 0 through 127 on flash bank 0
  295. Loading section .init, size 0x266 lma 0x8000000
  296. Loading section .text, size 0x2e9c lma 0x8000280
  297. Loading section .rodata, size 0x1f0 lma 0x8003120
  298. Loading section .data, size 0x70 lma 0x8003310
  299. Start address 0x800015c, load size 13154
  300. Transfer rate: 7 KB/sec, 3288 bytes/write.
  301. shutdown command invoked
  302. A debugging session is active.
  303. Inferior 1 [Remote target] will be detached.
  304. Quit anyway? (y or n) [answered Y; input not from terminal]
  305. [Inferior 1 (Remote target) detached]
  306. As you can see the application is uploaded successfully using ``openocd`` and ``gdb``,
  307. then you can check the output in your UART terminal, see :ref:`figure_quickstart_8`.
  308. .. _figure_quickstart_8:
  309. .. figure:: /asserts/images/nuclei_app_helloworld_uart.png
  310. :width: 80 %
  311. :align: center
  312. :alt: Nuclei SDK Hello World Application UART Output
  313. Nuclei SDK Hello World Application UART Output
  314. Debug Application
  315. ~~~~~~~~~~~~~~~~~
  316. If the application is built successfully for this board :ref:`design_board_gd32vf103v_rvstar`,
  317. then you can debug it using this command line:
  318. .. code-block:: shell
  319. make SOC=gd32vf103 BOARD=gd32vf103v_rvstar debug
  320. 1. The program is not loaded automatically when you enter to debug state, just in case you want to
  321. debug the program running on the board.
  322. .. code-block::
  323. "Download and debug hello_world.elf"
  324. riscv-nuclei-elf-gdb hello_world.elf -ex "set remotetimeout 240" \
  325. -ex "target remote | openocd -c \"gdb_port pipe; log_output openocd.log\" -f ../../../SoC/gd32vf103/Board/gd32vf103v_rvstar/openocd_gd32vf103.cfg"
  326. D:\Software\Nuclei\gcc\bin\riscv-nuclei-elf-gdb.exe: warning: Couldn't determine a path for the index cache directory.
  327. GNU gdb (GDB) 8.3.0.20190516-git
  328. Copyright (C) 2019 Free Software Foundation, Inc.
  329. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
  330. This is free software: you are free to change and redistribute it.
  331. There is NO WARRANTY, to the extent permitted by law.
  332. Type "show copying" and "show warranty" for details.
  333. This GDB was configured as "--host=i686-w64-mingw32 --target=riscv-nuclei-elf".
  334. Type "show configuration" for configuration details.
  335. For bug reporting instructions, please see:
  336. <http://www.gnu.org/software/gdb/bugs/>.
  337. Find the GDB manual and other documentation resources online at:
  338. <http://www.gnu.org/software/gdb/documentation/>.
  339. --Type <RET> for more, q to quit, c to continue without paging--
  340. For help, type "help".
  341. Type "apropos word" to search for commands related to "word"...
  342. Reading symbols from hello_world.elf...
  343. Remote debugging using | openocd -c \"gdb_port pipe; log_output openocd.log\" -f ../../../SoC/gd32vf103/Board/gd32vf103v_rvstar/openocd_gd32vf103.cfg
  344. Nuclei OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev-00014-g0eae03214 (2019-12-12-07:43)
  345. Licensed under GNU GPL v2
  346. For bug reports, read
  347. http://openocd.org/doc/doxygen/bugs.html
  348. _start0800 () at ../../../SoC/gd32vf103/Common/Source/GCC/startup_gd32vf103.S:359
  349. 359 j 1b
  350. 2. If you want to load the built application, you can type ``load`` to load the application.
  351. .. code-block::
  352. (gdb) load
  353. Loading section .init, size 0x266 lma 0x8000000
  354. Loading section .text, size 0x2e9c lma 0x8000280
  355. Loading section .rodata, size 0x1f0 lma 0x8003120
  356. Loading section .data, size 0x70 lma 0x8003310
  357. Start address 0x800015c, load size 13154
  358. Transfer rate: 7 KB/sec, 3288 bytes/write.
  359. 3. If you want to set a breakpoint at *main*, then you can type ``b main`` to set a breakpoint.
  360. .. code-block::
  361. (gdb) b main
  362. Breakpoint 1 at 0x8001b04: file hello_world.c, line 85.
  363. 4. If you want to set more breakpoints, you can do as you like.
  364. 5. Then you can type ``c``, then the program will stop at **main**
  365. .. code-block::
  366. (gdb) c
  367. Continuing.
  368. Note: automatically using hardware breakpoints for read-only addresses.
  369. Breakpoint 1, main () at hello_world.c:85
  370. 85 srand(__get_rv_cycle() | __get_rv_instret() | __RV_CSR_READ(CSR_MCYCLE));
  371. 6. Then you can step it using ``n`` (short of next) or ``s`` (short of step)
  372. .. code-block::
  373. (gdb) n
  374. 86 uint32_t rval = rand();
  375. (gdb) n
  376. 87 rv_csr_t misa = __RV_CSR_READ(CSR_MISA);
  377. (gdb) s
  378. 89 printf("MISA: 0x%lx\r\n", misa);
  379. (gdb) n
  380. 90 print_misa();
  381. (gdb) n
  382. 92 printf("Hello World!\r\n");
  383. (gdb) n
  384. 93 printf("Hello World!\r\n");
  385. 7. If you want to quit debugging, then you can press ``CTRL - c``, and type ``q`` to quit debugging.
  386. .. code-block::
  387. (gdb) Quit
  388. (gdb) q
  389. A debugging session is active.
  390. Inferior 1 [Remote target] will be detached.
  391. Quit anyway? (y or n) y
  392. Detaching from program: D:\workspace\Sourcecode\nuclei-sdk\application\baremetal\helloworld\hello_world.elf, Remote target
  393. Ending remote debugging.
  394. [Inferior 1 (Remote target) detached]
  395. .. note::
  396. * More about how to debug using gdb, you can refer to the `GDB User Manual`_.
  397. * If you want to debug using Nuclei Studio, you can open Nuclei Studio, and create a debug configuration,
  398. and choose the application elf, and download and debug in IDE.
  399. Create helloworld Application
  400. -----------------------------
  401. If you want to create your own ``helloworld`` application, it is also very easy.
  402. There are several ways to achieve it, see as below:
  403. * **Method 1:** You can find a most similar sample application folder and copy it, such as
  404. ``application/baremetal/helloworld``, you can copy and rename it as ``application/baremetal/hello``
  405. - Open the ``Makefile`` in ``application/baremetal/hello``
  406. 1. Change ``TARGET = hello_world`` to ``TARGET = hello``
  407. - Open the ``hello_world.c`` in ``application/baremetal/hello``, and replace the content using code below:
  408. .. code-block:: c
  409. :linenos:
  410. // See LICENSE for license details.
  411. #include <stdio.h>
  412. #include <time.h>
  413. #include <stdlib.h>
  414. #include "nuclei_sdk_soc.h"
  415. int main(void)
  416. {
  417. printf("Hello World from Nuclei RISC-V Processor!\r\n");
  418. return 0;
  419. }
  420. - Save all the changes, and then you can follow the steps described
  421. in :ref:`quickstart_buildrundebug_app` to run or debug this new application.
  422. * **Method 2:** You can also do it from scratch, with just create simple ``Makefile`` and ``main.c``
  423. - Create new folder named ``hello`` in ``application/baremetal``
  424. - Create two files named ``Makefile`` and ``main.c``
  425. - Open ``Makefile`` and edit the content as below:
  426. .. code-block:: makefile
  427. :linenos:
  428. TARGET = hello
  429. NUCLEI_SDK_ROOT = ../../..
  430. SRCDIRS = .
  431. INCDIRS = .
  432. include $(NUCLEI_SDK_ROOT)/Build/Makefile.base
  433. - Open ``main.c`` and edit the content as below:
  434. .. code-block:: c
  435. :linenos:
  436. // See LICENSE for license details.
  437. #include <stdio.h>
  438. #include <time.h>
  439. #include <stdlib.h>
  440. #include "nuclei_sdk_soc.h"
  441. int main(void)
  442. {
  443. printf("Hello World from Nuclei RISC-V Processor!\r\n");
  444. return 0;
  445. }
  446. - Save all the changes, and then you can follow the steps described
  447. in :ref:`quickstart_buildrundebug_app` to run or debug this new application.
  448. .. note::
  449. * If your are looking for how to run for other boards, please ref to :ref:`design_board`.
  450. * Please refer to :ref:`develop_appdev` and :ref:`develop_buildsystem` for more information.
  451. * If you want to access SoC related APIs, please use ``nuclei_sdk_soc.h`` header file.
  452. * If you want to access SoC and board related APIs, please use ``nuclei_sdk_hal.h`` header file.
  453. * For simplified application development, you can use ``nuclei_sdk_hal.h`` directly.
  454. .. _quickstart_advanced_usage:
  455. Advanced Usage
  456. --------------
  457. For more advanced usage, please follow the items as below:
  458. * Click :ref:`design` to learn about Nuclei SDK Design and Architecture, Board and SoC support documentation.
  459. * Click :ref:`develop` to learn about Nuclei SDK Build System and Application Development.
  460. * Click :ref:`design_app` to learn about each application usage and expected output.
  461. .. note::
  462. * If you met some issues in using this guide, please check :ref:`faq`,
  463. if still not solved, please :ref:`contribute_submit_issue`.
  464. * If you are trying to **develop Nuclei SDK application in IDE**, now you have three choices:
  465. 1. **Recommended**: Since Nuclei Studio 2020.08, Nuclei SDK will be deeply integrated with
  466. Nuclei Studio IDE, you can easily create a Nuclei SDK Project in Nuclei Studio through IDE
  467. Project Wizard, and easily configure selected Nuclei SDK project using SDK Configuration Tool,
  468. for more details, please click `Nuclei Tools`_ to download Nuclei Studio IDE, and refer to
  469. the `Nuclei_Studio_User_Guide.pdf`_ for how to use it.
  470. 2. You can take a try using Segger embedded studio, we provided prebuilt projects using Nuclei
  471. SDK release version, click `Segger embedded studio projects for Nuclei SDK`_ to learn about it
  472. 3. You can also take a try with the Cross-platform PlatformIO IDE, we provided our Nuclei platform
  473. and Nuclei SDK release version in PlatformIO, click `Platform Nuclei in PlatformIO`_ to learn
  474. more about it, or you can visit `Light on onboard LED of RVSTAR board using PlatformIO(Chinese)`_
  475. to play with PlatformIO for Nuclei.
  476. 4. You can also use source code in Nuclei SDK as base, and easily integrate with other IDE tools,
  477. such as IAR workbench for RISC-V, Compiler-IDE and others.
  478. .. _GDB User Manual: https://www.gnu.org/software/gdb/documentation/
  479. .. _Nuclei Tools: https://nucleisys.com/download.php
  480. .. _Segger embedded studio projects for Nuclei SDK: https://github.com/riscv-mcu/ses_nuclei_sdk_projects
  481. .. _Platform Nuclei in PlatformIO: https://platformio.org/platforms/nuclei
  482. .. _Nuclei_Studio_User_Guide.pdf: https://www.nucleisys.com/upload/files/doc/nucleistudio/Nuclei_Studio_User_Guide.pdf
  483. .. _Light on onboard LED of RVSTAR board using PlatformIO(Chinese): https://www.rvmcu.com/community-topic-id-310.html