Last active
May 6, 2021 16:18
-
-
Save drfloob/884989c24802a56db7a5aaf068553ed5 to your computer and use it in GitHub Desktop.
Minimal build files for SoftDevice 110 version of the nrf51 blinky peripheral example - armgcc on Linux, Waveshare ble400 board
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Unmodified from the original example in the NRF51 SDK | |
/* Linker script to configure memory regions. */ | |
SEARCH_DIR(.) | |
GROUP(-lgcc -lc -lnosys) | |
MEMORY | |
{ | |
FLASH (rx) : ORIGIN = 0x18000, LENGTH = 0x28000 | |
RAM (rwx) : ORIGIN = 0x20002000, LENGTH = 0x6000 | |
} | |
SECTIONS | |
{ | |
.fs_data_out ALIGN(4): | |
{ | |
PROVIDE( __start_fs_data = .); | |
KEEP(*(fs_data)) | |
PROVIDE( __stop_fs_data = .); | |
} = 0 | |
} | |
INCLUDE "nrf5x_common.ld"% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
See examples/bsp/boards.h from the NRF51 SDK. | |
The Makefile adds the `-DCUSTOM_BOARD` compiler flag | |
*/ | |
#ifndef BLE400_H | |
#define BLE400_H | |
// LEDs definitions for BLE400 | |
#define LEDS_NUMBER 5 | |
#define LED_START 18 | |
#define LED_1 18 | |
#define LED_2 19 | |
#define LED_3 20 | |
#define LED_4 21 | |
#define LED_5 22 | |
#define LED_STOP 22 | |
#define LEDS_LIST { LED_1, LED_2, LED_3, LED_4, LED_5 } | |
#define BSP_LED_0 LED_1 | |
#define BSP_LED_1 LED_2 | |
#define BSP_LED_2 LED_3 | |
#define BSP_LED_3 LED_4 | |
#define BSP_LED_4 LED_5 | |
#define BSP_LED_0_MASK (1<<BSP_LED_0) | |
#define BSP_LED_1_MASK (1<<BSP_LED_1) | |
#define BSP_LED_2_MASK (1<<BSP_LED_2) | |
#define BSP_LED_3_MASK (1<<BSP_LED_3) | |
#define BSP_LED_4_MASK (1<<BSP_LED_4) | |
#define LEDS_MASK (BSP_LED_0_MASK | BSP_LED_1_MASK | BSP_LED_2_MASK | BSP_LED_3_MASK | BSP_LED_4_MASK) | |
/* all LEDs are lit when GPIO is low */ | |
#define LEDS_INV_MASK LEDS_MASK | |
#define BUTTONS_NUMBER 2 | |
#define BUTTON_START 16 | |
#define BUTTON_1 16 | |
#define BUTTON_2 17 | |
#define BUTTON_STOP 17 | |
#define BUTTON_PULL NRF_GPIO_PIN_PULLUP | |
#define BUTTONS_LIST { BUTTON_1, BUTTON_2 } | |
#define BSP_BUTTON_0 BUTTON_1 | |
#define BSP_BUTTON_1 BUTTON_2 | |
#define BSP_BUTTON_0_MASK (1<<BSP_BUTTON_0) | |
#define BSP_BUTTON_1_MASK (1<<BSP_BUTTON_1) | |
#define BUTTONS_MASK 0x001E0000 | |
#define RX_PIN_NUMBER 9 | |
#define TX_PIN_NUMBER 11 | |
#define CTS_PIN_NUMBER 8 | |
#define RTS_PIN_NUMBER 10 | |
#define HWFC true | |
#define SPIS_MISO_PIN 28 // SPI MISO signal. | |
#define SPIS_CSN_PIN 12 // SPI CSN signal. | |
#define SPIS_MOSI_PIN 25 // SPI MOSI signal. | |
#define SPIS_SCK_PIN 29 // SPI SCK signal. | |
#define SPIM0_SCK_PIN 29 // SPI clock GPIO pin number. | |
#define SPIM0_MOSI_PIN 25 // SPI Master Out Slave In GPIO pin number. | |
#define SPIM0_MISO_PIN 28 // SPI Master In Slave Out GPIO pin number. | |
#define SPIM0_SS_PIN 12 // SPI Slave Select GPIO pin number. | |
#define SPIM1_SCK_PIN 2 // SPI clock GPIO pin number. | |
#define SPIM1_MOSI_PIN 3 // SPI Master Out Slave In GPIO pin number. | |
#define SPIM1_MISO_PIN 4 // SPI Master In Slave Out GPIO pin number. | |
#define SPIM1_SS_PIN 5 // SPI Slave Select GPIO pin number. | |
#define SPIM2_SCK_PIN 12 // SPI clock GPIO pin number. | |
#define SPIM2_MOSI_PIN 13 // SPI Master Out Slave In GPIO pin number. | |
#define SPIM2_MISO_PIN 14 // SPI Master In Slave Out GPIO pin number. | |
#define SPIM2_SS_PIN 15 // SPI Slave Select GPIO pin number. | |
// serialization APPLICATION board - temp. setup for running serialized MEMU tests | |
#define SER_APP_RX_PIN 31 // UART RX pin number. | |
#define SER_APP_TX_PIN 30 // UART TX pin number. | |
#define SER_APP_CTS_PIN 28 // UART Clear To Send pin number. | |
#define SER_APP_RTS_PIN 29 // UART Request To Send pin number. | |
#define SER_APP_SPIM0_SCK_PIN 2 // SPI clock GPIO pin number. | |
#define SER_APP_SPIM0_MOSI_PIN 4 // SPI Master Out Slave In GPIO pin number | |
#define SER_APP_SPIM0_MISO_PIN 3 // SPI Master In Slave Out GPIO pin number | |
#define SER_APP_SPIM0_SS_PIN 31 // SPI Slave Select GPIO pin number | |
#define SER_APP_SPIM0_RDY_PIN 29 // SPI READY GPIO pin number | |
#define SER_APP_SPIM0_REQ_PIN 30 // SPI REQUEST GPIO pin number | |
// serialization CONNECTIVITY board | |
#define SER_CON_RX_PIN 13 // UART RX pin number. | |
#define SER_CON_TX_PIN 12 // UART TX pin number. | |
#define SER_CON_CTS_PIN 14 // UART Clear To Send pin number. Not used if HWFC is set to false. | |
#define SER_CON_RTS_PIN 15 // UART Request To Send pin number. Not used if HWFC is set to false. | |
#define SER_CON_SPIS_SCK_PIN 29 // SPI SCK signal. | |
#define SER_CON_SPIS_MOSI_PIN 25 // SPI MOSI signal. | |
#define SER_CON_SPIS_MISO_PIN 28 // SPI MISO signal. | |
#define SER_CON_SPIS_CSN_PIN 12 // SPI CSN signal. | |
#define SER_CON_SPIS_RDY_PIN 14 // SPI READY GPIO pin number. | |
#define SER_CON_SPIS_REQ_PIN 13 // SPI REQUEST GPIO pin number. | |
#define SER_CONN_CHIP_RESET_PIN 27 // Pin used to reset connectivity chip | |
// Arduino board mappings | |
#define ARDUINO_SCL_PIN 27 // SCL signal pin | |
#define ARDUINO_SDA_PIN 26 // SDA signal pin | |
#define ARDUINO_AREF_PIN 2 // Aref pin | |
#define ARDUINO_13_PIN 25 // Digital pin 13 | |
#define ARDUINO_12_PIN 24 // Digital pin 12 | |
#define ARDUINO_11_PIN 23 // Digital pin 11 | |
#define ARDUINO_10_PIN 22 // Digital pin 10 | |
#define ARDUINO_9_PIN 20 // Digital pin 9 | |
#define ARDUINO_8_PIN 19 // Digital pin 8 | |
#define ARDUINO_7_PIN 18 // Digital pin 7 | |
#define ARDUINO_6_PIN 17 // Digital pin 6 | |
#define ARDUINO_5_PIN 16 // Digital pin 5 | |
#define ARDUINO_4_PIN 15 // Digital pin 4 | |
#define ARDUINO_3_PIN 14 // Digital pin 3 | |
#define ARDUINO_2_PIN 13 // Digital pin 2 | |
#define ARDUINO_1_PIN 12 // Digital pin 1 | |
#define ARDUINO_0_PIN 11 // Digital pin 0 | |
#define ARDUINO_A0_PIN 3 // Analog channel 0 | |
#define ARDUINO_A1_PIN 4 // Analog channel 1 | |
#define ARDUINO_A2_PIN 28 // Analog channel 2 | |
#define ARDUINO_A3_PIN 29 // Analog channel 3 | |
#define ARDUINO_A4_PIN 30 // Analog channel 4 | |
#define ARDUINO_A5_PIN 31 // Analog channel 5 | |
// Low frequency clock source to be used by the SoftDevice | |
#define NRF_CLOCK_LFCLKSRC NRF_CLOCK_LFCLKSRC_XTAL_20_PPM | |
#endif // BLE400_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# After starting openocd, and telnetting into it | |
# telnet localhost 4444 | |
reset halt | |
nrf51 mass_erase | |
program s110_nrf51_8.0.0_softdevice.hex verify | |
program /home/alarm/_build_blinky/nrf51822_blinky_s110_out.hex verify | |
reset run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Unmodified from the original example in the NRF51 SDK | |
/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved. | |
* | |
* The information contained herein is property of Nordic Semiconductor ASA. | |
* Terms and conditions of usage are described in detail in NORDIC | |
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. | |
* | |
* Licensees are granted free, non-transferable use of the information. NO | |
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from | |
* the file. | |
* | |
*/ | |
/** @file | |
* | |
* @defgroup blinky_example_main main.c | |
* @{ | |
* @ingroup blinky_example | |
* @brief Blinky Example Application main file. | |
* | |
*/ | |
#include <stdbool.h> | |
#include <stdint.h> | |
#include "nrf_delay.h" | |
#include "nrf_gpio.h" | |
#include "boards.h" | |
const uint8_t leds_list[LEDS_NUMBER] = LEDS_LIST; | |
/** | |
* @brief Function for application main entry. | |
*/ | |
int main(void) | |
{ | |
// Configure LED-pins as outputs. | |
LEDS_CONFIGURE(LEDS_MASK); | |
// Toggle LEDs. | |
while (true) | |
{ | |
for (int i = 0; i < LEDS_NUMBER; i++) | |
{ | |
LEDS_INVERT(1 << leds_list[i]); | |
nrf_delay_ms(500); | |
} | |
} | |
} | |
/** @} */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Environment Variables required for this to run | |
# NRF_SDK_INSTALL_DIR=/path/to/nrf51_sdk_10 | |
PROJECT_NAME := blinky_s110_play | |
export OUTPUT_FILENAME | |
#MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)) | |
MAKEFILE_NAME := $(MAKEFILE_LIST) | |
MAKEFILE_DIR := $(dir $(MAKEFILE_NAME) ) | |
FILENAME := nrf51822_blinky_s110_out | |
TEMPLATE_PATH = $(NRF_SDK_INSTALL_DIR)/components/toolchain/gcc | |
include $(TEMPLATE_PATH)/Makefile.posix | |
MK := mkdir | |
RM := rm -rf | |
#echo suspend | |
ifeq ("$(VERBOSE)","1") | |
NO_ECHO := | |
else | |
NO_ECHO := @ | |
endif | |
# Toolchain commands | |
CC := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-gcc' | |
AS := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-as' | |
AR := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ar' -r | |
LD := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ld' | |
NM := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-nm' | |
OBJDUMP := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objdump' | |
OBJCOPY := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objcopy' | |
SIZE := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-size' | |
#function for removing duplicates in a list | |
remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1)))) | |
#source common to all targets | |
C_SOURCE_FILES += \ | |
$(abspath $(NRF_SDK_INSTALL_DIR)/components/toolchain/system_nrf51.c) \ | |
$(abspath ../main.c) \ | |
$(abspath $(NRF_SDK_INSTALL_DIR)/components/drivers_nrf/delay/nrf_delay.c) \ | |
#assembly files common to all targets | |
ASM_SOURCE_FILES = $(abspath $(NRF_SDK_INSTALL_DIR)/components/toolchain/gcc/gcc_startup_nrf51.s) | |
#includes common to all targets | |
INC_PATHS += -I$(abspath $(NRF_SDK_INSTALL_DIR)/components/toolchain/gcc) | |
INC_PATHS += -I$(abspath $(NRF_SDK_INSTALL_DIR)/components/toolchain) | |
INC_PATHS += -I$(abspath $(NRF_SDK_INSTALL_DIR)/examples/bsp) | |
INC_PATHS += -I$(abspath $(NRF_SDK_INSTALL_DIR)/components/device) | |
INC_PATHS += -I$(abspath $(NRF_SDK_INSTALL_DIR)/components/drivers_nrf/delay) | |
INC_PATHS += -I$(abspath $(NRF_SDK_INSTALL_DIR)/components/drivers_nrf/hal) | |
INC_PATHS += -I$(abspath $(NRF_SDK_INSTALL_DIR)/components/softdevice/s110/headers) | |
OBJECT_DIRECTORY = _build | |
LISTING_DIRECTORY = $(OBJECT_DIRECTORY) | |
OUTPUT_BINARY_DIRECTORY = $(OBJECT_DIRECTORY) | |
# Sorting removes duplicates | |
BUILD_DIRECTORIES := $(sort $(OBJECT_DIRECTORY) $(OUTPUT_BINARY_DIRECTORY) $(LISTING_DIRECTORY) ) | |
#flags common to all targets | |
CFLAGS = -DBOARD_CUSTOM | |
CFLAGS += -DSOFTDEVICE_PRESENT | |
CFLAGS += -DNRF51 | |
CFLAGS += -DS110 | |
CFLAGS += -DBLE_STACK_SUPPORT_REQD | |
CFLAGS += -DBSP_DEFINES_ONLY | |
CFLAGS += -mcpu=cortex-m0 | |
CFLAGS += -mthumb -mabi=aapcs --std=gnu99 | |
CFLAGS += -Wall -Werror -O3 | |
CFLAGS += -mfloat-abi=soft | |
# keep every function in separate section. This will allow linker to dump unused functions | |
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing | |
CFLAGS += -fno-builtin --short-enums | |
# keep every function in separate section. This will allow linker to dump unused functions | |
LDFLAGS += -Xlinker -Map=$(LISTING_DIRECTORY)/$(OUTPUT_FILENAME).map | |
LDFLAGS += -mthumb -mabi=aapcs -L $(TEMPLATE_PATH) -T$(LINKER_SCRIPT) | |
LDFLAGS += -mcpu=cortex-m0 | |
# let linker to dump unused sections | |
LDFLAGS += -Wl,--gc-sections | |
# use newlib in nano version | |
LDFLAGS += --specs=nano.specs -lc -lnosys | |
# Assembler flags | |
ASMFLAGS += -x assembler-with-cpp | |
ASMFLAGS += -DNRF51 | |
ASMFLAGS += -DBOARD_CUSTOM | |
ASMFLAGS += -DBSP_DEFINES_ONLY | |
ASMFLAGS += -DSOFTDEVICE_PRESENT | |
ASMFLAGS += -DS110 | |
ASMFLAGS += -DBLE_STACK_SUPPORT_REQD | |
#default target - first one defined | |
default: clean $(FILENAME) | |
#building all targets | |
all: clean | |
$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e cleanobj | |
$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e $(FILENAME) | |
#target for printing all targets | |
help: | |
@echo following targets are available: | |
@echo $(FILENAME) | |
@echo flash_softdevice | |
C_SOURCE_FILE_NAMES = $(notdir $(C_SOURCE_FILES)) | |
C_PATHS = $(call remduplicates, $(dir $(C_SOURCE_FILES) ) ) | |
C_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(C_SOURCE_FILE_NAMES:.c=.o) ) | |
ASM_SOURCE_FILE_NAMES = $(notdir $(ASM_SOURCE_FILES)) | |
ASM_PATHS = $(call remduplicates, $(dir $(ASM_SOURCE_FILES) )) | |
ASM_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(ASM_SOURCE_FILE_NAMES:.s=.o) ) | |
vpath %.c $(C_PATHS) | |
vpath %.s $(ASM_PATHS) | |
OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS) | |
$(FILENAME): OUTPUT_FILENAME := $(FILENAME) | |
$(FILENAME): LINKER_SCRIPT=blinky_gcc_nrf51.ld | |
$(FILENAME): $(BUILD_DIRECTORIES) $(OBJECTS) | |
@echo Linking target: $(OUTPUT_FILENAME).out | |
$(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out | |
$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e finalize | |
## Create build directories | |
$(BUILD_DIRECTORIES): | |
echo $(MAKEFILE_NAME) | |
$(MK) $@ | |
# Create objects from C SRC files | |
$(OBJECT_DIRECTORY)/%.o: %.c | |
@echo Compiling file: $(notdir $<) | |
$(NO_ECHO)$(CC) $(CFLAGS) $(INC_PATHS) -c -o $@ $< | |
# Assemble files | |
$(OBJECT_DIRECTORY)/%.o: %.s | |
@echo Compiling file: $(notdir $<) | |
$(NO_ECHO)$(CC) $(ASMFLAGS) $(INC_PATHS) -c -o $@ $< | |
# Link | |
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out: $(BUILD_DIRECTORIES) $(OBJECTS) | |
@echo Linking target: $(OUTPUT_FILENAME).out | |
$(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out | |
## Create binary .bin file from the .out file | |
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out | |
@echo Preparing: $(OUTPUT_FILENAME).bin | |
$(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin | |
## Create binary .hex file from the .out file | |
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out | |
@echo Preparing: $(OUTPUT_FILENAME).hex | |
$(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex | |
finalize: genbin genhex echosize | |
genbin: | |
@echo Preparing: $(OUTPUT_FILENAME).bin | |
$(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin | |
## Create binary .hex file from the .out file | |
genhex: | |
@echo Preparing: $(OUTPUT_FILENAME).hex | |
$(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex | |
echosize: | |
-@echo '' | |
$(NO_ECHO)$(SIZE) $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out | |
-@echo '' | |
clean: | |
$(RM) $(BUILD_DIRECTORIES) | |
cleanobj: | |
$(RM) $(BUILD_DIRECTORIES)/*.o | |
flash: $(MAKECMDGOALS) | |
@echo Flashing: $(OUTPUT_BINARY_DIRECTORY)/$<.hex | |
nrfjprog --program $(OUTPUT_BINARY_DIRECTORY)/$<.hex -f nrf51 --sectorerase | |
nrfjprog --reset | |
## Flash softdevice | |
flash_softdevice: | |
@echo Flashing: s110_nrf51_8.0.0_softdevice.hex | |
nrfjprog --program ../../../../../../components/softdevice/s110/hex/s110_nrf51_8.0.0_softdevice.hex -f nrf51 --chiperase | |
nrfjprog --reset |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run OpenOcd to use the STLink v2 programmer/debugger | |
# Note: I compiled openocd locally with RPi support, hence the binary path | |
./openocd/src/openocd -d2 -s openocd/tcl/ -d2 -f interface/stlink.cfg -f target/nrf51_stlink.tcl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment