Skip to content
Open
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
nrf-sdk/
_build/
.DS_Store
15 changes: 10 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
{
"actionButtons": {
"defaultColor": "#ff0034", // Can also use string color names.
"loadNpmCommands":false, // Disables automatic generation of actions for npm commands.
"reloadButton":"♻️", // Custom reload button text or icon (default ↻). null value enables automatic reload on configuration change
"commands": [
{
"name": "Setup",
"color": "black",
"singleInstance": true,
"command": "make setup", // This is executed in the terminal.
},
{
"name": "Build",
"color": "black",
"singleInstance": true,
"command": "make nrf52840_xxaa", // This is executed in the terminal.
},
{
"name": "Flash",
"color": "black",
"singleInstance": true,
"command": "make flash", // This is executed in the terminal.
},
{
"name": "Flash Soft-Device",
"color": "black",
"singleInstance": true,
"command": "make flash_softdevice", // This is executed in the terminal.
},
Expand All @@ -33,6 +28,16 @@
"color": "red",
"singleInstance": true,
"command": "make erase", // This is executed in the terminal.
},
{
"name": "Clean",
"singleInstance": true,
"command": "make clean", // This is executed in the terminal.
},
{
"name": "Reset",
"singleInstance": true,
"command": "make reset", // This is executed
}
]
},
Expand Down
39 changes: 33 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
PROJECT_NAME := ble_app_blinky_pca10056_s140
TARGETS := nrf52840_xxaa
OUTPUT_DIRECTORY := _build
ARM_TOOLCHAIN ?= /usr/local/bin/

SDK_ROOT := ./nrf-sdk
PROJ_DIR := ./
Expand Down Expand Up @@ -259,6 +260,18 @@ nrf52840_xxaa: ASMFLAGS += -D__STACK_SIZE=8192
# that may need symbols provided by these libraries.
LIB_FILES += -lc -lnosys -lm

### OS Agnosticity shennanigans ###
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
GNU_INSTALL_ROOT ?= $(ARM_TOOLCHAIN)
SETUP_CLI_SCRIPT ?= scripts/macOS/get_cli_tools.sh
SETUP_SDK_SCRIPT ?= scripts/macOS/get_sdk.sh
endif
ifeq ($(UNAME_S),Linux)
GNU_INSTALL_ROOT ?= $(ARM_TOOLCHAIN)
SETUP_CLI_SCRIPT ?= scripts/linux/get_cli_tools.sh
SETUP_SDK_SCRIPT ?= scripts/linux/get_sdk.sh
endif

.PHONY: default help

Expand All @@ -269,21 +282,35 @@ default: nrf52840_xxaa
help:
@echo following targets are available:
@echo setup - download and install compiler, sdk, and micro-ecc
@echo reset - remove sdk and output directory
@echo clean - remove output directory
@echo nrf52840_xxaa
@echo flash_softdevice
@echo sdk_config - starting external tool for editing sdk_config.h
@echo flash - flashing binary

setup: ./nrf-sdk
./scripts/get_cli_tools.sh
setup:
# create nrf-sdk directory
mkdir -p $(SDK_ROOT)
@echo ""
@echo "Setting up CLI"
./$(SETUP_CLI_SCRIPT)
@echo ""
@echo "Setting up SDK"
./$(SETUP_SDK_SCRIPT)
@echo ""

./nrf-sdk:
./scripts/get_sdk.sh
reset:
@echo "Resetting project"
@rm -rf $(SDK_ROOT)
@rm -rf $(OUTPUT_DIRECTORY)

TEMPLATE_PATH := $(SDK_ROOT)/components/toolchain/gcc
clean:
@rm -rf $(OUTPUT_DIRECTORY)


include $(TEMPLATE_PATH)/Makefile.common
TEMPLATE_PATH ?= $(SDK_ROOT)/components/toolchain/gcc
-include $(TEMPLATE_PATH)/Makefile.common

$(foreach target, $(TARGETS), $(call define_target, $(target)))

Expand Down
34 changes: 29 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
# Why?
# nRF52840 VSCode Template

## Why ?

I was frustrated with the setup process for the nrf sdk and tools, so I made this sample project to make setup simple and automate installation of the sdk and cli tools.

# Environment Setup
#### Note, the setup scripts assume you are running this on a 64-bit debian/ubuntu based linux distribution
## Environment Setup

### macOS

#### Pre-requisites

VSCode has to be installed, along with `make`, `wget`, and `git`.

`arm-gcc` toolchain has to be installed. You can install it using homebrew:

```bash
brew install arm-none-eabi-gcc
```

#### Setup

1. Open this directory in VSCode
2. Install the extensions listed below
3. Click the "Setup" button in the status bar (if VSCode action buttons is installed), or run `make setup` from the command line
4. Follow instructions in the terminal (some links should open in Safari, and Finder windows will open to make file copies easier)

### Linux

1. Install vscode, make, wget, git, tar, and unzip
2. Run `code ./` in this directory
3. Install extensions listed below
4. Click the "Setup" button in the status bar or run `make setup` from the command line

## VS Code extensions used

# VS Code extensions used
* [C/C++](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools)
* [VsCode Action Buttons (optional)](https://marketplace.visualstudio.com/items?itemName=seunlanlege.action-buttons)
* [VSCode Action Buttons (optional)](https://marketplace.visualstudio.com/items?itemName=seunlanlege.action-buttons)
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions scripts/macOS/get_cli_tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

echo "Please download the latest macOS nRF Command Line Tools from the NordicSemi website and install them."
open -a Safari https://www.nordicsemi.com/Products/Development-tools/nrf-command-line-tools/download
read -n 1 -s -r -p "Press any key to continue"
22 changes: 22 additions & 0 deletions scripts/macOS/get_sdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

git_root=`git rev-parse --show-toplevel`


open ./nrf-sdk
echo "Download the latest nRF5 SDK, along your preferred softdevices and tools"
open -a Safari "https://www.nordicsemi.com/Products/Development-software/nRF5-SDK/Download#infotabs"
echo "Once downloaded, extract the SDK to the nrf-sdk folder"
echo ""

# wait for the user to press a key
read -n 1 -s -r -p "Press any key to continue"
echo ""

# Clone and install micro-ecc
git clone --depth 1 https://github.com/kmackay/micro-ecc.git nrf-sdk/external/micro-ecc/micro-ecc
# replace "/usr/local/gcc-arm-none-eabi-9-2020-q2-update/bin/" with "/usr/local/bin" in "nrf-sdk/components/toolchain/gcc/Makefile.posix"
sed -i '' 's/\/usr\/local\/gcc-arm-none-eabi-9-2020-q2-update\/bin\//\/usr\/local\/bin\//g' nrf-sdk/components/toolchain/gcc/Makefile.posix
(cd nrf-sdk/external/micro-ecc/nrf52hf_armgcc/armgcc; make;)