contribute.rst 10 KB

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