AnsweredAssumed Answered

USB DFU Host class

Question asked by Francisco Expósito on Sep 18, 2015
Latest reply on Sep 21, 2015 by Francisco Expósito
Hello everybody,

I am developing the firmware for a STM32F4 board which has to be capable of flashing slave STM32F4 boards by means of USB DFU.

Since USB Host library doesn't have support for DFU class I am implementing a custom DFU Host class, but I can't get it working.

I have managed to enumerate successfully the slave device:

USB Device Attached
PID: df11h
VID: 483h
Address (#1) assigned.
Manufacturer : STMicroelectronics
Product : STM32  BOOTLOADER
Serial Number : 346139623034
Enumeration done.
This device has only 1 configuration.
Default configuration set.
Switching to Interface (#0)
Class    : feh
SubClass : 1h
Protocol : 2h
DFU class started.

The problem comes on the ClassRequest handler. Whenever I issue a DFU_GetStatus request to the device I get one of the following responses:
       
  1. USBH_BUSY
  2.    
  3. USBH_OK and response buffer remains unchanged (bytes set to 0). This response makes no sense since device state is appIDLE (0x00) when it should be dfuIDLE (0x02).

01./**
02.  * @brief  The function is responsible for handling Standard requests for DFU class.
03.  * @param  phost: Host handle
04.  * @retval USBH Status
05.  */
06. 
07.static USBH_StatusTypeDef USBH_DFU_ClassRequest(USBH_HandleTypeDef *phost){  
08. 
09.    USBH_DFU_HandleTypeDef *    handleDFU;
10.    USBH_StatusTypeDef          result; 
11.    DFU_STATUS_RESPONSE         status;
12. 
13.    handleDFU = (USBH_DFU_HandleTypeDef *)phost->pActiveClass->pData;
14. 
15.    result = DFU_Get_Status(phost, &status);
16. 
17.    if ( result == USBH_OK ){
18. 
19.        handleDFU->deviceState  = (DFU_STATE)status.bState;
20.        handleDFU->deviceStatus = (DFU_STATUS)status.bStatus;
21.
22. 
23.        phost->pUser(phost, HOST_USER_CLASS_ACTIVE);
24. 
25.        }
26. 
27.    return result;
28. 
29.}


01./*
02. *  DFU_Get_Status
03. */
04. 
05.static USBH_StatusTypeDef DFU_Get_Status(USBH_HandleTypeDef * phost, DFU_STATUS_RESPONSE * status){
06. 
07.    USBH_DFU_HandleTypeDef *    handleDFU;
08.    DFU_STATUS_RESPONSE_DATA    response;
09.    USBH_StatusTypeDef          result;
10. 
11.    handleDFU = (USBH_DFU_HandleTypeDef * )phost->pActiveClass->pData;
12.     
13.    // Initialize the status data structure
14. 
15.    memset(response.bytes, 0, 8);
16. 
17.    // Prepare request
18. 
19.    phost->Control.setup.b.bmRequestType    = USB_EP_DIR_IN | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE;
20.    phost->Control.setup.b.bRequest         = DFU_GETSTATUS;
21.    phost->Control.setup.b.wIndex.w         = handleDFU->interface;
22.    phost->Control.setup.b.wLength.w        = 6;
23. 
24.    // Send request
25. 
26.    result = USBH_CtlReq(phost, response.bytes, 6);
27. 
28.    // Get result
29.     
30.    if ( result == USBH_OK ){
31.        status->bStatus         = response.info.bStatus;
32.        status->bwPollTimeout   = response.info.bwPollTimeout;
33.        status->bState          = response.info.bState;
34.        status->iString         = response.info.iString;
35.        status->reserved        = 0;
36.        }
37.    else{
38.        status->bStatus         = DFU_STATUS_ERR_UNKNOWN;
39.        status->bwPollTimeout   = 0;
40.        status->bState          = STATE_DFU_ERROR;
41.        status->iString         = 0;
42.        status->reserved        = 0;
43.        }
44. 
45.    return result;
46. 
47.}

Any ideas? 

Maybe the almighty clive1 can shed some light... :)

Thank you very much for your time

Outcomes