/**@brief Function for bootloader main entry. */ int main(void) { uint32_t err_code; bool dfu_start = false; bool app_reset = (NRF_POWER->GPREGRET == BOOTLOADER_DFU_START); // This check ensures that the defined fields in the bootloader corresponds with actual // setting in the nRF51 chip. APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START); APP_ERROR_CHECK_BOOL(NRF_FICR->CODEPAGESIZE == CODE_PAGE_SIZE); // Initialize. timers_init(); gpiote_init(); buttons_init(); bootloader_init(); // Check if we reset in the middle of a firmware update if (bootloader_dfu_sd_in_progress()) { err_code = bootloader_dfu_sd_update_continue(); APP_ERROR_CHECK(err_code); softdevice_init(!app_reset); scheduler_init(); err_code = bootloader_dfu_sd_update_finalize(); APP_ERROR_CHECK(err_code); } else { // If stack is present then continue initialization of bootloader. softdevice_init(!app_reset); scheduler_init(); } // Check if the Bootloader Control pin is low. If so, enter the bootloader // mode. dfu_start = (nrf_gpio_pin_read(BOOTLOADER_CTRL_PIN) == 0); // If the Bootloader Control pin is low or the application in the flash // is not valid, enter the bootloader mode. if (dfu_start || (!bootloader_app_is_valid(DFU_BANK_0_REGION_START))) { err_code = sd_power_gpregret_clr(POWER_GPREGRET_GPREGRET_Msk); APP_ERROR_CHECK(err_code); // Initiate an update of the firmware. err_code = bootloader_dfu_start(); APP_ERROR_CHECK(err_code); } // If the application was or now is valid, run it if (bootloader_app_is_valid(DFU_BANK_0_REGION_START)) { // 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); } NVIC_SystemReset(); }
/**@brief Function for application main entry. */ int main(void) { uint32_t err_code; bool bootloader_is_pushed = false; leds_init(); // This check ensures that the defined fields in the bootloader corresponds with actual // setting in the nRF51 chip. APP_ERROR_CHECK_BOOL(NRF_UICR->CLENR0 == CODE_REGION_1_START); APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START); APP_ERROR_CHECK_BOOL(NRF_FICR->CODEPAGESIZE == CODE_PAGE_SIZE); // Initialize. timers_init(); gpiote_init(); buttons_init(); ble_stack_init(); scheduler_init(); bootloader_is_pushed = ((nrf_gpio_pin_read(BOOTLOADER_BUTTON_PIN) == 0)? true: false); if (bootloader_is_pushed || (!bootloader_app_is_valid(DFU_BANK_0_REGION_START))) { nrf_gpio_pin_set(LED_2); // Initiate an update of the firmware. err_code = bootloader_dfu_start(); APP_ERROR_CHECK(err_code); nrf_gpio_pin_clear(LED_2); } if (bootloader_app_is_valid(DFU_BANK_0_REGION_START)) { leds_off(); // 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); } nrf_gpio_pin_clear(LED_0); nrf_gpio_pin_clear(LED_1); nrf_gpio_pin_clear(LED_2); nrf_gpio_pin_clear(LED_7); NVIC_SystemReset(); }
/**@brief Function for application main entry. */ int main(void) { uint32_t err_code; bool bootloader_is_pushed = false; static uint32_t TestAdr; TestAdr = (uint32_t)*(&(BluetoothDFU)); if(TestAdr == 100) { bootloader_is_pushed = true; F_flash_page_erase(&BluetoothDFU); ble_flash_word_write(&BluetoothDFU , 0); } // This check ensures that the defined fields in the bootloader corresponds with actual // setting in the nRF51 chip. APP_ERROR_CHECK_BOOL(NRF_UICR->CLENR0 == CODE_REGION_1_START); APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START); APP_ERROR_CHECK_BOOL(NRF_FICR->CODEPAGESIZE == CODE_PAGE_SIZE); // Initialize. timers_init(); gpiote_init(); buttons_init(); ble_stack_init(); scheduler_init(); //bootloader_is_pushed = ((nrf_gpio_pin_read(BOOTLOADER_BUTTON_PIN) == 0)? true: false); if (bootloader_is_pushed || (!bootloader_app_is_valid(DFU_BANK_0_REGION_START))) { // Initiate an update of the firmware. err_code = bootloader_dfu_start(); APP_ERROR_CHECK(err_code); } if (bootloader_app_is_valid(DFU_BANK_0_REGION_START)) { // 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); } NVIC_SystemReset(); }
int main() { simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, 0); xprintf("\n\n\n\n\n\r\n region2 start..\r\n"); if(region1_is_valid()) { xprintf("dump to region11111\r\n"); bootloader_app_start(); } system_app_pages_erase(CODE_REGION_1_START, CODE_REGION_1_SIZE); xprintf(" app area has eased..\r\n"); ble_start(); for( ; ;) { ble_rec_handle(); if(get_dfu_state() == SYSTEM_UPDATE_END) { xprintf("system update end.\r\n"); sd_softdevice_disable(); flash_specword_write((uint32_t*)BOOTLOADER_SETTINGS_ADDRESS, SYSTEM_APP_VALID_OFFSET, SYSTEM_APP_VALID); NVIC_SystemReset(); } if(get_dfu_state() == SYSTEM_UPDATE_FAILURE) { xprintf("system update failed.\r\n"); NVIC_SystemReset(); } } }
/**@brief Function for bootloader main entry. */ int main(void) { uint32_t err_code; bool dfu_start = false; bool app_reset = (NRF_POWER->GPREGRET == BOOTLOADER_DFU_START); leds_init(); // This check ensures that the defined fields in the bootloader corresponds with actual // setting in the nRF51 chip. APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START); APP_ERROR_CHECK_BOOL(NRF_FICR->CODEPAGESIZE == CODE_PAGE_SIZE); // Initialize. timers_init(); gpiote_init(); buttons_init(); (void)bootloader_init(); if (bootloader_dfu_sd_in_progress()) { err_code = bootloader_dfu_sd_update_continue(); APP_ERROR_CHECK(err_code); ble_stack_init(!app_reset); scheduler_init(); err_code = bootloader_dfu_sd_update_finalize(); APP_ERROR_CHECK(err_code); } else { // If stack is present then continue initialization of bootloader. ble_stack_init(!app_reset); scheduler_init(); } dfu_start = app_reset; // dfu_start |= ((nrf_gpio_pin_read(BOOTLOADER_BUTTON_PIN) == 0) ? true: false); if (dfu_start || (!bootloader_app_is_valid(DFU_BANK_0_REGION_START))) { err_code = sd_power_gpregret_clr(POWER_GPREGRET_GPREGRET_Msk); APP_ERROR_CHECK(err_code); nrf_gpio_pin_set(LED_0); // Initiate an update of the firmware. err_code = bootloader_dfu_start(); APP_ERROR_CHECK(err_code); nrf_gpio_pin_clear(LED_0); } if (bootloader_app_is_valid(DFU_BANK_0_REGION_START)) { leds_off(); // 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); } nrf_gpio_pin_clear(LED_0); nrf_gpio_pin_clear(LED_1); NVIC_SystemReset(); }
/**@brief Function for bootloader main entry. */ int main(void) { uint32_t err_code; bool dfu_start = false; bool app_reset = (NRF_POWER->GPREGRET == BOOTLOADER_DFU_START); if (app_reset) { NRF_POWER->GPREGRET = 0; } leds_init(); // This check ensures that the defined fields in the bootloader corresponds with actual // setting in the chip. APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START); APP_ERROR_CHECK_BOOL(NRF_FICR->CODEPAGESIZE == CODE_PAGE_SIZE); // Initialize. timers_init(); buttons_init(); (void)bootloader_init(); if (bootloader_dfu_sd_in_progress()) { nrf_gpio_pin_write(UPDATE_IN_PROGRESS_LED, UPDATE_IN_PROGRESS_LED_ONSTATE); err_code = bootloader_dfu_sd_update_continue(); APP_ERROR_CHECK(err_code); ble_stack_init(!app_reset); scheduler_init(); err_code = bootloader_dfu_sd_update_finalize(); APP_ERROR_CHECK(err_code); nrf_gpio_pin_write(UPDATE_IN_PROGRESS_LED, !UPDATE_IN_PROGRESS_LED_ONSTATE); } else { // If stack is present then continue initialization of bootloader. ble_stack_init(!app_reset); scheduler_init(); } dfu_start = app_reset; dfu_start |= ((nrf_gpio_pin_read(BOOTLOADER_BUTTON) == BOOTLOADER_BUTTON_ONSTATE) ? true: false); // If button is held down for 3 seconds, don't start bootloader. // This means that we go straight to Espruino, where the button is still // pressed and can be used to stop execution of the sent code. if (dfu_start) { nrf_gpio_pin_write(BOOTLOADER_BUTTON_PRESS_LED, BOOTLOADER_BUTTON_PRESS_LED_ONSTATE); int count = 3000; while (nrf_gpio_pin_read(BOOTLOADER_BUTTON) == BOOTLOADER_BUTTON_ONSTATE && count) { nrf_delay_us(999); count--; } if (!count) dfu_start = false; nrf_gpio_pin_write(BOOTLOADER_BUTTON_PRESS_LED, !BOOTLOADER_BUTTON_PRESS_LED_ONSTATE); } if (dfu_start || (!bootloader_app_is_valid(DFU_BANK_0_REGION_START))) { nrf_gpio_pin_write(UPDATE_IN_PROGRESS_LED, UPDATE_IN_PROGRESS_LED_ONSTATE); // Initiate an update of the firmware. err_code = bootloader_dfu_start(); APP_ERROR_CHECK(err_code); nrf_gpio_pin_write(UPDATE_IN_PROGRESS_LED, !UPDATE_IN_PROGRESS_LED_ONSTATE); } if (bootloader_app_is_valid(DFU_BANK_0_REGION_START) && !bootloader_dfu_sd_in_progress()) { // 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); } NVIC_SystemReset(); }
/* * Function for bootloader main entry. */ int main(void) { uint32_t err_code; bool dfu_start = false; bool app_reset = (NRF_POWER->GPREGRET == BOOTLOADER_DFU_START); if (app_reset) { NRF_POWER->GPREGRET = 0; } leds_init(); #if defined(DBGLOG_SUPPORT) uart_init(); #endif PUTS("\nBootloader *** " __DATE__ " " __TIME__ " ***"); // This check ensures that the defined fields in the bootloader // corresponds with actual setting in the nRF51 chip. APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START); APP_ERROR_CHECK_BOOL(NRF_FICR->CODEPAGESIZE == CODE_PAGE_SIZE); // Initialize. timers_init(); #if defined(BUTTON_SUPPORT) buttons_init(); #endif (void)bootloader_init(); if (bootloader_dfu_sd_in_progress()) { nrf_gpio_pin_clear(UPDATE_IN_PROGRESS_LED); err_code = bootloader_dfu_sd_update_continue(); APP_ERROR_CHECK(err_code); ble_stack_init(!app_reset); scheduler_init(); err_code = bootloader_dfu_sd_update_finalize(); APP_ERROR_CHECK(err_code); nrf_gpio_pin_set(UPDATE_IN_PROGRESS_LED); } else { // If stack is present then continue initialization of bootloader. ble_stack_init(!app_reset); scheduler_init(); dis_init(); } dfu_start = app_reset; #if defined(BUTTON_SUPPORT) dfu_start |= ((nrf_gpio_pin_read(BOOTLOADER_BUTTON) == 0) ? true: false); #endif if (dfu_start || (!bootloader_app_is_valid(DFU_BANK_0_REGION_START))) { nrf_gpio_pin_clear(UPDATE_IN_PROGRESS_LED); PUTS("Start DFU"); // Initiate an update of the firmware. err_code = bootloader_dfu_start(); APP_ERROR_CHECK(err_code); nrf_gpio_pin_set(UPDATE_IN_PROGRESS_LED); } if (bootloader_app_is_valid(DFU_BANK_0_REGION_START) && !bootloader_dfu_sd_in_progress()) { PUTS("Start App"); // 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); } NVIC_SystemReset(); }
/**@brief Function for bootloader main entry. */ int main(void) { uint32_t err_code; bool dfu_start = (NRF_POWER->GPREGRET == BOOTLOADER_DFU_START); bool power_on = (NRF_POWER->GPREGRET == 0x000000); if (dfu_start || power_on) { NRF_POWER->GPREGRET = BOOTLOADER_APP_START; } // leds_init(); // This check ensures that the defined fields in the bootloader corresponds with actual // setting in the chip. APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START); APP_ERROR_CHECK_BOOL(NRF_FICR->CODEPAGESIZE == CODE_PAGE_SIZE); // Initialize. timers_init(); // buttons_init(); (void)bootloader_init(); if (bootloader_dfu_sd_in_progress()) { // nrf_gpio_pin_clear(UPDATE_IN_PROGRESS_LED); err_code = bootloader_dfu_sd_update_continue(); APP_ERROR_CHECK(err_code); ble_stack_init(!dfu_start); scheduler_init(); err_code = bootloader_dfu_sd_update_finalize(); APP_ERROR_CHECK(err_code); // nrf_gpio_pin_set(UPDATE_IN_PROGRESS_LED); } else { // If stack is present then continue initialization of bootloader. ble_stack_init(!dfu_start); scheduler_init(); } // dfu_start |= ((nrf_gpio_pin_read(BOOTLOADER_BUTTON) == 0) ? true: false); if (power_on || dfu_start || (!bootloader_app_is_valid(DFU_BANK_0_REGION_START))) { // nrf_gpio_pin_clear(UPDATE_IN_PROGRESS_LED); // Initiate an update of the firmware. err_code = bootloader_dfu_start(power_on); APP_ERROR_CHECK(err_code); // nrf_gpio_pin_set(UPDATE_IN_PROGRESS_LED); } else if (bootloader_app_is_valid(DFU_BANK_0_REGION_START) && !bootloader_dfu_sd_in_progress()) { // 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); } NVIC_SystemReset(); }