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

Command line Make example project for nRF52 DK

I'm trying to build the "blinky" example found in nRF5_SDK_15.3.0_59ac345/examples/peripheral/blinky/pca10040e/blank/armgcc

Actually the pca10040e directory contains 'blank' and 'mbr' directories, I just went with blank but I've no idea what the difference is and which I should be using. I went with 'blank' and tried a 'make' command. Everything compiled but the linker is missing a library. I've installed both the  nRF5_SDK_15.3.0 and s132 packages but searching my machine and there's no occurrences of either libc_nano* or libg_nano. I'm not sure if those libs are target, as in Nordic nRF52 specific or arm specific, in which case they should have been installed with my arm-none-eabi-gcc packages?

/usr/lib64/gcc/arm-none-eabi/7/ld: cannot find -lc_nano
/usr/lib64/gcc/arm-none-eabi/7/ld: cannot find -lg_nano
/usr/lib64/gcc/arm-none-eabi/7/ld: cannot find -lc_nano

So should I be making in 'blank' or 'mbr' and where should I install libs from?

Parents Reply Children
  • Oops, I already have the gcc toolchain for arm installed from the package manager on my linux distro. I'll use the one distributed with the SDK and try that.

    Thanks for your help

  • So I managed to build the blinky project from the command line. And flash it to the target dev board by copying the hex file to the mounted drive. I'll have to come back to that as if I designed by own board that's not how this would work. I have a JLink so I'd have to connect to the JTAG header and user a command line program to flash.

    I'll come back to that but for the moment if I wanted to create a template C project I've now got this script to pull necessary files from the blinky project. My question is that if I wanted instead to create an empty C++ project, what is required. I've tried changing the Makefile.common to specify -std=c++17 instead of -std=c99, and changing to $(CXX) but there's more to it then that as you need the standard library.

    #!/bin/bash
    
    SDK_ROOT=/home/john/Install/Nordic/nRF5SDK/nRF5_SDK_15.3.0_59ac345
    
    if [ $# -ne 1 ]; then
        echo "usage: $0 <target>"
        exit 1
    fi
    
    target=$1
    	
    if [ -f $target ]; then
        echo "Error - Target file exists"
        exit 2
    fi
    
    if [ -d $target ]; then
        echo "Error - Target directory exists"
        exit 2
    fi
    
    #
    # Create the target directory
    #
    mkdir -p $target/src
    
    #
    # Copy in Blinkey Makefile and Makefile.common
    #
    cp $SDK_ROOT/examples/peripheral/blinky/pca10040e/blank/armgcc/Makefile $target
    cp $SDK_ROOT/components/toolchain/gcc/Makefile.common $target
    
    sed -e "s/blinky_pca10040e/$target/" \
        -e "s;SDK_ROOT := ../../../../../..;SDK_ROOT := $SDK_ROOT;" \
        -e "s;PROJ_DIR := ../../..;PROJ_DIR := .;" \
        -e "s/blinky_gcc_nrf52.ld/gcc_nrf52.ld/" \
        -e 's;(PROJ_DIR);(PROJ_DIR)/src;' \
        -e 's;SDK_CONFIG_FILE := ../config/sdk_config.h;SDK_CONFIG_FILE := sdk_config.h;' \
        -e 's;$(TEMPLATE_PATH)/;;' \
        -e '/..\/config/d' \
        $target/Makefile > $target/Makefile.tmp
    
    rm $target/Makefile
    mv $target/Makefile.tmp $target/Makefile
     
    #
    # Copy in the linker script from blinkey project
    #
    cp $SDK_ROOT/examples/peripheral/blinky/pca10040e/blank/armgcc/blinky_gcc_nrf52.ld $target/gcc_nrf52.ld
    
    #
    # Populate the src directory with the config header file and a main
    cp $SDK_ROOT/examples/peripheral/blinky/pca10040e/blank/config/sdk_config.h $target/src
    
    echo "int main(int argc, char **argv){}" > $target/src/main.c
    

  • Our SDK has limited support for C++, unfortunately. I don't have experience with it myself but seen from other forum threads that macros, etc need to be ported in order to be C++ compliant. That said, you can specify the C++ compiler flags by using the CXXFLAGS variable in your project Makefile. It should not be necessary to modify Makefile.common. 

  • I'm not sure about some of your points. The Makefile already sets up the CXXFLAGS variable, it's obviously not used, or possibly not used but it's certainly set up in the Makefile. Makefile.common specifies the toolchain, or possibly just the location of the toolchain, so possibly I don't have to mess with it. I hope that's right.

    As for the SDK supporting C++, the SDK will contain a lot of C Libraries, but that should not be an issue as C++ code can call C functions. Then the gcc toolchain already has very good support for C++ so that's not an issue. I'd imagine that as the heart of the nRF52 is an ARM ISA CPU that there's a good percentage of the STL supported, possibly much of it of little use in an embedded target but I'd say it's there.

    So all the bits are there I just have to figure out how to plug them all in together.

    If by SDK Support of C++ you mean the IDE I don't really have much interest in the IDE.

Related