cancel
Showing results for 
Search instead for 
Did you mean: 

STM32Cube USB Device Library dual DFU

ivandevel
Associate II
Posted on November 06, 2014 at 09:07

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...

1 REPLY 1
tsuneo
Senior
Posted on November 07, 2014 at 17:58

> I've modified usbd_conf.h:

USBD_DFU_MAX_ITF_NUM appends additional alternate interface to the DFU interface.

But this technique has been kept unimplemented so far, including STM32Cube.

- there isn’t any code which binds the alternate interface to specific memory segment

And then, you should keep USBD_DFU_MAX_ITF_NUM to 1

Instead, ST had provided a DFU example of multi-memory segments in the STM32_USB-Host-Device_Lib_V2.1.0, usbd_dfu_mal.c

http://www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1743/PF257882

STM32_USB-Host-Device_Lib_V2.1.0\Libraries\STM32_USB_Device_Library\Class\dfu\src\usbd_dfu_mal.c

usbd_dfu_mal.c introduces a wrapper memory object, which binds two memory segments.

Target memory segment is identified by the address to be handled.

I believe you may easily drag in this technique (ie. usbd_dfu_mal.c) into the Cube code.

Try it 😉

Tsuneo