AnsweredAssumed Answered

STM32Cube USB Device Library dual DFU

Question asked by Ivan Kuznetsov on Nov 6, 2014
Latest reply on Nov 7, 2014 by Chinzei.Tsuneo
Hello! I want to implement a dual DFU (Internal flash and SPI flash) on new STM32Cube USB Library.

I've modified usbd_conf.h:
/* DFU Class Config */
#define USBD_DFU_MAX_ITF_NUM                   2

I've created a new file usbd_dfu_sflash.c and described there a new device:
#define SFLASH_DESC_STR      "@SPI Flash: M25P64   /0x00000000/128*064Kg"                                                       
                                                              
/* Extern function prototypes ------------------------------------------------*/
uint16_t sFlash_If_Init(void);
uint16_t sFlash_If_Erase(uint32_t Add);
uint16_t sFlash_If_Write(uint8_t *src, uint8_t *dest, uint32_t Len);
uint8_t *sFlash_If_Read(uint8_t *src, uint8_t *dest, uint32_t Len);
uint16_t sFlash_If_DeInit(void);
uint16_t sFlash_If_GetStatus(uint32_t Add, uint8_t Cmd, uint8_t *buffer);
 
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
  #pragma data_alignment=4  
#endif
__ALIGN_BEGIN USBD_DFU_MediaTypeDef USBD_DFU_sFlash_fops __ALIGN_END = {
  (uint8_t*) SFLASH_DESC_STR,
  sFlash_If_Init,
  sFlash_If_DeInit,
  sFlash_If_Erase,
  sFlash_If_Write,
  sFlash_If_Read,
  sFlash_If_GetStatus, 
};


And run in main.c this sequence:
/* Otherwise enters DFU mode to allow user to program his application */
  /* Init Device Library */
  USBD_Init(&hUSBDDevice, &DFU_Desc, 0);
   
  /* Add Supported Class */
  USBD_RegisterClass(&hUSBDDevice, &USBD_DFU);
   
  /* Add DFU Media interface */
  USBD_DFU_RegisterMedia(&hUSBDDevice, &USBD_DFU_Flash_fops);
 
  /* Add DFU Media Serial Flash interface */
  USBD_DFU_RegisterMedia(&hUSBDDevice, &USBD_DFU_sFlash_fops);
   
  /* Start Device Process */
  USBD_Start(&hUSBDDevice);

And now I see in DfuSe Demo only a two lines:
00 SPI Flash:M25P64     128 sectors...
01 SPI Flash:M25P64     128 sectors...

Outcomes