From 9ece5f64a95e1d1b439084b1e9fa87db3099ea00 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 4 Jan 2019 07:00:45 +0700 Subject: [PATCH 1/9] clean up makefile --- Makefile | 74 +++++++++++++++++++++++----------------------------- src/boards.c | 6 ++--- 2 files changed, 35 insertions(+), 45 deletions(-) diff --git a/Makefile b/Makefile index 1f2cdc3..b952016 100644 --- a/Makefile +++ b/Makefile @@ -82,8 +82,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),) @@ -100,12 +100,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 @@ -149,7 +149,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 @@ -171,28 +183,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 #****************************************************************************** @@ -263,20 +263,15 @@ 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:]') -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 @@ -310,19 +305,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) ) @@ -448,12 +438,12 @@ $(BUILD)/%.o: %.c # Assemble files $(BUILD)/%.o: %.S @echo AS $(notdir $<) - $(QUIET)$(CC) $(ASMFLAGS) $(INC_PATHS) -c -o $@ $< + @$(CC) $(ASMFLAGS) $(INC_PATHS) -c -o $@ $< # Link $(BUILD)/$(OUTPUT_FILENAME)-nosd.out: $(BUILD) $(OBJECTS) @echo LD $(OUTPUT_FILENAME)-nosd.out - $(QUIET)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -lm -o $@ + $(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -lm -o $@ size: $(BUILD)/$(OUTPUT_FILENAME)-nosd.out -@echo '' diff --git a/src/boards.c b/src/boards.c index 55c285a..85199ce 100644 --- a/src/boards.c +++ b/src/boards.c @@ -384,9 +384,9 @@ void neopixel_write (uint8_t *pixels) 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 From 95cbe3b1298f482e87c4778aabe948c7fc371751 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 10 Jan 2019 15:55:03 +0700 Subject: [PATCH 2/9] fix PWM psel[1] is not reset to 0xffffffff when teardown also move neopixel to pwm1 --- src/boards.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/boards.c b/src/boards.c index 85199ce..d66a558 100644 --- a/src/boards.c +++ b/src/boards.c @@ -132,6 +132,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; @@ -301,6 +304,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 @@ -310,7 +314,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 @@ -353,7 +357,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 @@ -376,8 +380,7 @@ 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); From 04f05dac64a4cf4ee490dd808f52e99235e45b55 Mon Sep 17 00:00:00 2001 From: Song Luan Date: Thu, 10 Jan 2019 13:00:31 +0000 Subject: [PATCH 3/9] Fix OTA using nRF toolbox on iPhone (tested on SE and XS) --- .../libraries/bootloader_dfu/dfu_transport_ble.c | 16 ++++++++++++++++ src/sdk_config.h | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c index 665193e..5d6e0e7 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c @@ -885,6 +885,22 @@ 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: + { +// ble_gap_phys_t* req_phy = &evt->evt.gap_evt.params.phy_update_request.peer_preferred_phys; + + // 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_GAP_EVT_PHY_UPDATE: + { +// ble_gap_evt_phy_update_t* active_phy = &evt->evt.gap_evt.params.phy_update; + } + 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); diff --git a/src/sdk_config.h b/src/sdk_config.h index d6780ac..80c39ba 100644 --- a/src/sdk_config.h +++ b/src/sdk_config.h @@ -64,7 +64,7 @@ #define HCI_MEM_POOL_ENABLED 1 #define HCI_TX_BUF_SIZE 600 #define HCI_RX_BUF_SIZE 600 -#define HCI_RX_BUF_QUEUE_SIZE 4 +#define HCI_RX_BUF_QUEUE_SIZE 8 //========================================================== // UART_ENABLED - nrf_drv_uart - UART/UARTE peripheral driver From 3611a0579e10248ba9ae407af186d6abd30035fe Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 11 Jan 2019 11:36:42 +0700 Subject: [PATCH 4/9] minor clean up for pca10059 --- src/boards/pca10059.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/boards/pca10059.h b/src/boards/pca10059.h index cfa3cb3..30c2998 100644 --- a/src/boards/pca10059.h +++ b/src/boards/pca10059.h @@ -37,6 +37,8 @@ #ifndef PCA10059_H #define PCA10059_H +#define _PINNUM(port, pin) ((port)*32 + (pin)) + /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ @@ -50,8 +52,8 @@ *------------------------------------------------------------------*/ #define BUTTONS_NUMBER 2 -#define BUTTON_1 (1 << 5 | 6) -#define BUTTON_2 (1 << 5 | 10) +#define BUTTON_1 _PINNUM(1, 6) +#define BUTTON_2 _PINNUM(1, 10) #define BUTTON_PULL NRF_GPIO_PIN_PULLUP /*------------------------------------------------------------------*/ From 2f1eec711872465f7b9335c97314eda0967dd4ce Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 14 Jan 2019 12:50:20 +0700 Subject: [PATCH 5/9] fix #41 use RXD,TXD in board header --- Makefile | 11 +++++--- src/boards/feather_nrf52832.h | 32 +++++++++++----------- src/boards/feather_nrf52840_express.h | 38 +++++++++++++-------------- src/boards/pca10056.h | 28 ++++++++++---------- src/sdk_config.h | 12 +++++---- 5 files changed, 63 insertions(+), 58 deletions(-) diff --git a/Makefile b/Makefile index b952016..a5859c0 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -335,6 +336,8 @@ $(info CFLAGS $(CFLAGS)) $(info ) $(info LDFLAGS $(LDFLAGS)) $(info ) +$(info ASMFLAGS $(ASMFLAGS)) +$(info ) endif .phony: all clean size flash sd erase @@ -438,12 +441,12 @@ $(BUILD)/%.o: %.c # Assemble files $(BUILD)/%.o: %.S @echo AS $(notdir $<) - @$(CC) $(ASMFLAGS) $(INC_PATHS) -c -o $@ $< + $(QUIET)$(CC) $(ASMFLAGS) $(INC_PATHS) -c -o $@ $< # Link $(BUILD)/$(OUTPUT_FILENAME)-nosd.out: $(BUILD) $(OBJECTS) @echo LD $(OUTPUT_FILENAME)-nosd.out - $(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -lm -o $@ + $(QUIET)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -lm -o $@ size: $(BUILD)/$(OUTPUT_FILENAME)-nosd.out -@echo '' diff --git a/src/boards/feather_nrf52832.h b/src/boards/feather_nrf52832.h index 99cd55f..be4671a 100644 --- a/src/boards/feather_nrf52832.h +++ b/src/boards/feather_nrf52832.h @@ -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 diff --git a/src/boards/feather_nrf52840_express.h b/src/boards/feather_nrf52840_express.h index 05ecfc7..3206046 100644 --- a/src/boards/feather_nrf52840_express.h +++ b/src/boards/feather_nrf52840_express.h @@ -42,35 +42,35 @@ /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN _PINNUM(1, 15) -#define LED_SECONDARY_PIN _PINNUM(1, 10) -#define LED_NEOPIXEL 16 -#define BOARD_RGB_BRIGHTNESS 0x040404 -#define LED_STATE_ON 1 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN _PINNUM(1, 15) +#define LED_SECONDARY_PIN _PINNUM(1, 10) +#define LED_NEOPIXEL 16 +#define BOARD_RGB_BRIGHTNESS 0x040404 +#define LED_STATE_ON 1 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(0, 15) -#define BUTTON_2 _PINNUM(0, 19) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTONS_NUMBER 2 +#define BUTTON_1 _PINNUM(0, 15) +#define BUTTON_2 _PINNUM(0, 19) +#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 nRF52840 Express" +#define DIS_MANUFACTURER "Adafruit Industries" +#define DIS_MODEL "Bluefruit Feather nRF52840 Express" -#define PRODUCT_NAME "Adafruit Feather nRF52840 Express" -#define VOLUME_LABEL "FTHR840BOOT" +#define PRODUCT_NAME "Adafruit Feather nRF52840 Express" +#define VOLUME_LABEL "FTHR840BOOT" #endif // _FEATHER52840_H diff --git a/src/boards/pca10056.h b/src/boards/pca10056.h index c49ba36..f09cd2a 100644 --- a/src/boards/pca10056.h +++ b/src/boards/pca10056.h @@ -40,30 +40,30 @@ /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 13 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 13 #define LED_SECONDARY_PIN 14 -#define LED_STATE_ON 0 +#define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 11 -#define BUTTON_2 12 -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTONS_NUMBER 2 +#define BUTTON_1 11 +#define BUTTON_2 12 +#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 "Nordic" -#define DIS_MODEL "PCA10056" +#define DIS_MANUFACTURER "Nordic" +#define DIS_MODEL "PCA10056" #endif // PCA10056_H diff --git a/src/sdk_config.h b/src/sdk_config.h index d6780ac..62cd86f 100644 --- a/src/sdk_config.h +++ b/src/sdk_config.h @@ -43,17 +43,19 @@ #ifndef SDK_CONFIG_H #define SDK_CONFIG_H +#include "boards.h" + //========================================================== // HCI_SLIP_ENABLED - hci_slip - SLIP protocol implementation used by HCI //========================================================== #define HCI_SLIP_ENABLED 1 #define HCI_UART_BAUDRATE UART_BAUDRATE_BAUDRATE_Baud115200 -#define HCI_UART_FLOW_CONTROL 0 -#define HCI_UART_RX_PIN 8 -#define HCI_UART_TX_PIN 6 -#define HCI_UART_RTS_PIN 5 -#define HCI_UART_CTS_PIN 7 +#define HCI_UART_FLOW_CONTROL HWFC +#define HCI_UART_RX_PIN RX_PIN_NUMBER +#define HCI_UART_TX_PIN TX_PIN_NUMBER +#define HCI_UART_CTS_PIN CTS_PIN_NUMBER +#define HCI_UART_RTS_PIN RTS_PIN_NUMBER #define HCI_TRANSPORT_ENABLED 1 #define HCI_MAX_PACKET_SIZE_IN_BITS 8000 From 7279bd9b321e287fe7113c8ba89dd53c799584c3 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 31 Jan 2019 18:01:41 +0700 Subject: [PATCH 6/9] added metro nrf52840 revA clean up makefile --- Makefile | 1 + src/boards.c | 1 - src/boards.h | 38 +++++--------- src/boards/metro_nrf52840_express.h | 77 +++++++++++++++++++++++++++++ src/boards/particle_argon.h | 18 +++---- src/usb/usb.c | 2 + 6 files changed, 101 insertions(+), 36 deletions(-) create mode 100644 src/boards/metro_nrf52840_express.h diff --git a/Makefile b/Makefile index a5859c0..4523b39 100644 --- a/Makefile +++ b/Makefile @@ -265,6 +265,7 @@ 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='"boards/$(BOARD).h"' ifneq ($(IS_52832),) CFLAGS += -DNRF52 diff --git a/src/boards.c b/src/boards.c index d66a558..bd1f2ae 100644 --- a/src/boards.c +++ b/src/boards.c @@ -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); } diff --git a/src/boards.h b/src/boards.h index 68b236c..6f434e8 100644 --- a/src/boards.h +++ b/src/boards.h @@ -17,23 +17,7 @@ #include #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 @@ -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); diff --git a/src/boards/metro_nrf52840_express.h b/src/boards/metro_nrf52840_express.h new file mode 100644 index 0000000..10d7745 --- /dev/null +++ b/src/boards/metro_nrf52840_express.h @@ -0,0 +1,77 @@ +/**************************************************************************/ +/*! + @file metro_nrf52840_express.h + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2019, Adafruit Industries (adafruit.com) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#ifndef _METRO_NRF52840_EXPRESS_H_ +#define _METRO_NRF52840_EXPRESS_H_ + +#define _PINNUM(port, pin) ((port)*32 + (pin)) + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN _PINNUM(1, 13) +#define LED_SECONDARY_PIN _PINNUM(1, 15) +#define LED_NEOPIXEL _PINNUM(0, 13) +#define BOARD_RGB_BRIGHTNESS 0x040404 +#define LED_STATE_ON 1 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTONS_NUMBER 2 +#define BUTTON_1 _PINNUM(1, 0) +#define BUTTON_2 _PINNUM(2, 2) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +/*------------------------------------------------------------------*/ +/* UART + *------------------------------------------------------------------*/ +#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 Metro nRF52840 Express" + +#define PRODUCT_NAME "Adafruit Metro nRF52840 Express" +#define VOLUME_LABEL "METR840BOOT" + + +#endif /* _METRO_NRF52840_EXPRESS_H_ */ diff --git a/src/boards/particle_argon.h b/src/boards/particle_argon.h index 95bf3d1..7c3bd09 100644 --- a/src/boards/particle_argon.h +++ b/src/boards/particle_argon.h @@ -42,21 +42,21 @@ /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ - #define LEDS_NUMBER 1 - #define LED_PRIMARY_PIN _PINNUM(1, 12) - #define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN _PINNUM(1, 12) +#define LED_STATE_ON 1 - #define LED_RGB_RED_PIN _PINNUM(0, 13) - #define LED_RGB_GREEN_PIN _PINNUM(0, 14) - #define LED_RGB_BLUE_PIN _PINNUM(0, 15) - #define BOARD_RGB_BRIGHTNESS 0x202020 +#define LED_RGB_RED_PIN _PINNUM(0, 13) +#define LED_RGB_GREEN_PIN _PINNUM(0, 14) +#define LED_RGB_BLUE_PIN _PINNUM(0, 15) +#define BOARD_RGB_BRIGHTNESS 0x202020 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ #define BUTTONS_NUMBER 2 -#define BUTTON_DFU _PINNUM(0, 11) -#define BUTTON_FRESET _PINNUM(0, 03) // A0 +#define BUTTON_DFU _PINNUM(0, 11) +#define BUTTON_FRESET _PINNUM(0, 03) // A0 #define BUTTON_PULL NRF_GPIO_PIN_PULLUP /*------------------------------------------------------------------*/ diff --git a/src/usb/usb.c b/src/usb/usb.c index aaebdf4..2ba83e4 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -79,6 +79,8 @@ void usb_init(bool cdc_only) _inited = true; + NVIC_SetPriority(USBD_IRQn, 2); + // USB power may already be ready at this time -> no event generated // We need to invoke the handler based on the status initially uint32_t usb_reg; From 3737d4bc12dace0ec653b491204331690ea8f0d0 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 31 Jan 2019 21:39:02 +0700 Subject: [PATCH 7/9] update segger project, cleanup --- Makefile | 3 ++- .../libraries/bootloader_dfu/dfu_types.h | 10 +-------- .../Adafruit_nRF52_Bootloader.emProject | 21 ++++++++++++------- src/segger/nRF52840_xxAA_MemoryMap.xml | 3 +-- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 4523b39..eeec375 100644 --- a/Makefile +++ b/Makefile @@ -204,6 +204,7 @@ endif IPATH += $(SRC_PATH) IPATH += $(SRC_PATH)/cmsis/include IPATH += $(SRC_PATH)/usb +IPATH += $(SRC_PATH)/boards IPATH += $(TUSB_PATH) # nrfx @@ -265,7 +266,7 @@ 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='"boards/$(BOARD).h"' +CFLAGS += -DBOARD_HEADER_FILE='"$(BOARD).h"' ifneq ($(IS_52832),) CFLAGS += -DNRF52 diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h b/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h index 40bd414..617b8ee 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h @@ -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. */ diff --git a/src/segger/Adafruit_nRF52_Bootloader.emProject b/src/segger/Adafruit_nRF52_Bootloader.emProject index b3d4adc..6caf020 100644 --- a/src/segger/Adafruit_nRF52_Bootloader.emProject +++ b/src/segger/Adafruit_nRF52_Bootloader.emProject @@ -18,10 +18,12 @@ arm_target_debug_interface_type="ADIv5" arm_target_device_name="nRF52840_xxAA" arm_target_interface_type="SWD" + build_treat_warnings_as_errors="Yes" c_preprocessor_definitions="__nRF_FAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;NO_VTOR_CONFIG;MK_BOOTLOADER_VERSION=0x06010000;CONFIG_GPIO_AS_PINRESET;BLE_STACK_SUPPORT_REQD;SWI_DISABLE0;SOFTDEVICE_PRESENT;FLOAT_ABI_HARD;CFG_TUSB_DEBUG=2;UF2_VERSION="Segger"" - c_user_include_directories="../;../usb;../cmsis/include;$(tusbDir);$(nrfxDir);$(nrfxDir)/mdk;$(nrfxDir)/hal;$(nrfxDir)/drivers/include;$(sdDir)/include;$(sdDir)/include/nrf52;$(sdk11Dir)/drivers_nrf/pstorage;$(sdk11Dir)/ble/common/;$(sdk11Dir)/ble/ble_services/ble_dfu;$(sdk11Dir)/ble/ble_services/ble_dis;$(sdk11Dir)/libraries/bootloader_dfu;$(sdk11Dir)/libraries/bootloader_dfu/hci_transport;$(sdk11Dir)/libraries/util;$(sdkDir)/toolchain/cmsis/include;$(sdkDir)/device;$(sdkDir)/toolchain;$(sdkDir)/drivers_nrf/hal;$(sdkDir)/drivers_nrf/systick;$(sdkDir)/drivers_nrf/uart;$(sdkDir)/drivers_nrf/usbd;$(sdkDir)/drivers_nrf/common;$(sdkDir)/drivers_nrf/delay;$(sdkDir)/drivers_nrf/power;$(sdkDir)/drivers_nrf/clock;$(sdkDir)/libraries/util;$(sdkDir)/libraries/timer;$(sdkDir)/libraries/scheduler;$(sdkDir)/libraries/crc16;$(sdkDir)/libraries/util;$(sdkDir)/libraries/hci/config;$(sdkDir)/libraries/uart;$(sdkDir)/libraries/hci;$(sdkDir)/external/fprintf;$(sdkDir)/libraries/strerror;$(sdkDir)/libraries/atomic;$(sdkDir)/libraries/balloc;$(sdkDir)/libraries/experimental_log/src;$(sdkDir)/libraries/experimental_log;$(sdkDir)/libraries/experimental_section_vars;$(sdkDir)/libraries/experimental_memobj" + c_user_include_directories="../;../usb;../boards;../cmsis/include;$(tusbDir);$(nrfxDir);$(nrfxDir)/mdk;$(nrfxDir)/hal;$(nrfxDir)/drivers/include;$(sdDir)/include;$(sdDir)/include/nrf52;$(sdk11Dir)/drivers_nrf/pstorage;$(sdk11Dir)/ble/common/;$(sdk11Dir)/ble/ble_services/ble_dfu;$(sdk11Dir)/ble/ble_services/ble_dis;$(sdk11Dir)/libraries/bootloader_dfu;$(sdk11Dir)/libraries/bootloader_dfu/hci_transport;$(sdk11Dir)/libraries/util;$(sdkDir)/toolchain/cmsis/include;$(sdkDir)/device;$(sdkDir)/toolchain;$(sdkDir)/drivers_nrf/hal;$(sdkDir)/drivers_nrf/systick;$(sdkDir)/drivers_nrf/uart;$(sdkDir)/drivers_nrf/usbd;$(sdkDir)/drivers_nrf/common;$(sdkDir)/drivers_nrf/delay;$(sdkDir)/drivers_nrf/power;$(sdkDir)/drivers_nrf/clock;$(sdkDir)/libraries/util;$(sdkDir)/libraries/timer;$(sdkDir)/libraries/scheduler;$(sdkDir)/libraries/crc16;$(sdkDir)/libraries/util;$(sdkDir)/libraries/hci/config;$(sdkDir)/libraries/uart;$(sdkDir)/libraries/hci;$(sdkDir)/external/fprintf;$(sdkDir)/libraries/strerror;$(sdkDir)/libraries/atomic;$(sdkDir)/libraries/balloc;$(sdkDir)/libraries/experimental_log/src;$(sdkDir)/libraries/experimental_log;$(sdkDir)/libraries/experimental_section_vars;$(sdkDir)/libraries/experimental_memobj" debug_register_definition_file="$(ProjectDir)/nrf52840_Registers.xml" debug_target_connection="J-Link" + gcc_enable_all_warnings="No" gcc_entry_point="Reset_Handler" linker_memory_map_file="$(ProjectDir)/nRF52840_xxAA_MemoryMap.xml" linker_section_placement_file="$(ProjectDir)/flash_placement.xml" @@ -327,6 +329,7 @@ + + @@ -370,16 +374,19 @@ + - + + diff --git a/src/segger/nRF52840_xxAA_MemoryMap.xml b/src/segger/nRF52840_xxAA_MemoryMap.xml index 74814a4..c37570c 100644 --- a/src/segger/nRF52840_xxAA_MemoryMap.xml +++ b/src/segger/nRF52840_xxAA_MemoryMap.xml @@ -1,7 +1,6 @@ - - + From 981a6976e20e764201c1a8e16a7c5a76d275ec4c Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 31 Jan 2019 22:50:42 +0700 Subject: [PATCH 8/9] change HCI_RX_BUF_QUEUE_SIZE back to 4 --- .../libraries/bootloader_dfu/dfu_transport_ble.c | 8 -------- src/sdk_config.h | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c index 5d6e0e7..711cb78 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c @@ -887,20 +887,12 @@ static void on_ble_evt(ble_evt_t * p_ble_evt) case BLE_GAP_EVT_PHY_UPDATE_REQUEST: { -// ble_gap_phys_t* req_phy = &evt->evt.gap_evt.params.phy_update_request.peer_preferred_phys; - // 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_GAP_EVT_PHY_UPDATE: - { -// ble_gap_evt_phy_update_t* active_phy = &evt->evt.gap_evt.params.phy_update; - } - 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); diff --git a/src/sdk_config.h b/src/sdk_config.h index e66730e..62cd86f 100644 --- a/src/sdk_config.h +++ b/src/sdk_config.h @@ -66,7 +66,7 @@ #define HCI_MEM_POOL_ENABLED 1 #define HCI_TX_BUF_SIZE 600 #define HCI_RX_BUF_SIZE 600 -#define HCI_RX_BUF_QUEUE_SIZE 8 +#define HCI_RX_BUF_QUEUE_SIZE 4 //========================================================== // UART_ENABLED - nrf_drv_uart - UART/UARTE peripheral driver From 641d9fe811c6465f1c2539487300be955509341f Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 31 Jan 2019 22:51:12 +0700 Subject: [PATCH 9/9] added changelog --- changelog.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 changelog.md diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..5a6af1d --- /dev/null +++ b/changelog.md @@ -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 +