Fix bug during initialization of DFU Mode
@@ -67,7 +67,7 @@ static bool dfu_mode_state_machine(uint8_t rhport, tusb_control_request_t const
//--------------------------------------------------------------------+
void dfu_mode_init(void)
{
- _dfu_state_ctx.state = DFU_IDLE;
+ _dfu_state_ctx.state = APP_DETACH; // After init, reset will occur. We want to be in APP_DETACH to move to DFU_IDLE
_dfu_state_ctx.status = DFU_STATUS_OK;
_dfu_state_ctx.attrs = tud_dfu_mode_init_attrs_cb();
_dfu_state_ctx.blk_transfer_in_proc = false;
@@ -79,6 +79,10 @@ void dfu_mode_init(void)
void dfu_mode_reset(uint8_t rhport)
{
+ if (_dfu_state_ctx.state == APP_DETACH)
+ {
+ _dfu_state_ctx.state = DFU_IDLE;
+ } else {
if ( tud_dfu_mode_usb_reset_cb )
{
tud_dfu_mode_usb_reset_cb(rhport, &_dfu_state_ctx.state);
@@ -106,6 +110,7 @@ void dfu_mode_reset(uint8_t rhport)
break;
}
}
+ }
if(_dfu_state_ctx.state == APP_IDLE)
{
