Application Development
Overview
Here will describe how to develop an Nuclei SDK application.
To develop a Nuclei SDK application from scratch, you can do the following steps:
Create a directory to place your application code.
Create Makefile in the new created directory, the minimal Makefile should look like this
1 TARGET = your_target_name 2 3 NUCLEI_SDK_ROOT = path/to/your_nuclei_sdk_root 4 5 SRCDIRS = . 6 7 INCDIRS = . 8 9 include $(NUCLEI_SDK_ROOT)/Build/Makefile.base
Copy or create your application code in new created directory.
Note
If you just want to SoC related resource, you can include header file
nuclei_sdk_soc.hin your application code.If you just want to SoC and Board related resource, you can include header file
nuclei_sdk_hal.hin your application code.For simplity, we recomment you to use
nuclei_sdk_hal.hheader file
Follow Build System based on Makefile to change your application Makefile.
Note
Starting from version 0.9.0, you can use APPDIRS to apply compilation flags specifically to your application source code.
Add Extra Source Code
If you want to add extra source code, you can use these makefile variables:
- To add all the source code in directories, recursive search is not supported.
SRCDIRS: Add C/CPP/ASM source code located in the directories defined by this variable.
C_SRCDIRS: Add C only source code located in the directories defined by this variable.
CXX_SRCDIRS: Add CPP only source code located in the directories defined by this variable.
ASM_SRCDIRS: Add ASM only source code located in the directories defined by this variable.
- To add only selected c/cxx/asm source files
- To exclude some source files
EXCLUDE_SRCS: Exclude source files defined by this variable.
Add Extra Include Directory
If you want to add extra include directories, you can use these makefile variables:
INCDIRS: Include the directories defined by this variable for C/ASM/CPP code during compiling.
C_INCDIRS: Include the directories defined by this variable for C only code during compiling.
CXX_INCDIRS: Include the directories defined by this variable for CPP only code during compiling.
ASM_INCDIRS: Include the directories defined by this variable for ASM only code during compiling.
Add Extra Build Options
If you want to add extra build options, you can use these makefile variables:
COMMON_FLAGS: This will add compiling flags for C/CPP/ASM source code.
CFLAGS: This will add compiling flags for C source code.
CXXFLAGS: This will add compiling flags for CPP source code.
ASMFLAGS: This will add compiling flags for ASM source code.
LDFLAGS: This will add linker flags when linking.
LDLIBS: This will add extra libraries need to be linked.
LIBDIRS: This will add extra library directories to be searched by linker.
Optimize For Code Size
If you want to optimize your application for code size, you set COMMON_FLAGS
in your application Makefile like this:
COMMON_FLAGS := -Os
If you want to optimize code size even more, you use this link time optimization(LTO) as below:
COMMON_FLAGS := -Os -flto
see demo_eclic for example usage of optimize for code size.
For more details about gcc optimization, please refer to Options That Control Optimization in GCC.
Change Link Script
If you want to change the default link script defined by your make configuration(SOC, BOARD, DOWNLOAD). You can use LINKER_SCRIPT variable to set your linker script.
The default linker script used for different boards can be found in Board.
Set Default Make Options
Set Default Global Make Options For Nuclei SDK
If you want to change the global Make options for the Nuclei SDK, you can add the Makefile.global.
Set Local Make Options For Your Application
If you want to change the application level Make options, you can add the Makefile.local.
Application-Specific Compilation Flags with APPDIRS
Starting from Nuclei SDK version 0.9.0, you can use the APPDIRS variable to apply compilation flags specifically to your application source code, without affecting the SDK library code. This is particularly useful for features like profiling, code coverage, or other application-specific optimizations.
The APPDIRS variable allows you to specify directories that need application-specific compilation flags. It can support multiple directories separated by space, e.g. APPDIRS = . src.
If APPDIRS is not defined or empty, the APP_XXXFLAGS and APP_COMMON_FLAGS will be added to global flags and applied to all source files in the project.
If APPDIRS is defined, the APP_XXXFLAGS and APP_COMMON_FLAGS will be applied only to source code located in the directories specified by APPDIRS.
The following flags can be used with APPDIRS:
APP_COMMON_FLAGS: Common flags for C/C++/ASM compilation
APP_CFLAGS: Flags specific to C compilation
APP_CXXFLAGS: Flags specific to C++ compilation
APP_ASMFLAGS: Flags specific to ASM compilation
For example, if you want to append specific profiling or coverage flags only to your application source code while keeping the SDK source code compiled with default flags, you can set APPDIRS to point to your application source directories.
A practical example of this feature can be found in the application/baremetal/demo_profiling application, which uses APPDIRS to enable profiling instrumentation only for the application code:
# Application-specific compilation options that can be used for
# profiling, coverage, and other app-specific settings
# -pg enables profiling instrumentation
APP_COMMON_FLAGS := -pg
# App-specific C compilation flags
APP_CFLAGS :=
# App-specific C++ compilation flags
APP_CXXFLAGS :=
# App-specific Assembly compilation flags
APP_ASMFLAGS :=
# Specify directories that need app-specific compilation flags
# If left empty, APP_XXXFLAGS will be applied to all source files
APPDIRS := . src
This approach allows for fine-grained control of compilation flags for specific parts of an application while maintaining clean separation from SDK source code.