From e3449cd77146e4b5ef00e5aba299afffcd090c8c Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 29 Nov 2019 01:02:05 +0700 Subject: [PATCH] able to build with 52833 --- Makefile | 20 +++++++++------- lib/sdk/components/libraries/hci/hci_slip.c | 24 ++++++++++++------- .../drivers_nrf/pstorage/pstorage_raw.c | 8 +++---- .../libraries/bootloader_dfu/bootloader.c | 13 +++++----- .../bootloader_dfu/bootloader_settings.c | 4 ++-- .../libraries/bootloader_dfu/dfu_types.h | 8 +++---- src/dfu_init.c | 2 +- src/main.c | 11 +++++---- 8 files changed, 49 insertions(+), 41 deletions(-) diff --git a/Makefile b/Makefile index bc27130..da92efe 100644 --- a/Makefile +++ b/Makefile @@ -90,17 +90,19 @@ BUILD = _build-$(BOARD) # MCU_SUB_VARIANT can be nrf52 (nrf52832), nrf52833, nrf52840 ifeq ($(MCU_SUB_VARIANT),nrf52) - SD_NAME = s132 - DFU_DEV_REV = 0xADAF - MCU_FLAGS = -DNRF52 -DNRF52832_XXAA -DS132 + SD_NAME = s132 + DFU_DEV_REV = 0xADAF + MCU_FLAGS = -DNRF52 -DNRF52832_XXAA -DS132 else ifeq ($(MCU_SUB_VARIANT),nrf52833) - SD_NAME = s140 - DFU_DEV_REV = 52840 - MCU_FLAGS = -DNRF52833_XXAA -DS140 + SD_NAME = s140 + DFU_DEV_REV = 52840 + MCU_FLAGS = -DNRF52833_XXAA -DS140 +else ifeq ($(MCU_SUB_VARIANT),nrf52840) + SD_NAME = s140 + DFU_DEV_REV = 52840 + MCU_FLAGS = -DNRF52840_XXAA -DS140 else - SD_NAME = s140 - DFU_DEV_REV = 52840 - MCU_FLAGS = -DNRF52840_XXAA -DS140 + $(error Sub Variant $(MCU_SUB_VARIANT) is unknown) endif #****************************************************************************** diff --git a/lib/sdk/components/libraries/hci/hci_slip.c b/lib/sdk/components/libraries/hci/hci_slip.c index fb11f59..f7673f6 100644 --- a/lib/sdk/components/libraries/hci/hci_slip.c +++ b/lib/sdk/components/libraries/hci/hci_slip.c @@ -44,7 +44,8 @@ #include "app_uart.h" #include "nrf_error.h" -#ifdef NRF52840_XXAA +// nRF has native usb peripheral +#ifdef NRF_USBD #include "tusb.h" #endif @@ -121,13 +122,17 @@ static uint32_t send_tx_byte_end(void); */ uint32_t (*send_tx_byte) (void) = send_tx_byte_default; -#ifdef NRF52840_XXAA - static uint32_t serial_put(char ch) - { - return tud_cdc_write_char(ch) ? NRF_SUCCESS : NRF_ERROR_NO_MEM; - } +#ifdef NRF_USBD + +static uint32_t serial_put(char ch) +{ + return tud_cdc_write_char(ch) ? NRF_SUCCESS : NRF_ERROR_NO_MEM; +} + #else - #define serial_put app_uart_put + +#define serial_put app_uart_put + #endif static uint32_t send_tx_byte_end(void) @@ -345,7 +350,7 @@ static bool rx_buffer_overflowed(void) return false; } -#ifdef NRF52840_XXAA +#ifdef NRF_USBD static uint32_t slip_uart_open(void) { @@ -441,7 +446,8 @@ uint32_t hci_slip_open() uint32_t hci_slip_close() { m_current_state = SLIP_OFF; -#ifdef NRF52840_XXAA + +#ifdef NRF_USBD return NRF_SUCCESS; #else uint32_t err_code = app_uart_close(); diff --git a/lib/sdk11/components/drivers_nrf/pstorage/pstorage_raw.c b/lib/sdk11/components/drivers_nrf/pstorage/pstorage_raw.c index 12748f5..f9404fe 100644 --- a/lib/sdk11/components/drivers_nrf/pstorage/pstorage_raw.c +++ b/lib/sdk11/components/drivers_nrf/pstorage/pstorage_raw.c @@ -40,11 +40,11 @@ #define INVALID_OPCODE 0x00 /**< Invalid op code identifier. */ #ifdef NRF51 -#define SOC_MAX_WRITE_SIZE 1024 /**< Maximum write size allowed for a single call to \ref sd_flash_write as specified in the SoC API on the nRF51. */ -#elif defined(NRF52832_XXAA) || defined(NRF52840_XXAA) -#define SOC_MAX_WRITE_SIZE 4096 /**< Maximum write size allowed for a single call to \ref sd_flash_write as specified in the SoC API on the nRF52. */ + #define SOC_MAX_WRITE_SIZE 1024 /**< Maximum write size allowed for a single call to \ref sd_flash_write as specified in the SoC API on the nRF51. */ +#elif defined(NRF52_SERIES) + #define SOC_MAX_WRITE_SIZE 4096 /**< Maximum write size allowed for a single call to \ref sd_flash_write as specified in the SoC API on the nRF52. */ #else -#error No target defined + #error No target defined #endif diff --git a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c index 1245622..2ad777f 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c @@ -32,7 +32,7 @@ #include "boards.h" -#ifdef NRF52840_XXAA +#ifdef NRF_USBD #include "tusb.h" #endif @@ -40,11 +40,11 @@ #define IRQ_ENABLED 0x01 /**< Field identifying if an interrupt is enabled. */ -/**< Maximum number of interrupts available. */ +/**< Maximum number of interrupts available. (from IRQn_Type) */ #if defined(NRF52832_XXAA) -#define MAX_NUMBER_INTERRUPTS 39 -#elif defined(NRF52840_XXAA) -#define MAX_NUMBER_INTERRUPTS 48 + #define MAX_NUMBER_INTERRUPTS 39 +#elif defined(NRF52840_XXAA) || defined(NRF52833_XXAA) + #define MAX_NUMBER_INTERRUPTS 48 #endif /**@brief Enumeration for specifying current bootloader status. @@ -127,9 +127,8 @@ static void wait_for_events(void) // Event received. Process it from the scheduler. app_sched_execute(); -#ifdef NRF52840_XXAA +#ifdef NRF_USBD // skip if usb is not inited ( e.g OTA / finializing sd/bootloader ) - extern bool usb_inited(void); if ( tusb_inited() ) { tud_task(); diff --git a/lib/sdk11/components/libraries/bootloader_dfu/bootloader_settings.c b/lib/sdk11/components/libraries/bootloader_dfu/bootloader_settings.c index 608fdd5..439d7a0 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/bootloader_settings.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/bootloader_settings.c @@ -31,7 +31,7 @@ __root const uint32_t m_uicr_bootloader_start_address @ NRF_UICR_BOOT_START_A #endif -#if defined(NRF52832_XXAA) || defined(NRF52840_XXAA) +#if defined(NRF52_SERIES) #if defined ( __CC_ARM ) uint8_t m_mbr_params_page[CODE_PAGE_SIZE] __attribute__((at(BOOTLOADER_MBR_PARAMS_PAGE_ADDRESS))) __attribute__((used)); /**< This variable reserves a codepage for mbr parameters, to ensure the compiler doesn't locate any code or variables at his location. */ @@ -50,7 +50,7 @@ __no_init uint8_t m_mbr_params_page[CODE_PAGE_SIZE] @ BOOTLOADER_MBR_PARAMS_ __root const uint32_t m_uicr_mbr_params_page_address @ NRF_UICR_MBR_PARAMS_PAGE_ADDRESS = BOOTLOADER_MBR_PARAMS_PAGE_ADDRESS; /**< This variable ensures that the linker script will write the bootloader start address to the UICR register. This value will be written in the HEX file and thus written to UICR when the bootloader is flashed into the chip. */ #endif -#endif // defined(NRF52832_XXAA) || defined(NRF52840_XXAA) +#endif // NRF52_SERIES void bootloader_util_settings_get(const bootloader_settings_t ** pp_bootloader_settings) diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h b/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h index 617b8ee..2ed7ba4 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h @@ -30,22 +30,20 @@ #include "app_util.h" #define NRF_UICR_BOOT_START_ADDRESS (NRF_UICR_BASE + 0x14) /**< Register where the bootloader start address is stored in the UICR register. */ - -#if defined(NRF52832_XXAA) || defined(NRF52840_XXAA) #define NRF_UICR_MBR_PARAMS_PAGE_ADDRESS (NRF_UICR_BASE + 0x18) /**< Register where the mbr params page is stored in the UICR register. (Only in use in nRF52 MBR).*/ -#endif #define CODE_REGION_1_START SD_SIZE_GET(MBR_SIZE) /**< This field should correspond to the size of Code Region 0, (which is identical to Start of Code Region 1), found in UICR.CLEN0 register. This value is used for compile safety, as the linker will fail if application expands into bootloader. Runtime, the bootloader will use the value found in UICR.CLEN0. */ #define SOFTDEVICE_REGION_START MBR_SIZE /**< 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 CODE_PAGE_SIZE 0x1000 /**< Size of a flash codepage. Used for size of the reserved flash space in the bootloader region. Will be runtime checked against NRF_UICR->CODEPAGESIZE to ensure the region is correct. */ - -#if defined(NRF52832_XXAA) +// Flash = 512 KB +#if defined(NRF52832_XXAA) || defined(NRF52833_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. */ +// Flash = 1024 KB #elif defined(NRF52840_XXAA) #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. */ diff --git a/src/dfu_init.c b/src/dfu_init.c index 3ca0dd4..f68c5e6 100644 --- a/src/dfu_init.c +++ b/src/dfu_init.c @@ -83,7 +83,7 @@ */ #define ADAFRUIT_DEVICE_TYPE 0x0052 -#ifdef NRF52840_XXAA +#if defined(NRF52840_XXAA) || defined(NRF52833_XXAA) #define ADAFRUIT_DEV_REV 52840 #elif defined NRF52832_XXAA #define ADAFRUIT_DEV_REV 0xADAF diff --git a/src/main.c b/src/main.c index fcc7831..5a74640 100644 --- a/src/main.c +++ b/src/main.c @@ -68,7 +68,7 @@ #include "nrfx_nvmc.h" -#ifdef NRF52840_XXAA +#ifdef NRF_USBD #include "nrf_usbd.h" #include "tusb.h" @@ -120,9 +120,12 @@ enum { BLE_CONN_CFG_HIGH_BANDWIDTH = 1 }; #define APPDATA_ADDR_START (BOOTLOADER_REGION_START-DFU_APP_DATA_RESERVED) #ifdef NRF52840_XXAA -STATIC_ASSERT( APPDATA_ADDR_START == 0xED000); + // Flash 1024 KB + STATIC_ASSERT( APPDATA_ADDR_START == 0xED000); + #else -STATIC_ASSERT( APPDATA_ADDR_START == 0x6D000); + // Flash 512 KB + STATIC_ASSERT( APPDATA_ADDR_START == 0x6D000); #endif @@ -423,7 +426,7 @@ uint32_t proc_soc(void) { pstorage_sys_event_handler(soc_evt); -#ifdef NRF52840_XXAA +#ifdef NRF_USBD extern void tusb_hal_nrf_power_event(uint32_t event); /*------------- usb power event handler -------------*/ int32_t usbevt = (soc_evt == NRF_EVT_POWER_USB_DETECTED ) ? NRFX_POWER_USB_EVT_DETECTED: