appdev.rst 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. .. _develop_appdev:
  2. Application Development
  3. =======================
  4. .. _develop_appdev_overview:
  5. Overview
  6. --------
  7. Here will describe how to develop an Nuclei SDK application.
  8. To develop a Nuclei SDK application from scratch, you can do the following steps:
  9. 1. Create a directory to place your application code.
  10. 2. Create **Makefile** in the new created directory, the minimal **Makefile** should look like this
  11. .. code-block:: makefile
  12. :linenos:
  13. TARGET = your_target_name
  14. NUCLEI_SDK_ROOT = path/to/your_nuclei_sdk_root
  15. SRCDIRS = .
  16. INCDIRS = .
  17. include $(NUCLEI_SDK_ROOT)/Build/Makefile.base
  18. 3. Copy or create your application code in new created directory.
  19. .. note::
  20. * If you just want to SoC related resource, you can include header file ``nuclei_sdk_soc.h`` in your application code.
  21. * If you just want to SoC and Board related resource, you can include header file ``nuclei_sdk_hal.h`` in your application code.
  22. * For simplity, we recomment you to use ``nuclei_sdk_hal.h`` header file
  23. 4. Follow :ref:`develop_buildsystem` to change your application Makefile.
  24. .. _develop_appdev_addsrc:
  25. Add Extra Source Code
  26. ---------------------
  27. If you want to add extra source code, you can use these makefile variables:
  28. To add all the source code in directories, recursive search is not supported.
  29. * :ref:`develop_buildsystem_var_srcdirs`: Add C/CPP/ASM source code located
  30. in the directories defined by this variable.
  31. * :ref:`develop_buildsystem_var_c_srcdirs`: Add C only source code located
  32. in the directories defined by this variable.
  33. * :ref:`develop_buildsystem_var_cxx_srcdirs`: Add CPP only source code located
  34. in the directories defined by this variable.
  35. * :ref:`develop_buildsystem_var_asm_srcdirs`: Add ASM only source code located
  36. in the directories defined by this variable.
  37. To add only selected c/cxx/asm source files
  38. * :ref:`develop_buildsystem_var_c_srcs`: Add C only source code files defined by this variable.
  39. * :ref:`develop_buildsystem_var_cxx_srcs`: Add CPP only source code files defined by this variable.
  40. * :ref:`develop_buildsystem_var_asm_srcs`: Add ASM only source code files defined by this variable.
  41. To exclude some source files
  42. * :ref:`develop_buildsystem_var_exclude_srcs`: Exclude source files defined by this variable.
  43. .. _develop_appdev_addinc:
  44. Add Extra Include Directory
  45. ---------------------------
  46. If you want to add extra include directories, you can use these makefile variables:
  47. * :ref:`develop_buildsystem_var_incdirs`: Include the directories defined by
  48. this variable for C/ASM/CPP code during compiling.
  49. * :ref:`develop_buildsystem_var_c_incdirs`: Include the directories defined by
  50. this variable for C only code during compiling.
  51. * :ref:`develop_buildsystem_var_cxx_incdirs`: Include the directories defined by
  52. this variable for CPP only code during compiling.
  53. * :ref:`develop_buildsystem_var_asm_incdirs`: Include the directories defined by
  54. this variable for ASM only code during compiling.
  55. .. _develop_appdev_addoptions:
  56. Add Extra Build Options
  57. -----------------------
  58. If you want to add extra build options, you can use these makefile variables:
  59. * :ref:`develop_buildsystem_var_common_flags`: This will add compiling flags
  60. for C/CPP/ASM source code.
  61. * :ref:`develop_buildsystem_var_cflags`: This will add compiling flags
  62. for C source code.
  63. * :ref:`develop_buildsystem_var_cxxflags`: This will add compiling flags
  64. for CPP source code.
  65. * :ref:`develop_buildsystem_var_asmflags`: This will add compiling flags
  66. for ASM source code.
  67. * :ref:`develop_buildsystem_var_ldflags`: This will add linker flags when linking.
  68. * :ref:`develop_buildsystem_var_ldlibs`: This will add extra libraries need to be linked.
  69. * :ref:`develop_buildsystem_var_libdirs`: This will add extra library directories to be searched by linker.
  70. .. _develop_appdev_optimize_for_codesize:
  71. Optimize For Code Size
  72. ----------------------
  73. If you want to optimize your application for code size, you set ``COMMON_FLAGS``
  74. in your application Makefile like this:
  75. .. code-block:: makefile
  76. COMMON_FLAGS := -Os
  77. If you want to optimize code size even more, you use this link time optimization(LTO) as below:
  78. .. code-block:: makefile
  79. COMMON_FLAGS := -Os -flto
  80. see :ref:`design_app_demo_eclic` for example usage of optimize for code size.
  81. For more details about gcc optimization, please refer to `Options That Control Optimization in GCC`_.
  82. .. _develop_appdev_linkscript:
  83. Change Link Script
  84. ------------------
  85. If you want to change the default link script defined by your make configuration(SOC, BOARD, DOWNLOAD).
  86. You can use :ref:`develop_buildsystem_var_linker_script` variable to set your linker script.
  87. The default linker script used for different boards can be found in :ref:`design_board`.
  88. .. _develop_appdev_setdefaultmake:
  89. Set Default Make Options
  90. ------------------------
  91. Set Default Global Make Options For Nuclei SDK
  92. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  93. If you want to change the global Make options for the Nuclei SDK,
  94. you can add the :ref:`develop_buildsystem_makefile_global`.
  95. Set Local Make Options For Your Application
  96. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  97. If you want to change the application level Make options,
  98. you can add the :ref:`develop_buildsystem_makefile_local`.
  99. .. _Options That Control Optimization in GCC: https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Optimize-Options.html#Optimize-Options