nrf5340 how to forcefully enter into DFU mode if a buggy APP is loaded via DFU ?

How can we forcefully enter into DFU mode in NRF5340 if for example the newly loaded application due to a bug is unable to advertise BLE?
In another words, if I press reset button, I want the device to be in DFU mode for at least 10 seconds so that I can recover the  device in case if the application crashes.

At present the DFU bootloader is a standalone bootloader with BLE capability or is jt just a switcher which jumps to the application downloaded new image partition?

  • Hi Vinod, 
    I understand your concern. Unfortunately that's the situation we have now. 

    You may consider setting a special mode in your application that does exactly what you want with the DFU failsafe mode. It will boot up and do nothing but advertise and wait for DFU connection. After 15 seconds it would start doing the normal routine to read eeprom and other normal function. 

    This way you can do some intensive test on the application to make sure it will manage to do the DFU basic task and avoid accessing any other function/peripheral. 
    I agree that this is still not as robust as having a separate application (bootloader) , but other than that and the serial recovery mode, I don't find any better solution. 

  • Yes,

       I was also thinking about the same idea to not initialize any other task for 15 to 20 seconds other than the BLE task. Then no matter what ever happens, if that initial part of code logic is not changed, it should technically work at least for the first 20 seconds on a button reset.

    Anyways thanks for your comments and suggestion. 

  • Hello Hung,

      I have one more question regarding this,

    I am now keeping the BLE task  as the first code in my main.

    After that I will wait for a semaphore for 20 seconds, if mobile app is connected and started the SMP firmware download, then I will get semaphore before 20 seconds and if semaphore timeout, then I will continue my application code below that.

    But how can I know if the BLE connection is really for DFU or normal app connection?

    Means if someone press the DFU button in nrfconnect app and select the zip, can I get a callback in my application regarding that ? If so then I can release a semaphore to the indicate that DFU started. Then I can keep a very high delay before entering into application code assuming that the DFU itselft will reset the MCU before that happens.

  • Hi Vinod, 


    No, I don't think nRFConnect would send any Ping. 


    But if you use nRF Device Manager  you can send an Echo command. You can use that to tell your application that it's entering DFU mode. I assume that you will write your own app to do DFU ? 

    Another option is to make your own characteristic that handles the "enter DFU - don't do anything else" command. 

  • Another approach can be to go inside the attribute modified callback of the SMP characteristics to see if any communication or sync word exchange is happening, if so then that triggers an OTA. What do you say?

Related