This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ST-LINK nrf51822 and QT Creator

Hello! I'm trying to build a program for nrf51822 via QT Creator. I'm using QBS for build. I have a makefile from SDK examples for nrf51822. Someone can help me, how to setup qbs-project to build (and debug) nrf51822 program? Thanks.

  • Hi,

    I use QT creator under Linux and Mac for nRF51822 software development. Below an example qbs file using the heartrate example. I you have other questions just ask.

    import qbs
    import qbs.FileInfo
    
    Product {
    Depends { name:"cpp" }
    
    type: ["application", "hex", "bin", "size"]
    name: "example"
    
    property string sdk: "../nrf51-sdk/"
    property string vendor: "Nordic"
    property string softDevice: "s110"
    property string device: "nrf51822"
    property string deviceVariant: "xxac" // xxaa=256kB Flash,16kB RAM | xxab=128kB Flash,16kB RAM | xxac=256kB Flash,32kB RAM
    
    cpp.defines: [
    	"NRF51",
    	"BLE_STACK_SUPPORT_REQD",
    	"S110",
    	"SOFTDEVICE_PRESENT",
    	"BOARD_PCA10028"
    ]
    cpp.warningLevel: "default" //"all" // or "none", "default"
    cpp.treatWarningsAsErrors: true
    cpp.executableSuffix: ".out"
    cpp.positionIndependentCode: false
    
    Properties {
    	condition: qbs.buildVariant === "debug"
    	cpp.commonCompilerFlags: [
    		"-mcpu=cortex-m0", "-mthumb", "-mabi=aapcs", "-mfloat-abi=soft",
    		"-std=gnu99", "-flto", "-fno-builtin",
    		"-fdata-sections","-ffunction-sections","-fno-strict-aliasing",
    		"-Wall",
    	]
    	cpp.debugInformation: true
    	cpp.optimization: "none" // "none" or "fast"
    }
    
    Properties {
    	condition: qbs.buildVariant === "release"
    	cpp.commonCompilerFlags: [
    		"-mcpu=cortex-m0", "-mthumb", "-mabi=aapcs", "-mfloat-abi=soft",
    		"-std=gnu99", "-flto", "-fno-builtin",
    		"-fdata-sections","-ffunction-sections","-fno-strict-aliasing",
    		"-Wall",
    	]
    	cpp.debugInformation: false
    	cpp.optimization: "small"
    }
    
    cpp.linkerFlags:[
    	"-Xlinker", "-Map="+buildDirectory+"/"+name+".map",
    	"-mthumb", "-mabi=aapcs",
    	"-L"+path+"/"+sdk+"components/toolchain/gcc/",
    	"-T"+path+"/"+sdk+"components/toolchain/gcc/gcc_nrf51_"+softDevice+"_"+deviceVariant+".ld",
    	"-mcpu=cortex-m0",
    	"-Wl,--gc-sections","--specs=nano.specs","-lc","-lnosys",
    ]
    cpp.includePaths: [
    	"../inc",
    	sdk+"examples/bsp",
    	sdk+"components/ble/common",
    	sdk+"components/ble/ble_services/ble_bas",
    	sdk+"components/ble/ble_services/ble_hrs",
    	sdk+"components/ble/ble_services/ble_dis",
    	sdk+"components/ble/device_manager",
    	sdk+"components/drivers_nrf/hal",
    	sdk+"components/drivers_nrf/uart",
    	sdk+"components/drivers_nrf/pstorage",
    	sdk+"components/drivers_nrf/pstorage/config",
    	sdk+"components/libraries/fifo",
    	sdk+"components/libraries/sensorsim",
    	sdk+"components/libraries/scheduler",
    	sdk+"components/libraries/timer",
    	sdk+"components/libraries/button",
    	sdk+"components/libraries/trace",
    	sdk+"components/libraries/gpiote",
    	sdk+"components/libraries/util",
    	sdk+"components/softdevice/"+softDevice+"/headers/",
    	sdk+"components/softdevice/common/softdevice_handler",
    	sdk+"components/toolchain/gcc",
    	sdk+"components/toolchain",
    ]
    files: [
    	"../src/*.c",
    	sdk+"examples/bsp/bsp.c",
    	sdk+"components/libraries/button/app_button.c",
    	sdk+"components/libraries/sensorsim/ble_sensorsim.c",
    	sdk+"components/libraries/util/app_error.c",
    	sdk+"components/libraries/timer/app_timer.c",
    	sdk+"components/libraries/gpiote/app_gpiote.c",
    	sdk+"components/libraries/scheduler/app_scheduler.c",
    	sdk+"components/libraries/util/nrf_assert.c",
    	sdk+"components/libraries/trace/app_trace.c",
    	sdk+"components/libraries/uart/retarget.c",
    	sdk+"components/libraries/fifo/app_fifo.c",
    	sdk+"components/drivers_nrf/hal/nrf_delay.c",
    	sdk+"components/drivers_nrf/pstorage/pstorage.c",
    	sdk+"components/drivers_nrf/uart/app_uart_fifo.c",
    	sdk+"components/softdevice/common/softdevice_handler/softdevice_handler.c",
    	sdk+"components/toolchain/system_nrf51.c",
    	sdk+"components/ble/ble_services/ble_hrs/ble_hrs.c",
    	sdk+"components/ble/ble_services/ble_dis/ble_dis.c",
    	sdk+"components/ble/ble_services/ble_bas/ble_bas.c",
    	sdk+"components/ble/common/ble_conn_params.c",
    	sdk+"components/ble/common/ble_advdata.c",
    	sdk+"components/ble/common/ble_srv_common.c",
    	sdk+"components/ble/device_manager/device_manager_peripheral.c",
    	sdk+"components/toolchain/gcc/gcc_startup_nrf51.s",
    ]
    
    Rule {
    	id: hex
    	inputs: "application"
    	Artifact {
    		fileTags: ["hex"]
    		filePath: FileInfo.baseName(input.filePath) + ".hex"
    	}
    	prepare: {
    		var args = ["-O", "ihex", input.filePath, output.filePath];
    		var cmd = new Command("arm-none-eabi-objcopy", args);
    		cmd.description = "converting to hex: "+FileInfo.fileName(input.filePath);
    		cmd.highlight = "linker";
    		return cmd;
    
    	}
    }
    
    Rule {
    	id: bin
    	inputs: "application"
    	Artifact {
    		fileTags: ["bin"]
    		filePath: FileInfo.baseName(input.filePath) + ".bin"
    	}
    	prepare: {
    		var args = ["-O", "binary", input.filePath, output.filePath];
    		var cmd = new Command("arm-none-eabi-objcopy", args);
    		cmd.description = "converting to bin: "+FileInfo.fileName(input.filePath);
    		cmd.highlight = "linker";
    		return cmd;
    
    	}
    }
    
    Rule {
    		id: size
    		inputs: ["application"]
    		Artifact {
    			fileTags: ["size"]
    			filePath: "-"
    		}
    		prepare: {
    			var args = [input.filePath];
    			var cmd = new Command("arm-none-eabi-size", args);
    			cmd.description = "File size: " + FileInfo.fileName(input.filePath);
    			cmd.highlight = "linker";
    			return cmd;
    		}
    	}
    }