contribute.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. .. _contribute:
  2. Contributing
  3. ============
  4. Contributing to Nuclei SDK project is always welcome.
  5. You can always do a lot of things to help Nuclei SDK project
  6. improve and grow stronger.
  7. * :ref:`contribute_portsoc`
  8. * :ref:`contribute_submit_issue`
  9. * :ref:`contribute_submit_pr`
  10. .. _contribute_portsoc:
  11. Port your Nuclei SoC into Nuclei SDK
  12. ------------------------------------
  13. .. note::
  14. If you just want to do quick porting based on evalsoc implementation of Nuclei SDK
  15. to get quick ramp up, you can refer to `Quick Porting to you SoC based on Evalsoc in Nuclei SDK`_
  16. If you want to port you Nuclei Processor Core based Board to Nuclei SDK,
  17. you need to follow these steps:
  18. And the best example is our evalsoc support, although it may contains many unused features you may
  19. not want to use, but it is our evaluation SoC and will supply to provide best support for Nuclei RISC-V
  20. CPU features, if you are already using it, please keep in update of the evalsoc support changes in each
  21. release, you can track it by diff each release changes, and please also remember Nuclei SDK release may
  22. also bump with NMSIS release.
  23. Assume your SoC name is ``ncstar``, based on Nuclei core :ref:`n300f <develop_buildsystem_var_core>`, and **RISCV_ARCH**
  24. is ``rv32imafc``, **RISCV_ABI** is ``ilp32f``, and you made a new board called ``ncstar_eval``,
  25. and this SoC only support **flashxip** :ref:`download <develop_buildsystem_var_download>` mode.
  26. Make sure the SoC name and Board name used in this Nuclei SDK is all in lowercase.
  27. 1. Create a folder named ``ncstar`` under **SoC** directory.
  28. * Create folder named ``Board`` and ``Common`` under ``ncstar``
  29. * Create directory structure under ``ncstar/Common`` like below:
  30. .. code-block:: text
  31. <ncstar/Common>
  32. ├── Include
  33. │   ├── peripheral_or_device_headers.h
  34. │   ├── ......
  35. │   ├── ncstar.h
  36. │   ├── nuclei_sdk_soc.h
  37. │   └── system_ncstar.h
  38. └── Source
  39. ├── Drivers
  40. │   ├── peripheral_or_device_sources.c
  41. │   └── ......
  42. ├── GCC
  43. │   ├── intexc_ncstar.S
  44. │   └── startup_ncstar.S
  45. ├── Stubs
  46. │   ├── newlib
  47. │   └── libncrt
  48. ├── ncstar_soc.c
  49. └── system_ncstar.c
  50. .. note::
  51. * The directory structure is based on the NMSIS device template, please refer
  52. to https://doc.nucleisys.com/nmsis/core/core_templates.html
  53. * The folder names must be exactly the same as the directory structure showed
  54. * **peripheral_or_device_sources.c** means the SoC peripheral driver source code files,
  55. such as uart, gpio, i2c, spi driver sources, usually get from the SoC firmware library,
  56. it should be placed in **Drivers** folder.
  57. * **peripheral_or_device_headers.h** means the SoC peripheral driver header files,
  58. such as uart, gpio, i2c, spi driver headers, usually get from the SoC firmware library,
  59. it should be placed in **Include** folder.
  60. * The **Stubs** folder contains the stub code files for newlib c library and nuclei c runtime
  61. library porting code, take ``SoC/evalsoc/Common/Stubs`` as reference.
  62. * The **GCC** folder contains *startup* and *exeception/interrupt* assemble code,
  63. if your board share the same linker script files, you can also put link script files here,
  64. the linker script files name rules can refer to previously supported *evalsoc* SoC.
  65. * If you want to do IAR compiler support, you also need to implement IAR related stuff,
  66. which is located in folder called IAR.
  67. * The **nuclei_sdk_soc.h** file is very important, it is a Nuclei SoC Header file used
  68. by common application which can run accoss different SoC, it should include the SoC device
  69. header file ``ncstar.h``
  70. * Create directory structure under ``ncstar/Board`` like below:
  71. .. code-block:: text
  72. <ncstar/Board>
  73. └── ncstar_eval
  74.    ├── Include
  75.    │   ├── ncstar_eval.h
  76.    │   └── nuclei_sdk_hal.h
  77.    ├── openocd_ncstar.cfg
  78.    └── Source
  79.    ├── GCC
  80.    │   └── gcc_ncstar_flashxip.ld
  81.    └── ncstar_eval.c
  82. .. note::
  83. * The **ncstar_eval** is the board folder name, if you have a new board,
  84. you can create a new folder in the same level
  85. * **Include** folder contains the board related header files
  86. * **Source** folder contains the board related source files
  87. * **GCC** folder is optional, if your linker script for the board is different
  88. to the SoC, you need to put your linker script here
  89. * **openocd_ncstar.cfg** file is the board related openocd debug configuration file
  90. * **ncstar_eval.h** file contains board related definition or APIs and also include
  91. the **SoC** header file, you can refer to previously supported board such as ``nuclei_fpga_eval``
  92. * **nuclei_sdk_hal.h** is very important, it includes the **ncstar_eval.h** header file.
  93. This file is used in application as entry header file to access board and SoC resources.
  94. 2. Create Makefile related to ``ncstar`` in :ref:`Nuclei SDK build system <develop_buildsystem>`
  95. * Create **SoC/ncstar/build.mk**, the file content should be like this:
  96. .. code-block:: Makefile
  97. ##### Put your SoC build configurations below #####
  98. BOARD ?= ncstar_eval
  99. # override DOWNLOAD and CORE variable for NCSTAR SoC
  100. # even though it was set with a command argument
  101. override CORE := n300f
  102. override DOWNLOAD := flashxip
  103. NUCLEI_SDK_SOC_BOARD := $(NUCLEI_SDK_SOC)/Board/$(BOARD)
  104. NUCLEI_SDK_SOC_COMMON := $(NUCLEI_SDK_SOC)/Common
  105. #no ilm on NCSTAR SoC
  106. LINKER_SCRIPT ?= $(NUCLEI_SDK_SOC_BOARD)/Source/GCC/gcc_ncstar_flashxip.ld
  107. OPENOCD_CFG ?= $(NUCLEI_SDK_SOC_BOARD)/openocd_ncstar.cfg
  108. RISCV_ARCH ?= rv32imafc
  109. RISCV_ABI ?= ilp32f
  110. ##### Put your Source code Management configurations below #####
  111. INCDIRS += $(NUCLEI_SDK_SOC_COMMON)/Include
  112. C_SRCDIRS += $(NUCLEI_SDK_SOC_COMMON)/Source \
  113. $(NUCLEI_SDK_SOC_COMMON)/Source/Drivers
  114. ifneq ($(findstring libncrt,$(STDCLIB)),)
  115. C_SRCDIRS += $(NUCLEI_SDK_SOC_COMMON)/Source/Stubs/libncrt
  116. else ifneq ($(findstring newlib,$(STDCLIB)),)
  117. C_SRCDIRS += $(NUCLEI_SDK_SOC_COMMON)/Source/Stubs/newlib
  118. else
  119. # no stubs will be used
  120. endif
  121. ASM_SRCS += $(NUCLEI_SDK_SOC_COMMON)/Source/GCC/startup_ncstar.S \
  122. $(NUCLEI_SDK_SOC_COMMON)/Source/GCC/intexc_ncstar.S
  123. # Add extra board related source files and header files
  124. VALID_NUCLEI_SDK_SOC_BOARD := $(wildcard $(NUCLEI_SDK_SOC_BOARD))
  125. ifneq ($(VALID_NUCLEI_SDK_SOC_BOARD),)
  126. INCDIRS += $(VALID_NUCLEI_SDK_SOC_BOARD)/Include
  127. C_SRCDIRS += $(VALID_NUCLEI_SDK_SOC_BOARD)/Source
  128. endif
  129. * If you need to place vector table in flash device, and copy it to ilm when startup, such as
  130. using ``DOWNLOAD=flash`` mode, then you need to define extra ``VECTOR_TABLE_REMAPPED`` macro
  131. in this ``build.mk``, just take ``SoC/evalsoc/build.mk`` as reference.
  132. .. code-block:: Makefile
  133. ## omit some code above
  134. # Add extra cflags for SoC related
  135. ifeq ($(DOWNLOAD), flash)
  136. COMMON_FLAGS += -DVECTOR_TABLE_REMAPPED
  137. endif
  138. ## omit some code below
  139. RISCV_ARCH ?= rv32imafc
  140. 3. If you have setup the source code and build system correctly, then you can test
  141. your SoC using the common applications, e.g.
  142. .. code-block:: shell
  143. # Test helloworld application for ncstar_eval board
  144. ## cd to helloworld application directory
  145. cd application/baremetal/helloworld
  146. ## clean and build helloworld application for ncstar_eval board
  147. make SOC=ncstar BOARD=ncstar_eval clean all
  148. ## connect your board to PC and install jtag driver, open UART terminal
  149. ## set baudrate to 115200bps and then upload the built application
  150. ## to the ncstar_eval board using openocd, and you can check the
  151. ## run messsage in UART terminal
  152. make SOC=ncstar BOARD=ncstar_eval upload
  153. .. note::
  154. * You can always refer to previously supported SoCs for reference,
  155. such as the ``evalsoc`` and ``gd32vf103`` SoC, we suggest you follow
  156. the ``evalsoc`` implementation, since it is well maintained to support
  157. latest nuclei riscv cpu feature.
  158. * The ``evalsoc`` SoC is a FPGA based evaluation platform, it have
  159. ``ilm`` and ``dlm``, so it support many
  160. :ref:`download modes <develop_buildsystem_var_download>`
  161. * The ``gd32vf103`` SoC is a real silicon chip, it only have RAM and onchip
  162. flash, it only support FlashXIP mode.
  163. * The **nuclei_sdk_soc.h** must be created in SoC include directory, it must
  164. include the device header file <device>.h and SoC firmware library header files.
  165. * The **nuclei_sdk_hal.h** must be created in Board include directory, it must
  166. include **nuclei_sdk_soc.h** and board related header files.
  167. .. _contribute_submit_issue:
  168. Submit your issue
  169. -----------------
  170. If you find any issue related to Nuclei SDK project,
  171. you can open an issue in https://github.com/Nuclei-Software/nuclei-sdk/issues
  172. .. _contribute_submit_pr:
  173. Submit your pull request
  174. ------------------------
  175. If you want to contribute your code to Nuclei SDK project,
  176. you can open an pull request in https://github.com/Nuclei-Software/nuclei-sdk/pulls
  177. Regarding to code style, please refer to :ref:`develop_codestyle`.
  178. .. _contribute_git_guide:
  179. Git commit guide
  180. ----------------
  181. If you want to contribute your code, make sure you follow the guidance
  182. of git commit, see here https://chris.beams.io/posts/git-commit/ for details
  183. * Use the present tense ("Add feature" not "Added feature")
  184. * Use the imperative mood ("Move cursor to..." not "Moves cursor to...")
  185. * Limit the first line to 80 characters or less
  186. * Refer github issues and pull requests liberally using ``#``
  187. * Write the commit message with an category name and colon:
  188. - soc: changes related to soc
  189. - board: changes related to board support packages
  190. - nmsis: changes related to NMSIS
  191. - build: changes releated to build system
  192. - library: changes related to libraries
  193. - rtos: changes related to rtoses
  194. - test: changes related to test cases
  195. - doc: changes related to documentation
  196. - ci: changes related to ci environment
  197. - application: changes related to applications
  198. - misc: changes not categorized
  199. - env: changes related to environment
  200. .. _Quick Porting to you SoC based on Evalsoc in Nuclei SDK: https://doc.nucleisys.com/nuclei_studio_supply/28-quick_porting_from_evalsoc_to_customsoc_based_on_Nuclei_SDK/