4. New Project Guide based on cmake framework

This document will introduce how to create a new project based on this SDK.

4.1. Examples directory structure

There are two levels of subdirectories under bl_mcu_sdk/examples, the first level is the folders of different peripherals. The second level is a specific test case of the peripheral, and the directory usually contains a CMakeList.txt and the source code related to the case.

4.2. Add a single source file project

备注

The source file must contain the c program entry, usually the main function, the source file may not be called main.c

  • Create a new my_case folder under examples to store your case

  • Create a new folder that needs to be tested in the my_case directory, such as gpio_case

  • Then add the main.c and CMakeLists.txt files in the gpio_case directory

The directory structure is as follows:

1bl_mcu_sdk
2├── examples
3    ├── my_case
4        ├── gpio_case
5        │   ├──CMakeLists.txt
6        │   └──main.c
7        └── xxxx_case

CMakeLists.txt:

1set(mains main.c)
2generate_bin()
  • After writing the code in main.c, compile it in the bl_mcu_sdk directory. The compilation command is as follows:

1make BOARD=bl706_iot APP=gpio_case

4.3. Add multiple source file projects

备注

One of the source files must contain the c program entry, usually the main function, the source file does not need to be called main.c. This source file depends on other source files.

  • The steps for adding a multi-source file project are the same as the basic steps for adding a single source file project

  • Add test1.c, test1.h, test2.c, test2.h and other source files and header files that need to be relied on in the gpio_case directory

The directory structure is as follows:

 1bl_mcu_sdk
 2├── examples
 3    ├── my_case
 4        ├── gpio_case
 5        │   ├──CMakeLists.txt
 6        │   ├──test1.c
 7        │   ├──test1.h
 8        │   ├──test2.c
 9        │   ├──test2.h
10        │   └──main.c
11        └── xxxx_case
  • At this time, the CMakeLists.txt file needs to add the corresponding dependent source file, the content is as follows:

CMakeLists.txt:

1set(mains main.c)
2set(TARGET_REQUIRED_SRCS test1.c test2.c)
3generate_bin()
  • After writing the code, compile it in the bl_mcu_sdk directory. The compilation command is as follows:

1make BOARD=bl706_iot APP=gpio_case

4.4. Add a new project with dependent libraries

  • The steps for adding a new project with dependent libraries are the same as the basic steps for adding a single source file project

  • If the dependent library used already exists in this SDK, you only need to modify CMakeLists.txt

    • If the dependent library does not exist, you need to add it yourself, please refer to the follow-up instructions for details

If it already exists, the directory structure is as follows:

1bl_mcu_sdk
2├── examples
3    ├── my_case
4        ├── gpio_case
5        │   ├──CMakeLists.txt
6        │   └──main.c
7        └── xxxx_case
  • At this time, the CMakeLists.txt file needs to add the corresponding dependent library files. For example, we add the FreeRTOS component library, the content is as follows:

CMakeLists.txt:

1set(TARGET_REQUIRED_LIBS freertos)
2set(mains main.c)
3generate_bin()
  • After writing the code, compile it in the bl_mcu_sdk directory. The compilation command is as follows:

1make BOARD=bl706_iot APP=gpio_case  SUPPORT_FREERTOS=y

4.5. Add a new project and set the private compilation option (gcc option)

  • The steps of adding a new project are basically the same as adding a single source file project

  • Mainly modify the CMakeLists.txt file and add private compilation options

CMakeLists.txt:

1set(mains main.c)
2set(TARGET_REQUIRED_PRIVATE_OPTIONS -Ofast)
3generate_bin()
  • After writing the code, compile it in the bl_mcu_sdk directory. The compilation command is as follows:

1make BOARD=bl706_iot APP=gpio_case

4.7. Add a new project and its dependent source files and library files