Skip to content

Commit 7d47317

Browse files
authored
Merge pull request #66 from adafruit/develop
Clean up board and makefile
2 parents 2f314e1 + da2de8d commit 7d47317

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1102
-1525
lines changed

Makefile

Lines changed: 20 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#******************************************************************************
22
# CONFIGURE
3-
# - SDK_PATH : path to SDK directory
4-
# - SRC_PATH : path to src folder
3+
# - SDK_PATH : path to SDK directory
4+
# - SRC_PATH : path to src folder
55
#
6-
# - SD_NAME : e.g s132, s140
7-
# - SD_VER1, SD_VER2, SD_VER3: SoftDevice version e.g 6.0.0
8-
# - SD_HEX : to bootloader hex binary
6+
# - SD_NAME : e.g s132, s140
7+
# - SD_VERSION : SoftDevice version e.g 6.0.0
8+
# - SD_HEX : to bootloader hex binary
99
#******************************************************************************
1010
SRC_PATH = src
1111

@@ -16,26 +16,20 @@ SD_PATH = lib/softdevice/$(SD_FILENAME)
1616
TUSB_PATH = lib/tinyusb/src
1717
NRFX_PATH = lib/nrfx
1818

19-
SD_VER1 = 6
20-
SD_VER2 = 1
21-
SD_VER3 = 1
22-
23-
SD_VERSION = $(SD_VER1).$(SD_VER2).$(SD_VER3)
19+
SD_VERSION = 6.1.1
2420
SD_FILENAME = $(SD_NAME)_nrf52_$(SD_VERSION)
2521
SD_API_PATH = $(SD_PATH)/$(SD_FILENAME)_API
2622
SD_HEX = $(SD_PATH)/$(SD_FILENAME)_softdevice.hex
2723

28-
LD_FILE = $(SRC_PATH)/linker/$(SD_NAME)_v$(SD_VER1).ld
24+
LD_FILE = $(SRC_PATH)/linker/$(SD_NAME)_v$(word 1, $(subst ., ,$(SD_VERSION))).ld
2925

3026
MERGED_FNAME = $(OUTPUT_FILENAME)_$(SD_NAME)_$(SD_VERSION)
3127

32-
33-
MK_DIS_FIRMWARE = "$(SD_NAME) $(SD_VERSION)"
34-
3528
GIT_VERSION = $(shell git describe --dirty --always --tags)
3629
GIT_SUBMODULE_VERSIONS = $(shell git submodule status | cut -d' ' -f3,4 | paste -s -d" " -)
3730

3831
OUTPUT_FILENAME = $(BOARD)_bootloader-$(GIT_VERSION)
32+
3933
#******************************************************************************
4034
# Tool configure
4135
#******************************************************************************
@@ -80,22 +74,15 @@ remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-ou
8074
#*********************************
8175
# Select the board to build
8276
#*********************************
83-
BOARD_LIST = $(sort $(subst .h,,$(subst src/boards/,,$(wildcard src/boards/*.h))))
77+
BOARD_LIST = $(sort $(subst .h,,$(subst src/boards/,,$(wildcard src/boards/*))))
8478

8579
NRF52832_BOARDLIST = feather_nrf52832
8680
IS_52832 = $(filter $(BOARD),$(NRF52832_BOARDLIST))
8781

88-
ifeq ($(filter $(MAKECMDGOALS),all-board help),)
89-
ifeq ($(BOARD),)
90-
$(info You must provide a BOARD parameter with 'BOARD=')
91-
$(info Supported boards are: $(BOARD_LIST))
92-
$(info Run 'make help' for usage)
93-
$(error BOARD not defined)
94-
else
95-
ifeq ($(filter $(BOARD),$(BOARD_LIST)),)
96-
$(error Invalid BOARD specified)
97-
endif
98-
endif
82+
ifeq ($(filter $(BOARD),$(BOARD_LIST)),)
83+
$(info You must provide a BOARD parameter with 'BOARD='. Supported boards are:)
84+
$(info $(BOARD_LIST))
85+
$(error Invalid BOARD specified)
9986
endif
10087

10188
BUILD = _build-$(BOARD)
@@ -108,8 +95,6 @@ SD_NAME = s140
10895
DFU_DEV_REV = 52840
10996
endif
11097

111-
112-
11398
#******************************************************************************
11499
# SOURCE FILES
115100
#******************************************************************************
@@ -201,6 +186,8 @@ endif
201186

202187
# src
203188
IPATH += $(SRC_PATH)
189+
IPATH += $(SRC_PATH)/boards/$(BOARD)
190+
204191
IPATH += $(SRC_PATH)/cmsis/include
205192
IPATH += $(SRC_PATH)/usb
206193
IPATH += $(SRC_PATH)/boards
@@ -232,7 +219,6 @@ IPATH += $(SDK_PATH)/drivers_nrf/delay
232219
IPATH += $(SD_API_PATH)/include
233220
IPATH += $(SD_API_PATH)/include/nrf52
234221

235-
236222
INC_PATHS = $(addprefix -I,$(IPATH))
237223

238224
#******************************************************************************
@@ -251,23 +237,20 @@ CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
251237
CFLAGS += -fno-builtin --short-enums -fstack-usage
252238

253239
# Defined Symbol (MACROS)
254-
255-
# TODO use GIT_VERSION (numberic format)
256-
CFLAGS += -DMK_BOOTLOADER_VERSION=0x0$(SD_VER1)0$(SD_VER2)0$(SD_VER3)UL
257-
258240
CFLAGS += -D__HEAP_SIZE=0
259241
CFLAGS += -DCONFIG_GPIO_AS_PINRESET
242+
CFLAGS += -DCONFIG_NFCT_PINS_AS_GPIOS
260243
CFLAGS += -DBLE_STACK_SUPPORT_REQD
261-
CFLAGS += -DBSP_DEFINES_ONLY
262244
CFLAGS += -DSWI_DISABLE0
263245
CFLAGS += -DSOFTDEVICE_PRESENT
264246
CFLAGS += -DFLOAT_ABI_HARD
265-
CFLAGS += -DMK_DIS_FIRMWARE='$(MK_DIS_FIRMWARE)'
266247
CFLAGS += -DDFU_APP_DATA_RESERVED=7*4096
267248

268249
CFLAGS += -DUF2_VERSION='"$(GIT_VERSION) $(GIT_SUBMODULE_VERSIONS) $(SD_NAME) $(SD_VERSION)"'
269-
CFLAGS += -DBOARD_$(shell echo $(BOARD) | tr '[:lower:]' '[:upper:]')
270-
CFLAGS += -DBOARD_HEADER_FILE='"$(BOARD).h"'
250+
CFLAGS += -DBLEDIS_FW_VERSION='"$(GIT_VERSION) $(SD_NAME) $(SD_VERSION)"'
251+
252+
_VER = $(subst ., ,$(word 1, $(subst -, ,$(GIT_VERSION))))
253+
CFLAGS += -DMK_BOOTLOADER_VERSION='($(word 1,$(_VER)) << 16) + ($(word 2,$(_VER)) << 8) + $(word 3,$(_VER))'
271254

272255
ifneq ($(IS_52832),)
273256
CFLAGS += -DNRF52
@@ -302,9 +285,7 @@ LDFLAGS += --specs=nano.specs -lc -lnosys
302285
#******************************************************************************
303286
ASMFLAGS += -x assembler-with-cpp
304287
ASMFLAGS += -D__HEAP_SIZE=0
305-
ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET
306288
ASMFLAGS += -DBLE_STACK_SUPPORT_REQD
307-
ASMFLAGS += -DBSP_DEFINES_ONLY
308289
ASMFLAGS += -DSWI_DISABLE0
309290
ASMFLAGS += -DSOFTDEVICE_PRESENT
310291
ASMFLAGS += -DFLOAT_ABI_HARD
@@ -348,29 +329,6 @@ endif
348329
# default target to build
349330
all: $(BUILD)/$(OUTPUT_FILENAME)-nosd.out size
350331

351-
# Rule using BOARD_LIST, nl is newline
352-
define nl
353-
354-
355-
endef
356-
357-
_make_board = $(MAKE) -s -f $(MAKEFILE_LIST) -e BOARD=$1 $2 $(nl)
358-
_make_all_board = $(foreach b,$(BOARD_LIST), $(call _make_board,$b,$1))
359-
360-
# build all the boards
361-
all-board:
362-
$(call _make_all_board,clean all)
363-
364-
help:
365-
@echo To compile and build the current code for a board
366-
@echo $$ make BOARD=feather_nrf52840_express all
367-
@echo
368-
@echo To flash current code using Jlink
369-
@echo $$ make BOARD=feather_nrf52840_express flash
370-
@echo
371-
@echo To flash current code using existing bootloader dfu
372-
@echo $$ make BOARD=feather_nrf52840_express SERIAL=/dev/ttyACM0 dfu-flash
373-
374332
#******************* Flash target *******************
375333

376334
check_defined = \

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ This is a CDC/DFU/UF2 bootloader for nRF52 boards.
44

55
- [Adafruit Feather nRF52832](https://www.adafruit.com/product/3406)
66
- [Adafruit Feather nRF52840 Express](https://www.adafruit.com/product/4062)
7-
- Nordic nRF52840DK PCA10056
8-
- Nordic nRF52840DK PCA10059 ("Dongle")
7+
- Adafruit Metro nRF52840 Express
8+
- [Electronut Labs Papyr](https://docs.electronut.in/papyr/)
9+
- MakerDiary MDK nRF52840 USB Dongle
10+
- [Nordic nRF52840DK PCA10056](https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-DK)
11+
- [Nordic nRF52840DK PCA10059 ("Dongle")](https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-Dongle)
912
- Particle Argon
1013
- Particle Boron
1114
- Particle Xenon
12-
- MakerDiary MDK nRF52840 USB Dongle
13-
- [Electronut Labs Papyr](https://docs.electronut.in/papyr/)
1415

1516
UF2 is an easy-to-use bootloader that appears as a flash drive. You can just copy `.uf2`-format
1617
application images to the flash drive to load new firmware.

lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -994,20 +994,9 @@ static void services_init(void)
994994
ble_dis_init_t dis_init;
995995
memset(&dis_init, 0, sizeof(dis_init));
996996

997-
ascii_to_utf8(&dis_init.manufact_name_str, DIS_MANUFACTURER);
998-
ascii_to_utf8(&dis_init.model_num_str, DIS_MODEL);
999-
1000-
uint32_t const sd_id = SD_ID_GET(MBR_SIZE);
1001-
uint32_t const sd_version = SD_VERSION_GET(MBR_SIZE);
1002-
1003-
uint32_t const ver1 = sd_version / 1000000;
1004-
uint32_t const ver2 = (sd_version % 1000000)/1000;
1005-
uint32_t const ver3 = sd_version % 1000;
1006-
1007-
char fw_str[30+1];
1008-
sprintf(fw_str, "s%ld %ld.%ld.%ld r%ld", sd_id, ver1, ver2, ver3, MK_BOOTLOADER_VERSION & 0xFFUL);
1009-
1010-
ascii_to_utf8(&dis_init.fw_rev_str, fw_str);
997+
ascii_to_utf8(&dis_init.manufact_name_str, BLEDIS_MANUFACTURER);
998+
ascii_to_utf8(&dis_init.model_num_str, BLEDIS_MODEL);
999+
ascii_to_utf8(&dis_init.fw_rev_str, BLEDIS_FW_VERSION);
10111000

10121001
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&dis_init.dis_attr_md.read_perm);
10131002
BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&dis_init.dis_attr_md.write_perm);

src/boards.c

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,26 @@
1-
/**************************************************************************/
2-
/*!
3-
@file boards.c
4-
@author hathach (tinyusb.org)
5-
6-
@section LICENSE
7-
8-
Software License Agreement (BSD License)
9-
10-
Copyright (c) 2018, Adafruit Industries (adafruit.com)
11-
All rights reserved.
12-
13-
Redistribution and use in source and binary forms, with or without
14-
modification, are permitted provided that the following conditions are met:
15-
1. Redistributions of source code must retain the above copyright
16-
notice, this list of conditions and the following disclaimer.
17-
2. Redistributions in binary form must reproduce the above copyright
18-
notice, this list of conditions and the following disclaimer in the
19-
documentation and/or other materials provided with the distribution.
20-
3. Neither the name of the copyright holders nor the
21-
names of its contributors may be used to endorse or promote products
22-
derived from this software without specific prior written permission.
23-
24-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
25-
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
28-
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29-
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30-
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31-
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34-
*/
35-
/**************************************************************************/
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2018 Ha Thach for Adafruit Industries
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
3624

3725
#include "boards.h"
3826
#include "nrf_pwm.h"
@@ -50,6 +38,16 @@
5038
#endif
5139

5240
//------------- IMPLEMENTATION -------------//
41+
void button_init(uint32_t pin)
42+
{
43+
nrf_gpio_cfg_sense_input(pin, BUTTON_PULL, NRF_GPIO_PIN_SENSE_LOW);
44+
}
45+
46+
bool button_pressed(uint32_t pin)
47+
{
48+
return (nrf_gpio_pin_read(pin) == 0) ? true : false;
49+
}
50+
5351
void board_init(void)
5452
{
5553
// stop LF clock just in case we jump from application without reset

src/boards.h

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1-
/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
1+
/*
2+
* The MIT License (MIT)
23
*
3-
* The information contained herein is property of Nordic Semiconductor ASA.
4-
* Terms and conditions of usage are described in detail in NORDIC
5-
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
4+
* Copyright (c) 2018 Ha Thach for Adafruit Industries
65
*
7-
* Licensees are granted free, non-transferable use of the information. NO
8-
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
9-
* the file.
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
1012
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
1123
*/
24+
1225
#ifndef BOARDS_H
1326
#define BOARDS_H
1427

@@ -17,7 +30,7 @@
1730
#include <string.h>
1831
#include "nrf_gpio.h"
1932

20-
#include BOARD_HEADER_FILE
33+
#include "board.h"
2134

2235
#ifndef BUTTON_DFU
2336
#define BUTTON_DFU BUTTON_1
@@ -55,8 +68,6 @@ void board_teardown(void);
5568
// LED
5669
//--------------------------------------------------------------------+
5770

58-
#define bit(b) (1UL << (b))
59-
6071
enum {
6172
STATE_BOOTLOADER_STARTED = 0,
6273
STATE_USB_MOUNTED,
@@ -84,15 +95,8 @@ void led_tick(void);
8495
#error "At least two buttons required in the BSP (see 'BUTTONS_NUMBER')"
8596
#endif
8697

87-
static inline void button_init(uint32_t pin)
88-
{
89-
nrf_gpio_cfg_sense_input(pin, BUTTON_PULL, NRF_GPIO_PIN_SENSE_LOW);
90-
}
91-
92-
static inline bool button_pressed(uint32_t pin)
93-
{
94-
return (nrf_gpio_pin_read(pin) == 0) ? true : false;
95-
}
98+
void button_init(uint32_t pin);
99+
bool button_pressed(uint32_t pin);
96100

97101
bool is_ota(void);
98102

0 commit comments

Comments
 (0)