From be87aac09d5d9b3ff96c986486cf00e99467757f Mon Sep 17 00:00:00 2001 From: Yihui Xiong Date: Mon, 3 Feb 2020 03:08:59 +0000 Subject: [PATCH] step to no softdevice --- .../components/libraries/util/app_util_platform.c | 2 -- .../components/libraries/util/app_util_platform.h | 2 -- .../components/libraries/bootloader_dfu/bootloader.c | 12 +++++++++--- .../components/libraries/bootloader_dfu/dfu_types.h | 5 ++++- src/main.c | 3 ++- src/usb/uf2/uf2.h | 2 -- src/usb/uf2/uf2cfg.h | 5 +++++ src/usb/usb.c | 3 +++ 8 files changed, 23 insertions(+), 11 deletions(-) diff --git a/lib/sdk/components/libraries/util/app_util_platform.c b/lib/sdk/components/libraries/util/app_util_platform.c index bbe5856..ef8d831 100644 --- a/lib/sdk/components/libraries/util/app_util_platform.c +++ b/lib/sdk/components/libraries/util/app_util_platform.c @@ -39,10 +39,8 @@ */ #include "app_util_platform.h" -#ifdef SOFTDEVICE_PRESENT /* Global nvic state instance, required by nrf_nvic.h */ nrf_nvic_state_t nrf_nvic_state; -#endif static uint32_t m_in_critical_region = 0; diff --git a/lib/sdk/components/libraries/util/app_util_platform.h b/lib/sdk/components/libraries/util/app_util_platform.h index 61db926..195f9dd 100644 --- a/lib/sdk/components/libraries/util/app_util_platform.h +++ b/lib/sdk/components/libraries/util/app_util_platform.h @@ -52,10 +52,8 @@ #include #include "compiler_abstraction.h" #include "nrf.h" -#ifdef SOFTDEVICE_PRESENT #include "nrf_soc.h" #include "nrf_nvic.h" -#endif #include "nrf_assert.h" #include "app_error.h" diff --git a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c index 2ad777f..b177aa6 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c @@ -169,7 +169,7 @@ bool bootloader_app_is_valid(uint32_t app_addr) // A stored crc value of 0 indicates that CRC checking is not used. if (p_bootloader_settings->bank_0_crc != 0) { - image_crc = crc16_compute((uint8_t *)DFU_BANK_0_REGION_START, + image_crc = crc16_compute((uint8_t *)app_addr, p_bootloader_settings->bank_0_size, NULL); } @@ -375,9 +375,11 @@ static void interrupts_disable(void) void bootloader_app_start(uint32_t app_addr) { +#ifdef SOFTDEVICE_PRESENT // If the applications CRC has been checked and passed, the magic number will be written and we // can start the application safely. APP_ERROR_CHECK ( sd_softdevice_disable() ); +#endif interrupts_disable(); @@ -391,9 +393,13 @@ void bootloader_app_start(uint32_t app_addr) sd_mbr_command(&command); #endif - APP_ERROR_CHECK( sd_softdevice_vector_table_base_set(CODE_REGION_1_START) ); +#ifdef SOFTDEVICE_PRESENT + APP_ERROR_CHECK( sd_softdevice_vector_table_base_set(app_addr) ); +#else + SCB->VTOR = app_addr; +#endif - bootloader_util_app_start(CODE_REGION_1_START); + bootloader_util_app_start(app_addr); } diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h b/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h index 2ed7ba4..9cc7727 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h @@ -29,10 +29,13 @@ #include "nrf.h" #include "app_util.h" +#define SD_MAGIC_NUMBER 0x51b1e5db +#define SD_MAGIC_OK() (*((uint32_t*)(SOFTDEVICE_INFO_STRUCT_ADDRESS+4)) == 0x51b1e5db) + #define NRF_UICR_BOOT_START_ADDRESS (NRF_UICR_BASE + 0x14) /**< Register where the bootloader start address is stored in the UICR register. */ #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).*/ -#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 CODE_REGION_1_START (SD_MAGIC_OK() ? SD_SIZE_GET(MBR_SIZE) : 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. */ diff --git a/src/main.c b/src/main.c index 5a74640..f134c8a 100644 --- a/src/main.c +++ b/src/main.c @@ -258,9 +258,10 @@ int main(void) // Jump to application if valid if (bootloader_app_is_valid(DFU_BANK_0_REGION_START) && !bootloader_dfu_sd_in_progress()) { +#ifdef SOFTDEVICE_PRESENT // MBR must be init before start application if ( !sd_inited ) softdev_mbr_init(); - +#endif // Select a bank region to use as application region. // @note: Only applications running from DFU_BANK_0_REGION_START is supported. bootloader_app_start(DFU_BANK_0_REGION_START); diff --git a/src/usb/uf2/uf2.h b/src/usb/uf2/uf2.h index 6edbb4f..788b99b 100644 --- a/src/usb/uf2/uf2.h +++ b/src/usb/uf2/uf2.h @@ -39,8 +39,6 @@ SOFTWARE. #include "dfu_types.h" -#define SD_MAGIC_NUMBER 0x51b1e5db -#define SD_MAGIC_OK() (*((uint32_t*)(SOFTDEVICE_INFO_STRUCT_ADDRESS+4)) == 0x51b1e5db) extern bool sdRunning; // All entries are little endian. diff --git a/src/usb/uf2/uf2cfg.h b/src/usb/uf2/uf2cfg.h index a100f44..55fb588 100644 --- a/src/usb/uf2/uf2cfg.h +++ b/src/usb/uf2/uf2cfg.h @@ -9,7 +9,12 @@ #define FLASH_SIZE (USER_FLASH_END-USER_FLASH_START) // Max flash size // Only allow to write application TODO dynamic depending on SD size +#ifdef SOFTDEVICE_PRESENT #define USER_FLASH_START 0x26000 +#else +#define USER_FLASH_START 0x1000 +#endif + #define USER_FLASH_END 0xAD000 // Fat Fs start here #define FLASH_PAGE_SIZE 4096 diff --git a/src/usb/usb.c b/src/usb/usb.c index 0115072..ab6b39d 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -109,11 +109,14 @@ void usb_teardown(void) NRF_USBD->INTENCLR = NRF_USBD->INTEN; nrf_usbd_disable(NRF_USBD); + +#if defined(SOFTDEVICE_PRESENT) sd_clock_hfclk_release(); sd_power_usbdetected_enable(false); sd_power_usbpwrrdy_enable(false); sd_power_usbremoved_enable(false); +#endif } }