This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

DFU branch Bootloader when TWI is busy

Hi,

I have a application where the TWI is always reading a sensor in the main task.

When the DFU requiere to reset, frequently the TWI is busy and the current frame is broken !

When the application restart after the flash update, TWI can't read the sensor, the sensor is never responding !

What is the solution to wait the end of the TWI frame, before restart the MCU ? The difficulty is that the DFU request is in IRQ, and the TWI is in main thread !

Regards,

Parents
  • Hello,

    I suggest that you use the DFU request to set a flag. This way, you can check this flag in the main thread, to see whether it has been requested. If it has, then you can shut down the TWI gracefully before doing the DFU reset.

     

    Short, but hopefully explaining pseudo code:

    DFU_interrupt(void)
    {
        DFU_reset_requested = true;
    }
    
    main()
    {
        ...
        while(1)
        {
            ...
            if(DFU_reset_requested)
            {
                prepare_DFU();
                reset();
            }
            idle_state_handle(); //or whatever the wait function is called in the project
        }
    }

     

    Best regards,

    Edvin

Reply
  • Hello,

    I suggest that you use the DFU request to set a flag. This way, you can check this flag in the main thread, to see whether it has been requested. If it has, then you can shut down the TWI gracefully before doing the DFU reset.

     

    Short, but hopefully explaining pseudo code:

    DFU_interrupt(void)
    {
        DFU_reset_requested = true;
    }
    
    main()
    {
        ...
        while(1)
        {
            ...
            if(DFU_reset_requested)
            {
                prepare_DFU();
                reset();
            }
            idle_state_handle(); //or whatever the wait function is called in the project
        }
    }

     

    Best regards,

    Edvin

Children
Related