AN3990 Application note



Similar documents
AN3354 Application note

AN3332 Application note

AN3997 Application note

AN2557 Application note

UM0985 User manual. Developing your STM32VLDISCOVERY application using the IAR Embedded Workbench software. Introduction

UM1676 User manual. Getting started with.net Micro Framework on the STM32F429 Discovery kit. Introduction

AN3265 Application note

Getting started with DfuSe USB device firmware upgrade STMicroelectronics extension

AN4108 Application note

UM1790 User manual. Getting started with STM32L053 discovery kit software development tools. Introduction

UM1680 User manual. Getting started with STM32F429 Discovery software development tools. Introduction

UM1727 User manual. Getting started with STM32 Nucleo board software development tools. Introduction

AN3998 Application note

SPC5-FLASHER. Flash management tool for SPC56xx family. Description. Features

AN2824 Application note

EVL185W-LEDTV. 185 W power supply with PFC and standby supply for LED TV based on the L6564, L6599A and Viper27L. Features.

AN2680 Application note

DDSL01. Secondary protection for DSL lines. Features. Description

How To Write To An Eeprom Memory On A Flash Memory On An Iphone Or Ipro Memory On Microsoft Flash Memory (Eeprom) On A Microsoft Microsoft Powerbook (Ai) 2.2.2

2STBN15D100. Low voltage NPN power Darlington transistor. Features. Application. Description

AN2389 Application note

M24LRxx/CR95HF application software installation guide

AN3155 Application note

AN4156 Application note

ST High voltage fast-switching NPN power transistor. Features. Applications. Description

AN3252 Application note

ESDLIN1524BJ. Transil, transient voltage surge suppressor diode for ESD protection. Features. Description SOD323

AN2604 Application note

AN3353 Application note

BD238. Low voltage PNP power transistor. Features. Applications. Description. Low saturation voltage PNP transistor

TN0023 Technical note

BD135 - BD136 BD139 - BD140

AN4128 Application note

BD241A BD241C. NPN power transistors. Features. Applications. Description. NPN transistors. Audio, general purpose switching and amplifier transistors

BZW50. Transil, transient voltage surge suppressor (TVS) Features. Description

Single LNB supply and control IC DiSEqC 1.X compliant with EXTM based on the LNBH29 in a QFN16 (4x4) Description

Figure 1. STM32F429 Discovery board: STM32F429I-DISCO

AN3110 Application note

AN3270 Application note

ULN2801A, ULN2802A, ULN2803A, ULN2804A

ULN2001, ULN2002 ULN2003, ULN2004

AN3969 Application note

MC Low noise quad operational amplifier. Features. Description

AN3359 Application note

UM1613 User manual. 16-pin smartcard interface ST8034P demonstration board. Introduction

Getting started with software and firmware environments for the STM32F0DISCOVERY kit

STM32F4DISCOVERY. Discovery kit with STM32F407VG MCU. Features. Description

Description. Table 1. Device summary. Order code Temperature range Package Packaging Marking

ETP01-xx21. Protection for Ethernet lines. Features. Description. Applications. Benefits. Complies with the following standards

Order code Temperature range Package Packaging

EN: This Datasheet is presented by the m anufacturer. Please v isit our website for pricing and availability at ore.hu.

UM0834 User manual. Developing and debugging your STM8S-DISCOVERY application code. Introduction. Reference documents

LM337. Three-terminal adjustable negative voltage regulators. Features. Description

DSL01-xxxSC5. Secondary protection for DSL lines. Features. Description. Applications. Benefits. Complies with the following standards

STTH2R06. High efficiency ultrafast diode. Features. Description

SPC5-CRYP-LIB. SPC5 Software Cryptography Library. Description. Features. SHA-512 Random engine based on DRBG-AES-128

32F072BDISCOVERY. Discovery kit for STM32F072xx microcontrollers. Features. Description

STEVAL-IEG001V2. Smart real-time vehicle tracking system. Features

Description. IO and RF AGC. ASIC controller and power management. Carrier recovery loop. GPIO switch matrix. Lock indicator and monitoring DVBS2 FEC

AN2866 Application note

P6KE. Transil, transient voltage surge suppressor (TVS) Features. Description. Complies with the following standards

UM0462 User manual. STM32 and STM8 Flash loader demonstrator. Introduction

ST19NP18-TPM-I2C. Trusted Platform Module (TPM) with I²C Interface. Features

UM1075 User manual. ST-LINK/V2 in-circuit debugger/programmer for STM8 and STM32. Introduction

LM135-LM235-LM335. Precision temperature sensors. Features. Description

STTH1R04-Y. Automotive ultrafast recovery diode. Features. Description

L6234. Three phase motor driver. Features. Description

AN1819 APPLICATION NOTE Bad Block Management in Single Level Cell NAND Flash Memories

Table 1. Absolute maximum ratings (T amb = 25 C) Symbol Parameter Value Unit. ISO C = 330 pf, R = 330 Ω : Contact discharge Air discharge

L78MxxAB L78MxxAC. Precision 500 ma regulators. Features. Description

STP60NF06. N-channel 60V Ω - 60A TO-220 STripFET II Power MOSFET. General features. Description. Internal schematic diagram.

STP60NF06FP. N-channel 60V Ω - 30A TO-220FP STripFET II Power MOSFET. General features. Description. Internal schematic diagram.

UA741. General-purpose single operational amplifier. Features. Applications. Description. N DIP8 (plastic package)

TN0072 Technical note

STN3NF06L. N-channel 60 V, 0.07 Ω, 4 A, SOT-223 STripFET II Power MOSFET. Features. Application. Description

LM134-LM234-LM334. Three terminal adjustable current sources. Features. Description

Description. Table 1. Device summary

AN974 APPLICATION NOTE

AN1754 APPLICATION NOTE

STDP2690. Advanced DisplayPort to DisplayPort (dual mode) converter. Features. Applications

UM1969 User manual. Getting started with STM32F746G discovery software development tools. Introduction

AN3211 Application note

AN2146 APPLICATION NOTE

AN2760 Application note

32F769IDISCOVERY. Discovery kit with STM32F769NI MCU. Features

AN2703 Application note

Description SO-8. series. Furthermore, in the 8-pin configuration Very low-dropout voltage (0.2 V typ.)

Description. Table 1. Device summary. Order codes. TO-220 (single gauge) TO-220 (double gauge) D²PAK (tape and reel) TO-220FP

UM1727 User manual. Getting started with STM32 Nucleo board software development tools. Introduction

AN886 APPLICATION NOTE

TDA W CAR RADIO AUDIO AMPLIFIER

STCS A max constant current LED driver. Features. Applications. Description

STDP4328. DisplayPort 1.2a concentrator. Features. Applications

STDP4320. DisplayPort 1.2a splitter. Features. Applications

STP55NF06L STB55NF06L - STB55NF06L-1

VN05N. High side smart power solid state relay PENTAWATT. Features. Description

STGB10NB37LZ STGP10NB37LZ

TDA2004R W stereo amplifier for car radio. Features. Description

STTH110. High voltage ultrafast rectifier. Description. Features

Transcription:

Application note Upgrading STM32F4DISCOVERY board firmware using a USB key Introduction An important requirement for most Flash memory-based systems is the ability to update the firmware installed in the end product. This document provides general guidelines for creating a firmware upgrade application based on the STM32F4DISCOVERY board. The STM32F4 series microcontroller can run user-specific applications to upgrade the firmware of the microcontroller-embedded Flash memory. This feature allows the use of any type of communication protocol for the reprogramming process (for example, CAN, USART and USB). USB Host mass storage is the example used in this application note. The firmware upgrade using a USB Host is very advantageous because it is a standalone executed code in which the user does not need to use a host computer to perform the firmware upgrade. The user only needs a Flash disk to upgrade the target STM32 device. Document contents Section 1: Firmware upgrade overview contains an overview of the firmware upgrade process and demonstrates how to run the firmware upgrade. Section 2: How to use the firmware upgrade application describes the user program and system requirements for the software and hardware. Reference documents STM32F4DISCOVERY STM32F4 high-performance discovery board (UM1472) STM32F405xx, STM32F407xx, STM32F415xx and STM32F417xx advanced ARMbased 32-bit MCUs reference manual (RM0090) STM32F405xx STM32F407xx datasheet STM32F415xx STM32F417xx datasheet The above documents are available at www.st.com/stm32f4-discovery. October 2011 Doc ID 022318 Rev 1 1/14 www.st.com

Firmware upgrade overview AN3990 1 Firmware upgrade overview To program the firmware upgrade application to the Flash memory, use the STM32F4xx's embedded Bootloader or any in-system programming tool to easily reprogram this application. Note: The firmware upgrade application uses the USB Host to: Download a binary file (.bin) from a Flash disk (thumb drive) to the STM32F4xx's internal flash memory. Upload all the STM32F4xx's internal Flash memory content into a binary file. Execute the user program. This application note is based on the STM32 USB On-The-Go (OTG) Host and device library. For more details about the USB Host stack and a mass storage demonstration, please refer to user manual (UM1021). 1.1 Implementing the firmware upgrade application The firmware upgrade application contains the source files in Table 1. Table 1. Source files File Contents main.c stm32f4xx_it.c command.c flash_if.c usb_bsp.c usbh_usr.c system_stm32f4xx.c Contains the USB initialization data. The USB Host state machine is then executed if the user wants to execute the firmware upgrade application or the program will execute the user code Contains the interrupt handlers for the application Contains the firmware upgrade commands (DOWNLOAD, UPLOAD and JUMP commands) Provides a medium layer access to the STM32 embedded Flash driver Implements the board support package for the USB Host library Includes the USB Host library user callbacks Contains the system clock configuration for STM32 F4xx devices 2/14 Doc ID 022318 Rev 1

Firmware upgrade overview After the board reset and depending on the user button state: 1. User button pressed: The firmware upgrade application is executed. 2. User button not pressed: A test on the user application start address will be performed and one of the below processes is executed. User vector table available: User application is executed. User vector table not available: firmware upgrade application is executed. During the firmware upgrade application execution, there is a continuous check on the user button pressed state time. Depending on the state time of the user button, one of the following processes is executed. Table 2. User button state time control User button state Time Process executed Pressed > 3 seconds UPLOAD command will be executed immediately after completed execution of the DOWNLOAD command. < 3 seconds Only the DOWNLOAD command is executed. Note: The UPLOAD command condition verification is signaled by the blinking state of the blue LED. Doc ID 022318 Rev 1 3/14

Firmware upgrade overview AN3990 Figure 1 illustrates the Firmware upgrade application flowchart. Figure 1. Upgrade application flowchart Note: To execute the UPLOAD command the user button should be kept pressed 3s just after a board reset, at firmware startup. 4/14 Doc ID 022318 Rev 1

Firmware upgrade overview 1.2 LEDs status The following section describes the LEDs behaviors during the firmware upgrade application execution: Red LED blinks in infinite loop Error (USB key disconnected, binary file not available or FATFS file system error). Red LED blinks in infinite loop and Blue LED ON Error (No available Flash memory size to load the binary file). Red LED blinks in infinite loop, Blue LED ON and Orange LED ON Flash erase error. Blue LED ON DOWNLOAD ongoing. Blue LED ON and Orange LED ON DOWNLOAD done; UPLOAD ongoing. Blue LED blinks UPLOAD condition verified and the user should release the user button. Orange LED ON DOWNLOAD done. Orange LED ON, Blue LED ON and Red LED blinks in infinite loop USB key read out protection ON. Green LED ON and Orange LED OFF DOWNLOAD done with success; and the MCU waiting until you press the user button to execute the JUMP command. Green LED ON and Orange LED ON DOWNLOAD and UPLOAD done with success; and the MCU waiting until you press the user button before execute the JUMP command. 1.3 Commands description The firmware upgrade application commands are listed in Table 3. Table 3. Supported commands Command DOWNLOAD UPLOAD JUMP Description Reads the defined image file DOWNLOAD_FILENAME from the thumb drive and writes it to the embedded Flash memory. Reads the entire embedded Flash memory and saves the contents to the defined file name UPLOAD_FILENAME in the thumb drive. Executes the user code at the defined user application start address APPLICATION_ADDRESS. Note: The maximum length for the file names (DOWNLOAD_FILENAME, UPLOAD_FILENAME) should be 11 characters as the LFN feature on the FAT file system is a patent of Microsoft Corporation and when enabling it on commercial products, a license from Microsoft may be required depending on the final destination. Doc ID 022318 Rev 1 5/14

Firmware upgrade overview AN3990 1.3.1 DOWNLOAD command To download a binary file from the flash thumb drive to the internal STM32F4xx's embedded flash memory the flowchart in Figure 2: DOWNLOAD command is applied. Figure 2. DOWNLOAD command Start DOWNLOAD Open a binary file named DOWNLOAD_FILENAME saved on the Flash disk No: Binary file not available Yes Check the available Flash size to load the binary image Yes No available Flash memory size to load the binary file Blue LED ON Download on going Erase the necessary space to program the binary file Read the BUFFER_SIZE bytes from the binary file and writing them in the FLASH memory Set On blue LED and blink Red LED in infinite loop Set On Orange LED and blink Red LED in infinite loop Yes Check the remaining binary file size No Blue LED OFF and Green LED ON: Download done Close file named DOWNLOAD_FILENAME END Note: 1 BUFFER_SIZE is a user defined variable in the usbh_usr.h file that can be modified at compilation. BUFFER_SIZE = 512 * x; where x = [1,128] limited by firmware. 2 The DOWNLOAD command perform the erase of the required flash memory space then perform the program of the defined binary file using the flash word programming mode. 3 The Erase operation is performed for the FLASH memory space starting from the user application start address until the end of the flash memory. 6/14 Doc ID 022318 Rev 1

Firmware upgrade overview 1.3.2 UPLOAD command Figure 3 shows how to upload a copy of the internal Flash memory. Figure 3. UPLOAD command Start UPLOAD Check Flash Read Out Protection Status Yes: protection On No: Protection Off Remove the defined file UPLOAD_FILENAME if exists Open a new file named UPLOAD_FILENAME Blue LED ON Upload on going Read BUFFER_SIZE bytes in the FLASH memory and write them into the defined file UPLOAD_FILENAME Increment the counterread Set On Orange LED and blink Red LED in infinite loop counterread = end of FLASH No Yes Blue LED OFF and Green LED ON: Upload done Close file named UPLOAD_FILENAME END Note: 1 BUFFERSIZE is a user-defined variable in the usbh_usr.h file that can be modified at compilation. BUFFERSIZE = 512 * x; where x = [1,128] limited by firmware. 2 When the user selects the UPLOAD command, the old UPLOAD.BIN file will be deleted and replaced by a new one that contains the new Flash memory data. 3 To execute the UPLOAD command the user button should be kept pressed 3s just after a board reset, at firmware startup. Doc ID 022318 Rev 1 7/14

Firmware upgrade overview AN3990 1.3.3 JUMP command Once the new program has been loaded, you can use the JUMP command to execute this image which must be defined from this flash address: 0x08008000. Otherwise, the user must adapt the firmware to JUMP to another address. Figure 4 illustrates the JUMP command flowchart. Figure 4. JUMP Command Start JUMP MCU Software Reset TBD END JUMP Note: Once the previous command(s) are performed with success the user green LED is ON and the MCU waits until the user button is pressed before executing the JUMP command. 8/14 Doc ID 022318 Rev 1

How to use the firmware upgrade application 2 How to use the firmware upgrade application 2.1 System requirements Before running your application, you should establish the connection with the STM32F4DISCOVERY board as following in Figure 5. Figure 5. Hardware environment To run the firmware upgrade application on your STM32F4DISCOVERY board, the minimum requirements are as follows: Microsoft Windows PC (2000, XP, Vista, 7) USB type A to Mini-B' cable, used to power the board (through USB connector CN1) from host PC and connect to the embedded ST-LINK/V2 for debugging and programming. USB micro A-Male to A-Female' cable, used to connect the USB key (through USB connector CN5) as USB Device to host STM32F4xx. Doc ID 022318 Rev 1 9/14

How to use the firmware upgrade application AN3990 2.2 Running the firmware upgrade application To run the firmware upgrade application, proceed as follows: 1. Load the binary image of the user program to the root directory of a USB key. You can use the provided binary images (STM32F4-Discovery_xxxx_0x08008000.bin) under the Project\FW_upgrade\Binary folder. The binary should be renamed to image.bin. 2. Program the firmware upgrade application into the internal Flash memory. a) Open the project (under Project\FW_upgrade) with your preferred toolchain. b) Compile and load the project into the target memory and run the project. c) Another option is to use the embedded Bootloader or any in-system programming tool to easily reprogram this application. Use STM32F4-Discovery_FW_Upgrade_V1.0.0.hex with in-system programming tool such as STM32 ST-LINK Utility. Use STM32F4-Discovery_FW_Upgrade_V1.0.0.dfu with DFUse\DFUse Demonstration tool. For more details, please refer to the Binary images for reprogramming firmware applications section of UM1467. 3. Plug the USB key into the STM32F4DISCOVERY board through 'USB micro A-Male to A-Female' cable. 4. Follow the description provided in section Section 1.1: Implementing the firmware upgrade application on page 2. 10/14 Doc ID 022318 Rev 1

How to use the firmware upgrade application 2.3 User program condition The user application (binary file) to be loaded into the Flash memory using the firmware upgrade application is built by the following configuration settings: 1. Set the program load address to APPLICATION_ADDRESS in the toolchain linker file. 2. Relocate the vector table to address APPLICATION_ADDRESS using the NVIC_SetVectorTable function or the VECT_TAB_OFFSET definition inside the system_stm32f4xx.c file. Figure 6. Flash memory usage Note: 1 Be sure that APPLICATION_ADDRESS do not overlap with firmware upgrade application. For example, with all options enabled the total read-only memory size using EWARM compiler v6.21, with high optimization for size, is 17 936 bytes (17 744 bytes of read-only code memory and 192 bytes of read-only data memory). With these results, two sectors of 16 Kbytes each will be used to store the firmware upgrade application, so the user application flash start address will start from Sector2. Doc ID 022318 Rev 1 11/14

Frequently asked questions (FAQs) AN3990 3 Frequently asked questions (FAQs) How to change the name of the image to be loaded The name of the binary file to be loaded in the USB Key can be changed by personalizing the UPLOAD_FILENAME definition in the command.c file. How to change the name of the image to be downloaded The name of the binary file to be downloaded in the internal flash memory at user application start address can be changed by personalizing the DOWNLOAD_FILENAME definition in the command.c file. How to change the user application start address The user application start address can be changed by personalizing the APPLICATION_ADDRESS definition in the flash_if.h file. Note: By editing the user application start address, make sure that the user program conditions defined in Section 2: How to use the firmware upgrade application on page 9 are respected. How to modify the size of the Flash memory to be uploaded The size of the Flash memory to be uploaded can be changed by personalizing the FLASH_SIZE and the FLASH_STARTADDRESS definitions in the flash_if.h file. When using the CPU frequency = 168MHz, how much time does the DOWNLOAD command take? When the user application start address = 0x0800 8000 (start from sector 2) the erase operation takes 7.76s. With BUFFER_SIZE = 512 * 64 = 32 Kbytes and image size = 25 Kbytes, the DOWNLOAD operation takes about 7.94 seconds (7.76s erase time + 0.18s program time). With BUFFER_SIZE = 512 * 64 = 32 Kbytes and image size = 990 Kbytes, the DOWNLOAD operation takes about 12.7 seconds (7.76s erase time + 4.94s program time). When using the CPU frequency = 168MHz, how much time does the UPLOAD command take? With BUFFERSIZE = 512 * 64 = 32 Kbytes, uploading of all Flash memory (1Mbytes) takes about 1.5 seconds. 12/14 Doc ID 022318 Rev 1

Revision history 4 Revision history Table 4. Document revision history Date Revision Changes 24-Oct-2011 1 Initial release. Doc ID 022318 Rev 1 13/14

Please Read Carefully: Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries ( ST ) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at any time, without notice. All ST products are sold pursuant to ST s terms and conditions of sale. Purchasers are solely responsible for the choice, selection and use of the ST products and services described herein, and ST assumes no liability whatsoever relating to the choice, selection or use of the ST products and services described herein. No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein. UNLESS OTHERWISE SET FORTH IN ST S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY WITH RESPECT TO THE USE AND/OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWS OF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT. UNLESS EXPRESSLY APPROVED IN WRITING BY TWO AUTHORIZED ST REPRESENTATIVES, ST PRODUCTS ARE NOT RECOMMENDED, AUTHORIZED OR WARRANTED FOR USE IN MILITARY, AIR CRAFT, SPACE, LIFE SAVING, OR LIFE SUSTAINING APPLICATIONS, NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY, DEATH, OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE. ST PRODUCTS WHICH ARE NOT SPECIFIED AS "AUTOMOTIVE GRADE" MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER S OWN RISK. Resale of ST products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, any liability of ST. ST and the ST logo are trademarks or registered trademarks of ST in various countries. Information in this document supersedes and replaces all information previously supplied. The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners. 2011 STMicroelectronics - All rights reserved STMicroelectronics group of companies Australia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan - Malaysia - Malta - Morocco - Philippines - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of America www.st.com 14/14 Doc ID 022318 Rev 1