This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Way to Exclude softdevice and compile, NRF SDK16 example project

The goal is to be able to automate build using CMake. I am evaluating this by trying to build example project in nrfSDK 16.(I chose saadc example from nRF5_SDK\examples\peripheral\saadc)

The CMakeLists file and supporting scripts were taken from this and modified.

I am able to CMake to generate build files. Next, When I invoke make, I get the error 

/home/bharath/Nordic_Semi/components/libraries/log/src/nrf_log_backend_rtt.c:40:
/home/bharath/Nordic_Semi/components/libraries/util/app_util.h:133:10: fatal error: nrf_mbr.h: No such file or directory
 #include "nrf_mbr.h"

I found that file "nrf_mbr.h" is a part of softdevice. Is there a way to exclude softdevice and compile this?

Also, I am successfully able to compile the saadc example using armgcc Makefile at  nRF5_SDK\examples\peripheral\saadc\pca10056\blank\armgcc\. This file does not include any softdevice and still is able to generate hex files. I am looking for a solution similar to this.

Any help is appreciated. Thanks!

  • Surely, what that error tells you is that you haven't set your include paths correctly ?

    Is there a way to exclude softdevice and compile this

    This doesn't make sense.

    The SoftDevice is never part of the build: it is supplied as a pre-built binary - there is nothing to compile!

  • Hi,

    Is there a way to exclude softdevice and compile this

     As Andrew's said, you could not compile the softdevice, but you can the pre-built binary. 

     

    Also, I am successfully able to compile the saadc example using armgcc Makefile at  nRF5_SDK\examples\peripheral\saadc\pca10056\blank\armgcc\. This file does not include any softdevice and still is able to generate hex files. I am looking for a solution similar to this.

     You could use the examples under nRF5_SDK_16.0.0_98a08e2\examples\peripheral\PCA#\blank. They don't use the softdevice. 

    -Amanda H.

  • Hi and , Thanks for your replies.

    Issue was that, CMake script had the -DSOFTDEVICE_PRESENT compile definition flag. Once I got rid of this flag, I could proceed with build and it did not required headers from the softdevice library.

    Using the CMake script below, I was able to generate binaries and hex.

    cmake_minimum_required(VERSION 3.6)
    
    # check if all the necessary tools paths have been provided.
    if (NOT NRF5_SDK_PATH)
        message(FATAL_ERROR "The path to the nRF5 SDK (NRF5_SDK_PATH) must be set.")
    endif ()
    
    #if (NOT NRFJPROG)
    #    message(FATAL_ERROR "The path to the nrfjprog utility (NRFJPROG) must be set.")
    #endif ()
    
    # convert toolchain path to bin path
    if(DEFINED ARM_NONE_EABI_TOOLCHAIN_PATH)
        set(ARM_NONE_EABI_TOOLCHAIN_BIN_PATH ${ARM_NONE_EABI_TOOLCHAIN_PATH}/bin)
    endif()
    
    # check if the nRF target has been set
    if (NRF_TARGET MATCHES "nrf51")
    
    elseif (NRF_TARGET MATCHES "nrf52")
    
    elseif (NOT NRF_TARGET)
        message(FATAL_ERROR "nRF target must be defined")
    else ()
        message(FATAL_ERROR "Only nRF51 and rRF52 boards are supported right now")
    endif ()
    
    # must be set in file (not macro) scope (in macro would point to parent CMake directory)
    set(DIR_OF_nRF5x_CMAKE ${CMAKE_CURRENT_LIST_DIR})
    
    macro(nRF5x_toolchainSetup)
        include(${DIR_OF_nRF5x_CMAKE}/arm-gcc-toolchain.cmake)
    endmacro()
    
    macro(nRF5x_setup)
        if(NOT DEFINED ARM_GCC_TOOLCHAIN)
            message(FATAL_ERROR "The toolchain must be set up before calling this macro")
        endif()
        # language standard/version settings
        set(CMAKE_C_STANDARD 99)
        set(CMAKE_CXX_STANDARD 98)
    
            if(NOT DEFINED NRF5_LINKER_SCRIPT)
                set(NRF5_LINKER_SCRIPT "${CMAKE_SOURCE_DIR}/gcc_nrf52.ld")
            endif()
            set(CPU_FLAGS "-mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16")
            add_definitions(-DCONFIG_GPIO_AS_PINRESET -DFLOAT_ABI_HARD -DNRF52840_XXAA -DBOARD_PCA10056 -DBSP_DEFINES_ONLY) 
    
        set(COMMON_FLAGS " -MP -MD -mthumb -mabi=aapcs -Wall -g3 -ffunction-sections -fdata-sections -fno-strict-aliasing -fno-builtin --short-enums ${CPU_FLAGS}")
    
        # compiler/assambler/linker flags
        set(CMAKE_C_FLAGS "${COMMON_FLAGS}")
        set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O1")
        set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
        set(CMAKE_CXX_FLAGS "${COMMON_FLAGS}")
        set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O1")
        set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
        set(CMAKE_ASM_FLAGS "-MP -MD -std=c99 -x assembler-with-cpp")
        
    
    
        set(CMAKE_EXE_LINKER_FLAGS "-mthumb -mabi=aapcs -std=gnu++98 -std=c99 -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT} ${CPU_FLAGS} -Wl,--gc-sections --specs=nano.specs -lc -lnosys -lm")
    
        # note: we must override the default cmake linker flags so that CMAKE_C_FLAGS are not added implicitly
        set(CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_COMPILER} <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
        set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_C_COMPILER} <LINK_FLAGS> <OBJECTS> -lstdc++ -o <TARGET> <LINK_LIBRARIES>")
    
        # basic board definitions and drivers
        include_directories(
                "${NRF5_SDK_PATH}/components"
                "${NRF5_SDK_PATH}/modules/nrfx/mdk"
                "${NRF5_SDK_PATH}/components/libraries/pwr_mgmt"
                "${NRF5_SDK_PATH}/components/libraries/strerror"
                "${NRF5_SDK_PATH}/components/toolchain/cmsis/include"
                "${NRF5_SDK_PATH}/components/libraries/util"
                "${NRF5_SDK_PATH}/components/libraries/balloc"
                "${NRF5_SDK_PATH}/components/libraries/ringbuf"
                "${NRF5_SDK_PATH}/modules/nrfx/hal"
                "${NRF5_SDK_PATH}/components/libraries/bsp"
                "${NRF5_SDK_PATH}/components/libraries/log"
                "${NRF5_SDK_PATH}/modules/nrfx"
                "${NRF5_SDK_PATH}/components/libraries/experimental_section_vars"
                "${NRF5_SDK_PATH}/integration/nrfx/legacy"
                "${NRF5_SDK_PATH}/components/libraries/mutex"
                "${NRF5_SDK_PATH}/components/libraries/delay"
                "${NRF5_SDK_PATH}/integration/nrfx"
                "${NRF5_SDK_PATH}/components/drivers_nrf/nrf_soc_nosd"
                "${NRF5_SDK_PATH}/external/segger_rtt"
                "${NRF5_SDK_PATH}/components/boards"
                "${NRF5_SDK_PATH}/components/libraries/memobj"
                "${NRF5_SDK_PATH}/modules/nrfx/drivers/include"
                "${NRF5_SDK_PATH}/components/libraries/log/src"
                "${NRF5_SDK_PATH}/external/fprintf"
                "${NRF5_SDK_PATH}/components/libraries/atomic"
        )
    
        list(APPEND SDK_SOURCE_FILES
                "${NRF5_SDK_PATH}/modules/nrfx/mdk/gcc_startup_nrf52.S"
                "${NRF5_SDK_PATH}/components/libraries/log/src/nrf_log_backend_rtt.c"
                "${NRF5_SDK_PATH}/components/libraries/log/src/nrf_log_backend_serial.c"
                "${NRF5_SDK_PATH}/components/libraries/log/src/nrf_log_backend_uart.c"
                "${NRF5_SDK_PATH}/components/libraries/log/src/nrf_log_default_backends.c"
                "${NRF5_SDK_PATH}/components/libraries/log/src/nrf_log_frontend.c"
                "${NRF5_SDK_PATH}/components/libraries/log/src/nrf_log_str_formatter.c"
                "${NRF5_SDK_PATH}/components/boards/boards.c"
                "${NRF5_SDK_PATH}/components/libraries/util/app_error.c"
                "${NRF5_SDK_PATH}/components/libraries/util/app_error_handler_gcc.c"
                "${NRF5_SDK_PATH}/components/libraries/util/app_error_weak.c"
                "${NRF5_SDK_PATH}/components/libraries/util/app_util_platform.c"
                "${NRF5_SDK_PATH}/components/libraries/util/nrf_assert.c"
                "${NRF5_SDK_PATH}/components/libraries/atomic/nrf_atomic.c"
                "${NRF5_SDK_PATH}/components/libraries/balloc/nrf_balloc.c"
                "${NRF5_SDK_PATH}/external/fprintf/nrf_fprintf.c"
                "${NRF5_SDK_PATH}/external/fprintf/nrf_fprintf_format.c"
                "${NRF5_SDK_PATH}/components/libraries/memobj/nrf_memobj.c"
                "${NRF5_SDK_PATH}/components/libraries/pwr_mgmt/nrf_pwr_mgmt.c"
                "${NRF5_SDK_PATH}/components/libraries/ringbuf/nrf_ringbuf.c"
                "${NRF5_SDK_PATH}/components/libraries/experimental_section_vars/nrf_section_iter.c"
                "${NRF5_SDK_PATH}/components/libraries/strerror/nrf_strerror.c"
                "${NRF5_SDK_PATH}/integration/nrfx/legacy/nrf_drv_ppi.c"
                "${NRF5_SDK_PATH}/integration/nrfx/legacy/nrf_drv_uart.c"
                "${NRF5_SDK_PATH}/modules/nrfx/soc/nrfx_atomic.c"
                "${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_ppi.c"
                "${NRF5_SDK_PATH}/modules/nrfx/drivers/src/prs/nrfx_prs.c"
                "${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_saadc.c"
                "${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_timer.c"
                "${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_uart.c"
                "${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_uarte.c"
                "${NRF5_SDK_PATH}/external/segger_rtt/SEGGER_RTT.c"
                "${NRF5_SDK_PATH}/external/segger_rtt/SEGGER_RTT_Syscalls_GCC.c"
                "${NRF5_SDK_PATH}/external/segger_rtt/SEGGER_RTT_printf.c"
                "${NRF5_SDK_PATH}/modules/nrfx/mdk/system_nrf52840.c"
                )
    endmacro(nRF5x_setup)
    
    # adds a target for comiling and flashing an executable
    macro(nRF5x_addExecutable EXECUTABLE_NAME SOURCE_FILES)
        # executable
        add_executable(${EXECUTABLE_NAME} ${SDK_SOURCE_FILES} ${SOURCE_FILES})
        set_target_properties(${EXECUTABLE_NAME} PROPERTIES SUFFIX ".out")
        #set_target_properties(${EXECUTABLE_NAME} PROPERTIES LINK_FLAGS "-lc -lnosys -lm")
    
        # additional POST BUILD setps to create the .bin and .hex files
        add_custom_command(TARGET ${EXECUTABLE_NAME}
                POST_BUILD
                COMMAND ${CMAKE_SIZE_UTIL} ${EXECUTABLE_NAME}.out
                COMMAND ${CMAKE_OBJCOPY} -O binary ${EXECUTABLE_NAME}.out "${EXECUTABLE_NAME}.bin"
                COMMAND ${CMAKE_OBJCOPY} -O ihex ${EXECUTABLE_NAME}.out "${EXECUTABLE_NAME}.hex"
                COMMENT "post build steps for ${EXECUTABLE_NAME}")
    endmacro()
    
    

    This script, tries to mimic the Makefile for the Saadc project as much as possible.

    , now that i have and example built with cmake, I will proceed with cmake for my project with NRF. 

    Again, Thanks both.

Related