I'm having trouble making a single bank dfu mode with 128k NRF51822 chip.
Here's the problem;
- Works fine when everything(SoftDevice, Application, Bootloader) is all uploaded. The Application is launched as expected.
- I used the Nordic Master Control app to upload a new Application to the chip. Upload works fine (using Single Bank DFU boot loader).
- After the upload process finishes, the bootloader should launch the new Application BUT it seems to stop at the bootloader.
- If I remove the battery and put it again, the boot loader launches the application as expected and works fine.
This is the main() function of the boot loader. Did some debugging and I think that 'bootloader_app_start(DFU_BANK_0_REGION_START);' doesn't starts as expected.
It would be really thankful if anyone could tell me what I did wrong. Thanks.
int main(void)
{
uint32_t err_code;
//bool bootloader_is_pushed = false;
bool dfu_start = false;
bool app_reset = (NRF_POWER->GPREGRET == BOOTLOADER_DFU_START);
leds_init();
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(!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)))
{
//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);
//NRF_POWER->GPREGRET = 0xFF;
}
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();
}