From f42bea8d8fc902af8d5b6c5cf9eb9bcb1edf5039 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 29 Jun 2017 14:36:17 +0700 Subject: [PATCH] move bootloader retrieval to common init() --- boards.txt | 1 - cores/nRF5/main.cpp | 1 - cores/nRF5/wiring.c | 14 ++++++++++++++ cores/nRF5/wiring.h | 5 +++++ .../examples/Hardware/hwinfo/hwinfo.ino | 2 +- variants/feather52/variant.cpp | 13 ------------- variants/feather52/variant.h | 5 ----- 7 files changed, 20 insertions(+), 21 deletions(-) diff --git a/boards.txt b/boards.txt index e28f5cc8..86080db0 100644 --- a/boards.txt +++ b/boards.txt @@ -70,7 +70,6 @@ metro52.build.board=METRO52 metro52.build.core=nRF5 metro52.build.variant=metro52 - # Debug Menu metro52.menu.debug.l0=Level 0 (Release) metro52.menu.debug.l0.build.debug_flags=-DCFG_DEBUG=0 diff --git a/cores/nRF5/main.cpp b/cores/nRF5/main.cpp index af2276f9..57f2b15a 100644 --- a/cores/nRF5/main.cpp +++ b/cores/nRF5/main.cpp @@ -64,7 +64,6 @@ static void loop_task(void* arg) int main( void ) { init(); - initVariant(); if (setLoopStacksize) diff --git a/cores/nRF5/wiring.c b/cores/nRF5/wiring.c index bb3187f5..0da57c46 100644 --- a/cores/nRF5/wiring.c +++ b/cores/nRF5/wiring.c @@ -28,6 +28,10 @@ extern "C" { #define BOOTLOADER_DFU_SERIAL_MAGIC 0x4e #define BOOTLOADER_DFU_OTA_FULLRESET_MAGIC 0xA8 +// Must match temp register in bootloader +#define BOOTLOADER_VERSION_REGISTER NRF_TIMER2->CC[0] +uint32_t bootloaderVersion = 0; + void init( void ) { #if defined( USE_LFXO ) @@ -41,6 +45,16 @@ void init( void ) #endif NRF_CLOCK->TASKS_LFCLKSTART = 1UL; + + // Retrieve bootloader version + bootloaderVersion = BOOTLOADER_VERSION_REGISTER; + + // RTC1 could be enabled by bootloader. Disable it + NVIC_DisableIRQ(RTC1_IRQn); + NRF_RTC1->EVTENCLR = RTC_EVTEN_COMPARE0_Msk; + NRF_RTC1->INTENCLR = RTC_INTENSET_COMPARE0_Msk; + NRF_RTC1->TASKS_STOP = 1; + NRF_RTC1->TASKS_CLEAR = 1; } void enterSerialDfu(void) diff --git a/cores/nRF5/wiring.h b/cores/nRF5/wiring.h index 0e6a467a..6eaf6588 100644 --- a/cores/nRF5/wiring.h +++ b/cores/nRF5/wiring.h @@ -27,6 +27,11 @@ extern void init(void); extern void enterSerialDfu(void); extern void enterOTADfu(void); +/* Bootloader version. Assigned by init(). + * - value of 0x000500 is version 0.5.0 + */ +extern uint32_t bootloaderVersion; + // Hint instruction to tell CPU go to low power mode #if 0 #define waitForEvent() __WFE() diff --git a/libraries/Bluefruit52Lib/examples/Hardware/hwinfo/hwinfo.ino b/libraries/Bluefruit52Lib/examples/Hardware/hwinfo/hwinfo.ino index 575bbbf7..dde89def 100644 --- a/libraries/Bluefruit52Lib/examples/Hardware/hwinfo/hwinfo.ino +++ b/libraries/Bluefruit52Lib/examples/Hardware/hwinfo/hwinfo.ino @@ -11,7 +11,7 @@ typedef volatile uint32_t REG32; void setup() { Serial.begin(115200); - Serial.println("Bluefruit Feather 52 HW Info"); + Serial.println("Bluefruit 52 HW Info"); Serial.println(""); // MAC Address diff --git a/variants/feather52/variant.cpp b/variants/feather52/variant.cpp index 7f4ea3d9..2e1865c3 100644 --- a/variants/feather52/variant.cpp +++ b/variants/feather52/variant.cpp @@ -68,21 +68,8 @@ const uint32_t g_ADigitalPinMap[] = { }; -// Must match temp register in bootloader -#define BOOTLOADER_VERSION_REGISTER NRF_TIMER2->CC[0] -uint32_t bootloaderVersion = 0; - void initVariant() { - bootloaderVersion = BOOTLOADER_VERSION_REGISTER; - - // RTC1 is already configured by bootloader. Disable it here - NVIC_DisableIRQ(RTC1_IRQn); - NRF_RTC1->EVTENCLR = RTC_EVTEN_COMPARE0_Msk; - NRF_RTC1->INTENCLR = RTC_INTENSET_COMPARE0_Msk; - NRF_RTC1->TASKS_STOP = 1; - NRF_RTC1->TASKS_CLEAR = 1; - // LED1 & LED2 pinMode(PIN_LED1, OUTPUT); ledOff(PIN_LED1); diff --git a/variants/feather52/variant.h b/variants/feather52/variant.h index 2bf6d576..d7e0dde0 100644 --- a/variants/feather52/variant.h +++ b/variants/feather52/variant.h @@ -116,11 +116,6 @@ static const uint8_t SCK = PIN_SPI_SCK ; #define PIN_WIRE_SDA (25u) #define PIN_WIRE_SCL (26u) -/* Bootloader version, may move to other file. Assigned by - * initVariant() upon running. - * - value of 0x000500 is version 0.5.0 - */ -extern uint32_t bootloaderVersion; static inline bool isPinValid(uint32_t pin) {