Hi,
using a stock nRF52840 dongle and willing to enter bootloader (same as pushing the relevant button on the dongle) from app. How can that be done, using stock bootloader?
Regards,
Andrea
Hi,
using a stock nRF52840 dongle and willing to enter bootloader (same as pushing the relevant button on the dongle) from app. How can that be done, using stock bootloader?
Regards,
Andrea
HI Andrea
in the dfu_enter_check() function, which is called by nrf_bootloader_init(), the bootloader checks if one of the NRF_BL_DFU_ENTER_METHOD_xxxx has been used to trigger the device to stay in bootloader mode and not start the application( if there is a valid one).
static bool dfu_enter_check(void) { if (!app_is_valid(crc_on_valid_app_required())) { NRF_LOG_DEBUG("DFU mode because app is not valid."); return true; } if (NRF_BL_DFU_ENTER_METHOD_BUTTON && (nrf_gpio_pin_read(NRF_BL_DFU_ENTER_METHOD_BUTTON_PIN) == 0)) { NRF_LOG_DEBUG("DFU mode requested via button."); return true; } if (NRF_BL_DFU_ENTER_METHOD_PINRESET && (NRF_POWER->RESETREAS & POWER_RESETREAS_RESETPIN_Msk)) { NRF_LOG_DEBUG("DFU mode requested via pin-reset."); return true; } if (NRF_BL_DFU_ENTER_METHOD_GPREGRET && (nrf_power_gpregret_get() & BOOTLOADER_DFU_START)) { NRF_LOG_DEBUG("DFU mode requested via GPREGRET."); return true; } if (NRF_BL_DFU_ENTER_METHOD_BUTTONLESS && (s_dfu_settings.enter_buttonless_dfu == 1)) { NRF_LOG_DEBUG("DFU mode requested via bootloader settings."); return true; } return false; }
The method used in our buttonless DFU application example is the NRF_BL_DFU_ENTER_METHOD_GPREGRET, see the ble_dfu_buttonless_bootloader_start_finalize() function below.
uint32_t ble_dfu_buttonless_bootloader_start_finalize(void) { uint32_t err_code; NRF_LOG_DEBUG("In ble_dfu_buttonless_bootloader_start_finalize\r\n"); err_code = sd_power_gpregret_clr(0, 0xffffffff); VERIFY_SUCCESS(err_code); err_code = sd_power_gpregret_set(0, BOOTLOADER_DFU_START); VERIFY_SUCCESS(err_code); // Indicate that the Secure DFU bootloader will be entered m_dfu.evt_handler(BLE_DFU_EVT_BOOTLOADER_ENTER); // Signal that DFU mode is to be enter to the power management module nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_DFU); return NRF_SUCCESS; }
Hi,
thanks for the clarification, but my question is not yet answered. When I use a factory new (stock) dongle, bought on Mouser, what code should I use to enter bootloader from the APP?
The code above seems not to work. Could it be the bootloader which is flashed from factory does not have NRF_BL_DFU_ENTER_METHOD_GPREGRET enabled?
Regards,
Andrea
The bootloader that is factory programmed should be more or less use the same configuration as the SDK bootloader. I will have to take a look at the source code that was used to generate the bootloader hex that is programmed at the factory.
Hi Bjorn,
thanks! Best would be if you could confirm your APP code puts a factory dongle in bootloader mode... then I need to figure out what problem I have here...
Takk,
Andrea
Hi Andrea,
it turns out that you were correct, the bootloader used on the nRF52840 dongle does not have the NRF_BL_DFU_ENTER_METHOD_GPREGRET. It only enables NRF_BL_DFU_ENTER_METHOD_PINRESET and NRF_BL_DFU_ENTER_METHOD_BUTTON_PIN.
I knew that we are able to switch from application to bootloader without manually pressing the button on the nRF52840 when programming it with nRF Connect: Programmer. So I took a look at the schematic file(attached) of the nRF52840 dongle and saw that several GPIOs were connected directly to the RESET pin, which is how nRF Connect is able to switch from app to bootloader. We have a dedicated USB library for this, called the DFU Trigger Library (USB).
So I do not know how you want to trigger the nRF52840 to go to bootloader moder, but in essence you only have to pull on of the GPIOs connected to the RESET pin low, i.e.
#define BSP_SELF_PINRESET_PIN NRF_GPIO_PIN_MAP(0,19) // Call the following functions at the start of main() nrf_gpio_cfg_output(BSP_SELF_PINRESET_PIN); nrf_gpio_pin_set(BSP_SELF_PINRESET_PIN); // Call the following function when you want to switch to BL mode. nrf_gpio_pin_clear(BSP_SELF_PINRESET_PIN);
I have verified this on a nRF52840 Dongle with the factory bootloader.