Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 37 additions & 42 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ endif
MK := mkdir
RM := rm -rf

# Verbose mode (V=). 0: default, 1: print out CFLAG, LDFLAG 2: print all compile command
ifeq ("$(V)","2")
QUIET :=
QUIET =
else
QUIET := @
QUIET = @
endif

GNU_PREFIX = arm-none-eabi
Expand All @@ -82,8 +83,8 @@ remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-ou
#*********************************
BOARD_LIST = $(sort $(subst .h,,$(subst src/boards/,,$(wildcard src/boards/*.h))))

NRF52840_BOARDLIST = pca10056 pca10059 feather_nrf52840_express particle_argon particle_boron particle_xenon
IS_NRF52840 = $(filter $(BOARD),$(NRF52840_BOARDLIST))
NRF52832_BOARDLIST = feather_nrf52832
IS_52832 = $(filter $(BOARD),$(NRF52832_BOARDLIST))

ifeq ($(filter $(MAKECMDGOALS),all-board all-release help),)
ifeq ($(BOARD),)
Expand All @@ -100,12 +101,12 @@ endif

BUILD = _build-$(BOARD)

ifneq ($(IS_NRF52840),)
SD_NAME = s140
DFU_DEV_REV = 52840
else
ifneq ($(IS_52832),)
SD_NAME = s132
DFU_DEV_REV = 0xADAF
else
SD_NAME = s140
DFU_DEV_REV = 52840
endif


Expand Down Expand Up @@ -149,7 +150,19 @@ C_SOURCE_FILES += $(SDK_PATH)/libraries/hci/hci_slip.c
C_SOURCE_FILES += $(SDK_PATH)/libraries/hci/hci_transport.c
C_SOURCE_FILES += $(SDK_PATH)/libraries/util/nrf_assert.c

ifneq ($(IS_NRF52840),)
ifneq ($(IS_52832),)

C_SOURCE_FILES += $(NRFX_PATH)/mdk/system_nrf52.c

C_SOURCE_FILES += $(SDK_PATH)/libraries/uart/app_uart.c
C_SOURCE_FILES += $(SDK_PATH)/drivers_nrf/uart/nrf_drv_uart.c
C_SOURCE_FILES += $(SDK_PATH)/drivers_nrf/common/nrf_drv_common.c

IPATH += $(SDK11_PATH)/libraries/util
IPATH += $(SDK_PATH)/drivers_nrf/common
IPATH += $(SDK_PATH)/drivers_nrf/uart

else

# src
C_SOURCE_FILES += $(SRC_PATH)/usb/usb_desc.c
Expand All @@ -171,28 +184,16 @@ C_SOURCE_FILES += $(TUSB_PATH)/class/msc/msc_device.c
C_SOURCE_FILES += $(TUSB_PATH)/class/custom/custom_device.c
C_SOURCE_FILES += $(TUSB_PATH)/tusb.c

else

C_SOURCE_FILES += $(NRFX_PATH)/mdk/system_nrf52.c

C_SOURCE_FILES += $(SDK_PATH)/libraries/uart/app_uart.c
C_SOURCE_FILES += $(SDK_PATH)/drivers_nrf/uart/nrf_drv_uart.c
C_SOURCE_FILES += $(SDK_PATH)/drivers_nrf/common/nrf_drv_common.c

IPATH += $(SDK11_PATH)/libraries/util
IPATH += $(SDK_PATH)/drivers_nrf/common
IPATH += $(SDK_PATH)/drivers_nrf/uart

endif


#******************************************************************************
# Assembly Files
#******************************************************************************
ifneq ($(IS_NRF52840),)
ASM_SOURCE_FILES = $(NRFX_PATH)/mdk/gcc_startup_nrf52840.S
else
ifneq ($(IS_52832),)
ASM_SOURCE_FILES = $(NRFX_PATH)/mdk/gcc_startup_nrf52.S
else
ASM_SOURCE_FILES = $(NRFX_PATH)/mdk/gcc_startup_nrf52840.S
endif

#******************************************************************************
Expand All @@ -203,6 +204,7 @@ endif
IPATH += $(SRC_PATH)
IPATH += $(SRC_PATH)/cmsis/include
IPATH += $(SRC_PATH)/usb
IPATH += $(SRC_PATH)/boards
IPATH += $(TUSB_PATH)

# nrfx
Expand Down Expand Up @@ -263,20 +265,16 @@ CFLAGS += -DMK_DIS_FIRMWARE='$(MK_DIS_FIRMWARE)'
CFLAGS += -DDFU_APP_DATA_RESERVED=7*4096

CFLAGS += -DUF2_VERSION='"$(GIT_VERSION) $(GIT_SUBMODULE_VERSIONS) $(SD_NAME) $(SD_VERSION)"'

CFLAGS += -DBOARD_$(shell echo $(BOARD) | tr '[:lower:]' '[:upper:]')
CFLAGS += -DBOARD_HEADER_FILE='"$(BOARD).h"'

ifneq ($(IS_NRF52840),)

CFLAGS += -DNRF52840_XXAA
CFLAGS += -DS140

else

ifneq ($(IS_52832),)
CFLAGS += -DNRF52
CFLAGS += -DNRF52832_XXAA
CFLAGS += -DS132

else
CFLAGS += -DNRF52840_XXAA
CFLAGS += -DS140
endif


Expand Down Expand Up @@ -310,19 +308,14 @@ ASMFLAGS += -DSWI_DISABLE0
ASMFLAGS += -DSOFTDEVICE_PRESENT
ASMFLAGS += -DFLOAT_ABI_HARD

ifneq ($(IS_NRF52840),)

ASMFLAGS += -DNRF52840_XXAA
ASMFLAGS += -DS140

else

ifneq ($(IS_52832),)
ASMFLAGS += -DNRF52
ASMFLAGS += -DS132

else
ASMFLAGS += -DNRF52840_XXAA
ASMFLAGS += -DS140
endif


C_SOURCE_FILE_NAMES = $(notdir $(C_SOURCE_FILES))
C_PATHS = $(call remduplicates, $(dir $(C_SOURCE_FILES) ) )
C_OBJECTS = $(addprefix $(BUILD)/, $(C_SOURCE_FILE_NAMES:.c=.o) )
Expand All @@ -345,6 +338,8 @@ $(info CFLAGS $(CFLAGS))
$(info )
$(info LDFLAGS $(LDFLAGS))
$(info )
$(info ASMFLAGS $(ASMFLAGS))
$(info )
endif

.phony: all clean size flash sd erase
Expand Down
26 changes: 26 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Adafruit nRF52 Bootloader Changelog

## 0.2.7

- Fixed PWM psel[1] is not reset
- Fixed #41 move RXD, TXD into board header
- Added Metro nRF52840 Rev A
- Fixed #40 OTA issue with BLE_GAP_EVT_PHY_UPDATE_REQUEST e.g connecting with iPhone X

## 0.2.6

- Fixed copy/restore current.uf2 issue
- Fixed neopixel won't turn off after dfu cdc

## 0.2.5

- Make led pattern more consistent
- Fixed issue nrf52840 not reset properly when upgrading bootloader+sd combo
- Make led pattern more consistent

## 0.2.3

- Fully support Feather nRF52840
- Update bootloader with new led pattern
- Fix #203: return software timer handle

Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,14 @@ static void on_ble_evt(ble_evt_t * p_ble_evt)
APP_ERROR_CHECK( sd_ble_gap_data_length_update(m_conn_handle, NULL, NULL) );
break;

case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
{
// Tell SoftDevice to choose PHY automatically
ble_gap_phys_t phy = { BLE_GAP_PHY_AUTO, BLE_GAP_PHY_AUTO };
(void) sd_ble_gap_phy_update(m_conn_handle, &phy);
}
break;

case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST:
{
uint16_t att_mtu = MIN(p_ble_evt->evt.gatts_evt.params.exchange_mtu_request.client_rx_mtu, BLEGATT_ATT_MTU_MAX);
Expand Down
10 changes: 1 addition & 9 deletions lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,14 @@


#if defined(NRF52832_XXAA)

#define BOOTLOADER_REGION_START 0x00074000 /**< This field should correspond to start address of the bootloader, found in UICR.RESERVED, 0x10001014, register. This value is used for sanity check, so the bootloader will fail immediately if this value differs from runtime value. The value is used to determine max application size for updating. */
#define BOOTLOADER_SETTINGS_ADDRESS 0x0007F000 /**< The field specifies the page location of the bootloader settings address. */
#define BOOTLOADER_MBR_PARAMS_PAGE_ADDRESS 0x0007E000 /**< The field specifies the page location of the mbr params page address. */


#elif defined(NRF52840_XXAA)

// Increase bootloader size to application data region for easy debugging
#ifdef DEBUG_SIZE_EXPAND
#define BOOTLOADER_REGION_START (0x000F4000 - CODE_PAGE_SIZE*7)
#define DFU_APP_DATA_RESERVED 0
#else
#define BOOTLOADER_REGION_START 0x000F4000 /**< This field should correspond to start address of the bootloader, found in UICR.RESERVED, 0x10001014, register. This value is used for sanity check, so the bootloader will fail immediately if this value differs from runtime value. The value is used to determine max application size for updating. */
#endif

#define BOOTLOADER_SETTINGS_ADDRESS 0x000FF000 /**< The field specifies the page location of the bootloader settings address. */
#define BOOTLOADER_MBR_PARAMS_PAGE_ADDRESS 0x000FE000 /**< The field specifies the page location of the mbr params page address. */

Expand Down
18 changes: 10 additions & 8 deletions src/boards.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ void board_init(void)

// Configure Systick for led blinky
NVIC_SetPriority(SysTick_IRQn, 7);
extern uint32_t SystemCoreClock;
SysTick_Config(SystemCoreClock/1000);
}

Expand Down Expand Up @@ -132,6 +131,9 @@ void pwm_teardown(NRF_PWM_Type* pwm )
pwm->ENABLE = 0;

pwm->PSEL.OUT[0] = 0xFFFFFFFF;
pwm->PSEL.OUT[1] = 0xFFFFFFFF;
pwm->PSEL.OUT[2] = 0xFFFFFFFF;
pwm->PSEL.OUT[3] = 0xFFFFFFFF;

pwm->MODE = 0;
pwm->COUNTERTOP = 0x3FF;
Expand Down Expand Up @@ -301,6 +303,7 @@ void led_state(uint32_t state)

static uint16_t pixels_pattern[NEO_NUMBYTE * 8 + 2];

// use PWM1 for neopixel
void neopixel_init(void)
{
// To support both the SoftDevice + Neopixels we use the EasyDMA
Expand All @@ -310,7 +313,7 @@ void neopixel_init(void)
// totalMem = numBytes*8*2+(2*2)
// The two additional bytes at the end are needed to reset the
// sequence.
NRF_PWM_Type* pwm = NRF_PWM2;
NRF_PWM_Type* pwm = NRF_PWM1;

// Set the wave mode to count UP
// Set the PWM to use the 16MHz clock
Expand Down Expand Up @@ -353,7 +356,7 @@ void neopixel_teardown(void)
neopixel_write(grb);
NRFX_DELAY_US(50); // wait for this write

pwm_teardown(NRF_PWM2);
pwm_teardown(NRF_PWM1);
}

// write 3 bytes color to a built-in neopixel
Expand All @@ -376,17 +379,16 @@ void neopixel_write (uint8_t *pixels)
pixels_pattern[pos++] = 0 | (0x8000); // Seq end
pixels_pattern[pos++] = 0 | (0x8000); // Seq end


NRF_PWM_Type* pwm = NRF_PWM2;
NRF_PWM_Type* pwm = NRF_PWM1;

nrf_pwm_seq_ptr_set(pwm, 0, pixels_pattern);
nrf_pwm_seq_cnt_set(pwm, 0, sizeof(pixels_pattern)/2);
nrf_pwm_event_clear(pwm, NRF_PWM_EVENT_SEQEND0);
nrf_pwm_task_trigger(pwm, NRF_PWM_TASK_SEQSTART0);

// no need to blocking wait for sequence complete
// while( !nrf_pwm_event_check(pwm, NRF_PWM_EVENT_SEQEND0) ) {}
// nrf_pwm_event_clear(pwm, NRF_PWM_EVENT_SEQEND0);
// blocking wait for sequence complete
while( !nrf_pwm_event_check(pwm, NRF_PWM_EVENT_SEQEND0) ) {}
nrf_pwm_event_clear(pwm, NRF_PWM_EVENT_SEQEND0);
}
#endif

Expand Down
38 changes: 12 additions & 26 deletions src/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,7 @@
#include <string.h>
#include "nrf_gpio.h"

#if defined BOARD_FEATHER_NRF52840_EXPRESS
#include "boards/feather_nrf52840_express.h"
#elif defined BOARD_FEATHER_NRF52832
#include "boards/feather_nrf52832.h"
#elif defined BOARD_PCA10056
#include "boards/pca10056.h"
#elif defined BOARD_PCA10059
#include "boards/pca10059.h"
#elif defined BOARD_PARTICLE_ARGON
#include "boards/particle_argon.h"
#elif defined BOARD_PARTICLE_BORON
#include "boards/particle_boron.h"
#elif defined BOARD_PARTICLE_XENON
#include "boards/particle_xenon.h"
#else
#error No boards defined
#endif
#include BOARD_HEADER_FILE

#ifndef BUTTON_DFU
#define BUTTON_DFU BUTTON_1
Expand Down Expand Up @@ -73,15 +57,17 @@ void board_teardown(void);

#define bit(b) (1UL << (b))

#define STATE_BOOTLOADER_STARTED 0
#define STATE_USB_MOUNTED 1
#define STATE_USB_UNMOUNTED 2
#define STATE_FACTORY_RESET_STARTED 3
#define STATE_FACTORY_RESET_FINISHED 4
#define STATE_WRITING_STARTED 5
#define STATE_WRITING_FINISHED 6
#define STATE_BLE_CONNECTED 7
#define STATE_BLE_DISCONNECTED 8
enum {
STATE_BOOTLOADER_STARTED = 0,
STATE_USB_MOUNTED,
STATE_USB_UNMOUNTED,
STATE_FACTORY_RESET_STARTED,
STATE_FACTORY_RESET_FINISHED,
STATE_WRITING_STARTED,
STATE_WRITING_FINISHED,
STATE_BLE_CONNECTED,
STATE_BLE_DISCONNECTED
};

void led_pwm_init(uint32_t led_index, uint32_t led_pin);
void led_pwm_teardown(void);
Expand Down
32 changes: 16 additions & 16 deletions src/boards/feather_nrf52832.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,32 @@
/*------------------------------------------------------------------*/
/* LED
*------------------------------------------------------------------*/
#define LEDS_NUMBER 2
#define LED_PRIMARY_PIN 17 // Red
#define LED_SECONDARY_PIN 19 // Blue
#define LED_STATE_ON 1
#define LEDS_NUMBER 2
#define LED_PRIMARY_PIN 17 // Red
#define LED_SECONDARY_PIN 19 // Blue
#define LED_STATE_ON 1

/*------------------------------------------------------------------*/
/* BUTTON
*------------------------------------------------------------------*/
#define BUTTONS_NUMBER 2
#define BUTTON_1 20
#define BUTTON_2 22
#define BUTTON_PULL NRF_GPIO_PIN_PULLUP
#define BUTTONS_NUMBER 2
#define BUTTON_1 20
#define BUTTON_2 22
#define BUTTON_PULL NRF_GPIO_PIN_PULLUP

/*------------------------------------------------------------------*/
/* UART
*------------------------------------------------------------------*/
#define RX_PIN_NUMBER 8
#define TX_PIN_NUMBER 6
#define CTS_PIN_NUMBER 7
#define RTS_PIN_NUMBER 5
#define HWFC false
#define RX_PIN_NUMBER 8
#define TX_PIN_NUMBER 6
#define CTS_PIN_NUMBER 0
#define RTS_PIN_NUMBER 0
#define HWFC false

// Used as model string in OTA mode
#define DIS_MANUFACTURER "Adafruit Industries"
#define DIS_MODEL "Bluefruit Feather nRF52832"
#define DIS_MANUFACTURER "Adafruit Industries"
#define DIS_MODEL "Bluefruit Feather nRF52832"

#define PRODUCT_NAME "Adafruit Bluefruit Feather nRF52832"
#define PRODUCT_NAME "Adafruit Bluefruit Feather nRF52832"

#endif // _FEATHER52832_H
Loading