This is a CMake project to program a nRF52832 board using CMake 3.16.0, JLink, NRFJProgrammer and NRF5 SDK 16.0. The CMake files are taken from: https://github.com/Polidea/cmake-nRF5x and https://github.com/JF002/nrf52-baseproject for reference.
-
Download:
- gcc arm none eabi toolchain x86-64-linux: https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads
- SDK for the nRF52 16.0: https://www.nordicsemi.com/Software-and-tools/Software/nRF5-SDK/Download#infotabs
- Programmer NRFJPROG: https://www.nordicsemi.com/Software-and-tools/Development-Tools/nRF-Command-Line-Tools/Download#infotabs
- JLink: https://www.segger.com/downloads/jlink/#J-LinkSoftwareAndDocumentationPack
-
Create a folder in /opt to unzip files, e.g. /opt/SEGGER/
-
Change lines 19,20,21 and 22 in the CMakeLists.txt file at the root project with the path for each one (toolchain,SDK and Programmer) and save it. e.g.
set(NRF_TARGET "nrf52") # nrf51 or nrf52 set(ARM_NONE_EABI_TOOLCHAIN_PATH "/opt/SEGGER/gcc-arm-none-eabi-9-2019-q4-major") # Path to root folder set(NRF5_SDK_PATH "/opt/SEGGER/nRF5SDK" ) # Path to root folder set(NRFJPROG "/opt/SEGGER/Toolchain/nrfjprog/nrfjprog") # Path to .bin file
-
Create a build folder and,
$ cd build/ $ cmake ../
If everything is good, you should see something like this, e.g.
-- The C compiler identification is GNU 5.4.0 -- The CXX compiler identification is GNU 5.4.0 -- The ASM compiler identification is GNU -- Found assembler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done -- Generating done -- Build files have been written to: /home/xXx/Downloads/nRF5-cmake-framework-master/build
-
Compile with make: (this will compile the source code "main.c" and flash the softdevice.hex and bin.hex to the board)
$ make
e.g.
[ 91%] Linking C executable application-example.out post build steps for application-example text data bss dec hex filename 8800 172 884 9856 2680 application-example.out [ 91%] Built target application-example Scanning dependencies of target FLASH_application-example [ 93%] flashing application-example.hex Parsing hex file. Erasing page at address 0x0. Erasing page at address 0x1000. Erasing page at address 0x2000. Applying system reset. Checking that the area to write is not protected. Programming device. Applying system reset. Run. [ 93%] Built target FLASH_application-example Scanning dependencies of target FLASH_SOFTDEVICE [ 95%] flashing SoftDevice Parsing hex file. Erasing page at address 0x0. Erasing page at address 0x1000. . . . Erasing page at address 0x24000. Erasing page at address 0x25000. Applying system reset. Checking that the area to write is not protected. Programming device. Applying system reset. Run. [ 95%] Built target FLASH_SOFTDEVICE Scanning dependencies of target FLASH_ERASE [ 97%] erasing flashing Erasing user available code and UICR flash areas. Applying system reset. [ 97%] Built target FLASH_ERASE Scanning dependencies of target START_JLINK [100%] started JLink commands [100%] Built target START_JLINK
At the root folder run,
$ ./monitor
This assume that the JLink binaries are on /opt/SEGGER/JLink/ if not, you should modify the runJLinkEXE-nrf52 on the RTT folder.
Set these variables in your own code
NRF_LOG_INIT((void*)0);
NRF_LOG_DEFAULT_BACKENDS_INIT();
NRF_LOG_PROCESS();
NRF_LOG_INFO("TEXT TO PRINT\n");
NRF_LOG_FLUSH();
and set these definitions on sdk_config.h
NRF_LOG_BACKEND_RTT_ENABLED 1
NRF_FPRINTF_ENABLED 1
NRF_FPRINTF_DOUBLE_ENABLED 1
NRF_LOG_ENABLED 1
NRF_LOG_BACKEND_UART_BAUDRATE 115200
You have to comment-uncomment these lines in order to include a SDK library in the CMakeLists.txt file.
nRF5x_setup()
# nRF5x_addAppScheduler()
# nRF5x_addAppFIFO()
nRF5x_addAppTimer()
# nRF5x_addAppUART()
nRF5x_addAppButton()
nRF5x_addBSP(TRUE FALSE FALSE) # (btn atn_btn nfc)
nRF5x_addBLEGATT()
# nRF5x_addBLEService(ble_bas)
# nRF5x_addNFC()
nRF5x_addAppFDS()
nRF5x_addBLEPeerManager()
# nRF5x_addBLEAdvertising()
# nRF5x_addAppFIFO()
or,
include_directories(
"${NRF5_SDK_PATH}/<library header directory path>"
)
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/<library source file path>"
)
BLE SERVICES:
- ble_ancs_c
- ble_ans_c
- ble_bas
- ble_bas_c
- ble_bps
- ble_cscs
...
Just modify the main.c file with your own code. In case you need specify more SDK libraries you have to modify the nrF5x.cmake file on the cmake folder.