ST AN1603 Application note

AN1603
APPLICATION NOTE
USING THE ST7 USB DEVICE FIRMWARE UPGRADE
DEVELOPMENT KIT (DFU-DK)
by Microcontroller Division Applications
1 INTRODUCTION
This Application Note describes how to use the ST7 USB DFU PC development kit (DFU-DK). It begins with a presentation of the software architecture. It then gives a full description of the DFU-DK programming interface and all the features. Finally, an example is given of a vendor upgrade package developed with the DFU-DK.
The objective of the DFU-DK is to provide you with a simple means of upgrading the firmware of a USB device. It runs under Microsoft Windows and works with any STMicroelectronics USB micr ocontr oller that s upp orts th e DFU c apa bility i nclu ding the ST7 2F62, S T72F 63 an d ST72F65x MCU families.
The DFU-DK can be downloaded from ST’s website.
Related Documentation:
ST7 USB Device Firmware Upgrade Demonstrator User M anual.
AN1603/0203 1/21
1
USING THE ST7 USB DEVICE FIRMWARE UPGRADE DEVELOPMENT KIT (DFU-DK)
1 INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 LIST OF INSTA LL E D FILES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1 DEVELOPMENT MODULES FOR BUILDING YOUR OWN PC SOFTWARE . . 3
2.2 DO CU MENTATION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.3 DFU DRIVER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.4 EXAMPLE VENDOR UPGRADE SOFTWARE FILES . . . . . . . . . . . . . . . . . . . . 3
3 SOFTWARE ARCHITECTURE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4 DFU-DK PRO GRAMMING INTER FACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
4.1 OVER VIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
4.2 DRIVER INSTALLATION FILE (.INF) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
4.3 PROGRAMMING INTERFACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.3.1 STDFU_EnumGETNBDevices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.3.2 STDFU_GetDeviceDescriptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.3.3 STDFU_GetDFUDescriptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.3.4 STDFU_GetStringDescriptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.3.5 STDFU_GetNbOfConfigurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.3.6 STDFU_GetConfigurationDescriptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.3.7 STDFU_GetNbOfInterfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.3.8 STDFU_GetNbOfAlternates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.3.9 STDFU_GetInterfaceDescriptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.3.10S T DFU_O pen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.3.11STDFU_Close . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.3.12STDFU_Detach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.3.13S T DFU_Dn load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.3.14STDFU_UPload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.3.15STDFU_Getstatus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.3.16STDFU_Clrstatus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.3.17STDFU_Getstate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.3.18STDFU_Abort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.3.19S T DFU_Ha ndleDe viceC hange . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5 EXAMPLE VENDOR UPGRADE SOFTWARE (DFU DEMONSTRA TOR) . . . . . . . . 17
5.1 ST7D FUPRT PROGRAMMING INTERFACE . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.1.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.1.2 Programming Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.2 DFU DEMONSTRATOR GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2/21
2
USING THE ST7 USB DEVICE FIR MWARE UPGRADE DEVELOPMENT KIT (DFU-DK)
2 LIST OF INSTALLED FILE S
This section provides a list of all the DFU-DK files referred to in this application note.
2.1 DEVELOPMENT MODULES FOR BUILDING YOUR OWN PC SOFTWARE In the Dev subdirectory, you will find the following items :
– Bin subdirectory
-ST7DFU.dll : interface dll
-STTubeDevice203.dll : driver dll used by the ST7DFU dll – Inc subdirectory
-ST7DFU.h : C header containining all prototypes exported by ST7DFU.dll
-USB100.h : Microsoft header for USB. – Lib subdirectory
-ST7DFU.lib : static lib file
2.2 DOCUMENTATION
In the Doc subdirectory, you will find the following items : – Application note AN1603: this file.
2.3 DFU DRIVER
In the Driver subdirectory, you will find the following items : – STDFU.inf: installation file for the DFU driver that can be customised to meet the require-
ments of your application
– STTub203.sys: STMicroelectronics tube driver used as a DFU class driver
2.4 EXAMPLE VENDOR UPGRADE SOFTWARE FILES
In the Sources subdirectory, you will find the following items : – Binary subdirectory inludes binary modules: debug and release – DFUDEMO subdirectory includes GUI sources – ST7DFUPRT subdirectory includes DFU protocol dll sources
3/21
USING THE ST7 USB DEVICE FIRMWARE UPGRADE DEVELOPMENT KIT (DFU-DK)
(
g
3 SOFTWARE ARCHITECTURE
Figure 1. DFU-DK software layers
STMicro el ectr on i cs
referenc e so ftware
Firmware Im ag e
& suffix
Image.s19
e.dfu
Ima
STMicro el ectr on ics
binary module
ST7DFUPRT.DLL
Protocol DFU Interface
DFU Interface protocol
STTubeDeviceXXX.dll
DFU GUI
ST7DFU.DLL
Status and error reporting
4/21
Tube-Driver for the DFU Class
STTubXXX.SYS
Microsoft USB Driver Stack
USB Bus Interface
User Mode
Kernel Mode
USBD)
Hardwa re
USING THE ST7 USB DEVICE FIR MWARE UPGRADE DEVELOPMENT KIT (DFU-DK)
As shown in Figure 1, we can see that the DFU software is divided into four distinct layers:
– The hardware layer (USB bus interface), – The kernel layer (Microsoft USB stack and STMicroelectronics tube driver)
and a user application layer that is also divided into two other layers: – A generic one that manages all DFU requests and is provided as ready binary modules
(ST7DFU and STTubeDevice203 dynamic link libraries).
– A vendor-specific one that is provided as an example reference software (protocol manage-
ment dynamic link library and a demonstration GUI).
This modula r architec ture was chose n so that the DFU-DK c an be used for any ap plication that needs to implement DFU features. Moreover, this will make it easier to add features any­time in the future and manage changes.
Note: The DFU-DK is compatible with Windows 98, 98SE, Me, 2000 and XP and is compliant with the Device Class specification for DFU version1.0 as detailed by the USB-IF.
5/21
USING THE ST7 USB DEVICE FIRMWARE UPGRADE DEVELOPMENT KIT (DFU-DK)
4 DFU-DK PROGRAMMING INTERFACE
4.1 OVERVIEW
This module is used to allow the application to access the low level USB protocol, such as re­ceiving descriptor information, configuring a device etc, and also for managing all DFU re­quests that are implemented in this module and are not linked to the application layer.
The follow ing table sum mariz e the DF U class-sp ecific requ ests us ed to acco mplish the up­grade operation.
Table 1. DFU Class specific requests
bmRequetType bRequest wValue wIndex wLength Data
00100001b DFU_DETACH wTimeout Interface Zero None 00100001b DFU_DNLOAD wBlockNum Interface Length Firmware 10100001b DFU_UPLOAD wBlockNum Interface Length Firmware 10100001b DFU_GETSTATUS Zero Interface 6 Status 00100001b DFU_CLRSTATUS Zero Interface Zero None 10100001b DFU_GETSTATE Zero Interface 1 State 00100001b DFU_ABORT Zero Interface Zero None
4.2 DRIVER INSTAL LATION FILE (.INF)
Before creating o r customi sing the D FU inf file, you ha ve to obtain two l icence k eys fo r your vendor ID and product IDs, in order to use the DFU driver : One for the product ID of your com­posite device (Functional mode + DFU mode) and one for the only DFU mode device.
In our example we have two distinct keys, one for the PID=0xDF11 (ST M icroelectronics DFU
devices) which is “6f72a98be4e1edad” and another one for a composite device, PID= 0xFF03 (STMicroelectronics EvalKit and DFU) which is “d083fc290a34aa18”.
Once you have your licence keys, you need to make your own inf file. The inf file is a text file used by Windows to install a drive r. The one given in this package c an be customis ed to fit your needs. Anyway, you have to choose your own name for the inf file, and you shouldn’t use the one given in the package.
After a successful driver installation the correct values in this inf file will be entered in the reg­istery.
6/21
USING THE ST7 USB DEVICE FIR MWARE UPGRADE DEVELOPMENT KIT (DFU-DK)
4.3 PROGRAMMING INTERFACE
This is the Application-programming interface of the ST7DFU.dll modu le. The documentation describes the interface in C language.
4.3.1 STDFU_EnumGETNBDevices
4.3.1.1 Prototype
DWORD STDFU_EnumGetNbDevices( PDWORD pNb,
HWND hWnd, DWORD Message);
4.3.1.2 Description
Browses all DFU devices connected to the PC.
4.3.1.3 Parameters
pNb: pointer to the number of DFU devices hWnd :window handle Message: notifies an application of a change to the hardware configuration of a DFU-device.
4.3.1.4 Returned value
STDFU_NOERROR in case of success, otherwise (Error Code)
4.3.1.5 Remarks
For more details about hWnd and Message parameters please refer to Section 4.3.19 The following section provides all error codes that can be returned by any function:
STDFU_ERROR_OFFSET 0x12340000 STDFU_NOERROR STDFU_ERROR_OFFSET STDFU_MEMORY (STDFU_ERROR_OFFSET+1) STDFU_BADPARAMETER (STDFU_ERROR_OFFSET+2) STDFU_NOTIMPLEMENTED (STDFU_ERROR_OFFSET+3) STDFU_ENUMFINISHED (STDFU_ERROR_OFFSET+4)
STDFU_OPENDRIVERERROR (STDFU_ERROR_OFFSET+5) STDFU_ERRORDESCRIPTORBUILDING (STDFU_ERROR_OFFSET+6) STDFU_PIPECREATIONERROR (STDFU_ERROR_OFFSET+7) STDFU_PIPERESETERROR (STDFU_ERROR_OFFSET+8) STDFU_PIPEABORTERROR (STDFU_ERROR_OFFSET+9) STDFU_STRINGDESCRIPTORERROR (STDFU_ERROR_OFFSET+0xA) STDFU_DRIVERISCLOSED (STDFU_ERROR_OFFSET+0xB) STDFU_VENDOR_RQ_PB (STDFU_ERROR_OFFSET+0xC) STDFU_ERRORWHILEREADING (STDFU_ERROR_OFFSET+0xD) STDFU_ERRORBEFOREREADING (STDFU_ERROR_OFFSET+0xE) STDFU_ERRORWHILEWRITING (STDFU_ERROR_OFFSET+0xF)
7/21
Loading...
+ 14 hidden pages