NRF52833 BUTTONLESS DFU Problem

Hello,

I am working on developing a special "serial recovery" mode dfu function of nrf52833 with ncs SDK V2.3.0.
Now I encount a problem when adding the following code in my personal project for buttonless DFU, but it cannot stay in bootloader. Can anyone help me?

uint8_t val = nrf_power_gpregret_get(NRF_POWER);

printk("Old GPREGRET val: %u\n", val);

nrf_power_gpregret_set(NRF_POWER, 0xb1);

k_sleep(K_MSEC(1000));

NVIC_SystemReset();


I also try debugging and found the modem will reboot and jump to the "if" condition as follow:(/ncs/v2.6.0/bootloader/mcuboot/boot/zephyr/main.c   line:), then check the IF statement fails, then jump to the end and enter application.

if (detect_pin() &&
!boot_skip_serial_recovery()) {
#ifdef CONFIG_MCUBOOT_INDICATION_LED
gpio_pin_set_dt(&led0, 1);
#endif

mcuboot_status_change(MCUBOOT_STATUS_SERIAL_DFU_ENTERED);

BOOT_LOG_INF("Enter the serial recovery mode");
rc = boot_console_init();
__ASSERT(rc == 0, "Error initializing boot console.\n");
boot_serial_start(&boot_funcs);
__ASSERT(0, "Bootloader serial process was terminated unexpectedly.\n");
}
#endif

but I didn't find any infomation about gpregret, could you please tell me how to enter boot serial start process?

best regard!
Ben

Parents
  • Hi,

    The bootloader in SDK v2.3.0 does not implement support for this entrance mechanism. I.e. it does not read the GPREGRET register on startup. Support for this was added by this commit: https://github.com/nrfconnect/sdk-mcuboot/commit/b3e3ce39f3e1abd95ff4010263b3613edf59dd54

    The easiest solution is to either upgrade to a newer SDK version, or modify your bootloader/mcuboot/boot/zephyr/main.c file.

    Best regards,

    Vidar

  • Hi, Vidar

    Thanks for your answer!

    I just replace the two files in bootloader folder("bootloader/mcuboot/boot/zephyr") by the files you added, BUT It build error as follow when I replaced. Should I need add any other config parameter in "mcuboot.conf" ?

    ncs/v2.3.0/bootloader/mcuboot/boot/zephyr/main.c:477:17: warning: implicit declaration of function 'FIH_DECLARE'; did you mean 'Z_ISR_DECLARE'? [-Wimplicit-function-declaration]
    477 | FIH_DECLARE(fih_rc, FIH_FAILURE);
    | ^~~~~~~~~~~
    | Z_ISR_DECLARE
    ncs/v2.3.0/bootloader/mcuboot/boot/zephyr/main.c:477:17: error: 'fih_rc' undeclared (first use in this function); did you mean 'fih_eq'?
    477 | FIH_DECLARE(fih_rc, FIH_FAILURE);
    | ^~~~~~
    | fih_eq

    I would be grateful if you could give me any hints!

    Best Regards!

    Ben

  • Hi Ben,

    The files I linked to are on a newer version which includes several other changes which are not trivial to backport to your current version. 

    If you want to stay on SDK version 2.3.0, I recommend you add this mechanism yourself by adding a function that reads the GPREGRET register and returns 'true' if the DFU flag has been set. 

    if (<gpregret flag is set> && 
        !boot_skip_serial_recovery()) {
            ifdef CONFIG_MCUBOOT_INDICATION_LED
            gpio_pin_set_dt(&led0, 1);
    #endif
    
            mcuboot_status_change(MCUBOOT_STATUS_SERIAL_DFU_ENTERED);
    
            BOOT_LOG_INF("Enter the serial recovery mode");
            ...

    Best regards,

    Vidar

Reply
  • Hi Ben,

    The files I linked to are on a newer version which includes several other changes which are not trivial to backport to your current version. 

    If you want to stay on SDK version 2.3.0, I recommend you add this mechanism yourself by adding a function that reads the GPREGRET register and returns 'true' if the DFU flag has been set. 

    if (<gpregret flag is set> && 
        !boot_skip_serial_recovery()) {
            ifdef CONFIG_MCUBOOT_INDICATION_LED
            gpio_pin_set_dt(&led0, 1);
    #endif
    
            mcuboot_status_change(MCUBOOT_STATUS_SERIAL_DFU_ENTERED);
    
            BOOT_LOG_INF("Enter the serial recovery mode");
            ...

    Best regards,

    Vidar

Children
Related