AN2557 Application note

Similar documents
AN3965 Application note

AN3354 Application note

AN4113 Application note

AN4045 Application note

AN2667 Application note

STEVAL-CCM002V1. TFT-LCD panel demonstration board based on the STM32 as LCD controller. Features. Description

STEVAL-SPBT4ATV3. USB dongle for the Bluetooth class 1 SPBT2632C1A.AT2 module. Features. Description

AN2143 Application note

STM3210B-SK/KEIL STR91X-SK/KEI, STR7-SK/KEIL

STEVAL-PCC010V1. ST802RT1A Ethernet PHY demonstration board with STM32F107 controller add-on board. Features. Description

STM32-SK/KEIL STR91X-SK/KEI, STR7-SK/KEIL

AN3996 Application Note

AN2676 Application note

AN2672 Application note

STM32-SK/RAIS,STR91X-SK/RAI,STR7-SK/RAIS STM32-D/RAIS,STR9-D/RAIS,STR7-D/RAIS

AN3279 Application Note

UM0792 User manual. Demonstration firmware for the DMX-512 communication protocol transmitter based on the STM32F103Zx.

UM0693 User manual. 1 Introduction. STM8L101-EVAL demonstration firmware

STM32-MP3NL/DEC. STM32 audio engine MP3 decoder library. Description. Features

AN626 Application note

AN3154 Application note

UM1572 User manual. STEVAL-IPE020V1: ST energy meter application based on the Android platform. Introduction

AN3980 Application note

STM3220G-SK/KEI. Keil starter kit for STM32F2 series microcontrollers (STM32F207IG MCU) Features. Description

STM8 I 2 C optimized examples

AN2594 Application note

AN2470 Application note TS4871 low voltage audio power amplifier Evaluation board user guidelines Features Description

AN2855 Application note

EV-VNQ5E050AK VNQ5E050AK evaluation board

UM0401 User manual. User manual for eight bit port expander STMPE801 demonstration board. Introduction

AN2261 APPLICATION NOTE

OSPlus USB Extension. OSPlus USB 2.0 extension. Description. Features. Application. TCP/IP stack NexGenOS NexGenIP VFS. FAT Ext2 LVM Device layer

STTS V memory module temperature sensor. Features

STM32 embedded target for MATLAB and Simulink release 3.1. Summary for STM32 embedded target for MATLAB and Simulink release 3.1:

STM8L-PRIMER STM32-PRIMER STMPRIMER

AN2737 Application note Basic in-application programming example using the STM8 I 2 C and SPI peripherals Introduction

AN2430 Application note

ST33F1M. Smartcard MCU with 32-bit ARM SecurCore SC300 CPU and 1.25 Mbytes high-density Flash memory. Features. Hardware features.

AN2792 Application note

AN2361 Application note

SOT23-6L ESDALCL6-2SC6

ST19WR08 Dual Contactless Smartcard MCU With RF UART, IART & 8 Kbytes EEPROM Features Contactless specific features

STA bit single chip baseband controller for GPS and telematic applications. Features

AN2673 Application note

AN2825 Application Note

UM1488 User manual. STPMC1 evaluation software. Introduction

AN2592 Application note

STMicroelectronics. STxP70-4 assembler. User manual Rev A. October

UM1084 User manual. CR95HF development software user guide. Introduction. Reference documents

EVAL6235PD. L6235 three-phase brushless DC motor driver demonstration board. Features. Description

Description SPC564A-DISP. March 2014 DocID Rev 3 1/5

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

TN0189 Technical note

AN3250 Application note

STEVAL-IHM028V1. 2 kw 3-phase motor control demonstration board featuring the IGBT intelligent power module STGIPS20K60. Features.

AN2240 Application note

Getting started with DfuSe USB device firmware upgrade STMicroelectronics extension

RN0046 Release note. 1 Introduction. SimpleMAC library for STM32W108xx kits. About this release note

AN4152 Application note

AN2202 Application note

AN3362 Application note

STM8L-PRIMER STM32-PRIMER STMPRIMER

AN3988 Application note

STICE CF/Stice_Connect AD/Stice_Connect AS/Stice_Connect

AN2474 Application note

AN2734 Application note S-Touch design procedure Introduction

AN4321 Application note

EMIF01-SMIC01F2 IPAD. Single line EMI filter including ESD protection. Main application. Description. Benefits. Pin configuration (Bump side view)

AN3265 Application note

TN0132 Technical note

Obsolete Product(s) - Obsolete Product(s)

AN4274 Application note

AN2781 Application note

AN3155 Application note

AN2606 Application note

Main components USB charging controller with integrated power switch

STLC2500D. Bluetooth V2.1 "Lisbon" + EDR. Features. Description

AN2606 Application note

ST21NFCB. Near field communication controller. Features. RF communications. Hardware features. Communication interfaces. Electrical characteristics

Main components 1 A, high efficiency adjustable single inductor dual mode buckboost DC-DC converter

AN3001 Application note

EMIF02-SPK02F2. 2-line IPAD, EMI filter and ESD protection. Features. Application. Description. Complies with the following standards

SMP75. Trisil for telecom equipment protection. Features. Description. Applications. Benefits

AN3174 Application note

EMIF02-MIC01F2 2-line IPAD, EMI filter including ESD protection Features Application Description Complies with the standards:

STM8-SK/RAIS STM8-D/RAIS ST7-SK/RAIS ST7-D/RAIS

AN3975 Application note

AN2408 Application note

AN3376 Application note

ST33F1M, ST33F1M0, ST33F896, ST33F768, ST33F640, ST33F512

AN3099 Application note

UM1677 User manual. Getting started with STM32F030 Value Line Discovery development tools. Introduction

AN4464 Application note

Description of STM8 LIN software package (STSW-STM8A-LIN) release 4.1. Table 1. Release information. STM8 LIN package

AN3390 Application note

AN3226 Application note


L6460. SPI configurable stepper and DC multi motor driver. Features. Description

LD A very low drop adjustable positive voltage regulator. Description. Features

AN2860 Application note

Transcription:

Application note STM32F10x in-application programming using the USART Introduction An important requirement for most Flash-memory-based systems is the ability to update firmware when installed in the end product. This ability is referred to as in-application programming (IAP). The purpose of this application note is to provide general guidelines for creating an IAP application. The STM32100B-EVAL, STM32100E-EVAL, STM3210B-EVAL, STM3210E-EVAL and STM3210C-EVAL boards were used to validate the IAP driver. The STM32F10x microcontroller can run user-specific firmware to perform IAP of the microcontroller-embedded Flash memory. This feature allows the use of any type of communication protocol for the reprogramming process (such as CAN, USART, USB). USART is the example used in this application note. October 2010 Doc ID 13588 Rev 8 1/16 www.st.com

Contents AN2557 Contents 1 IAP overview............................................... 5 1.1 Principle................................................... 5 1.2 IAP driver description......................................... 5 2 Running the IAP driver....................................... 8 2.1 HyperTerminal configuration................................... 8 2.2 Executing the IAP driver....................................... 9 3 IAP driver menu............................................ 10 3.1 Download image to the internal Flash memory.................... 10 3.2 Upload image from the internal Flash memory.................... 11 3.3 Execute the new program..................................... 11 3.4 Disabling the write protection.................................. 11 4 STM32F10x IAP implementation summary...................... 12 5 User program conditions.................................... 14 6 Revision history........................................... 15 2/16 Doc ID 13588 Rev 8

List of tables List of tables Table 1. STM32F10xxx IAP implementation.......................................... 12 Table 2. Revision history......................................................... 15 Doc ID 13588 Rev 8 3/16

List of figures AN2557 List of figures Figure 1. Flowchart of the IAP driver.................................................. 7 Figure 2. COM port properties....................................................... 8 Figure 3. IAP Driver menu when the STM32F10x Flash memory is not protected.............. 10 Figure 4. IAP driver menu when the STM32F10x Flash memory is write-protected............. 11 Figure 5. Flash memory usage..................................................... 14 4/16 Doc ID 13588 Rev 8

IAP overview 1 IAP overview Low-density devices are STM32F101xx, STM32F102xx, and STM32F103xx microcontrollers where the Flash memory density ranges between 16 and 32 Kbytes. Medium-density devices are STM32F101xx, STM32F102xx, and STM32F103xx microcontrollers where the Flash memory density ranges between 64 and 128 Kbytes. High-density devices are STM32F101xx and STM32F103xx microcontrollers where the Flash memory density ranges between 256 and 512 Kbytes. High-density devices are implemented in the STMicroelectronics STM3210E-EVAL evaluation board. Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers. Connectivity line devices are implemented in the STMicroelectronics STM32100C-EVAL evaluation board. Low-density value line devices are STM32F100x4 and STM32F100x6 microcontrollers where the Flash memory density ranges between 16 and 32 Kbytes. Medium-density value line devices are STM32F100x8 and STM32F100xB microcontrollers where the Flash memory density ranges between 64 and 128 Kbytes. Medium-density value line devices are implemented in the STMicroelectronics STM32100B- EVAL evaluation board. XL-density devices are STM32F101xx and STM32F103xx microcontrollers where the Flash memory density ranges between 768 Kbytes and 1 Mbyte. High-density value line devices are STM32F100xC, STM32F100xD and STM32F100xE microcontrollers where the Flash memory density ranges between 256 and 512 Kbytes. High-density value line devices are implemented in the STMicroelectronics STM32100E- EVAL evaluation board. 1.1 Principle You should program the IAP driver to the Flash memory base address via the JTAG/SWD interface using the development toolchain of your choice or the factory-embedded boot loader in the System memory area. 'The IAP driver uses the USART to: Download a binary file from the HyperTerminal to the STM32F10x's internal Flash memory. Upload the STM32F10x's internal flash memory content (starting from the defined user application address) into a binary file. Execute the user program. 1.2 IAP driver description The IAP driver contains the following set of source files: main.c: where the USART initialization is set. A main menu is then executed from the common.c file. common.c: contains display functions and the main menu routine. The main menu gives the options of loading a new binary file, uploading a new binary file, executing the Doc ID 13588 Rev 8 5/16

IAP overview AN2557 binary file already loaded and disabling the write protection of the pages where the user loads his binary file (if they are write-protected). ymodem.c and download.c: they are used to receive the data from the HyperTerminal application (using the YMODEM protocol (a), and then to load them into the STM32F10x s internal RAM. In the event of a failure when receiving the data, the Failed to receive the file error message is displayed. If the data is received successfully, it is programmed into the internal Flash memory from the appropriate address. A comparison between internal RAM contents and internal Flash memory contents is performed to check the data integrity. If there is any data discrepancy, the Verification failed error message is displayed. Other error messages are also displayed when the image file size is greater than the allowed memory space and when the user aborts the task. upload.c: it is used to transmit the STM32F10xxx internal Flash memory content started from the user application address using the ymodem protocol. STM32F10x Standard Peripherals Library. To select the STMicroelectronics evaluation board STM32100B-EVAL (Medium density value line devices), STM3210C-EVAL (Connectivity line devices), STM3210E-EVAL (High density devices), STM32100E-EVAL (High-density value line devices) or STM3210B-EVAL (Medium-density devices) used to run the IAP, uncomment the corresponding line in stm32_eval.h file (under Utilities\STM32_EVAL) //#define USE_STM32100B_EVAL //#define USE_STM3210B_EVAL //#define USE_STM3210E_EVAL //#define USE_STM3210C_EVAL //#define USE_STM32100E_EVAL The user can choose to either go to the user application or execute the IAP for reprogramming purposes by pressing a push-button connected to a pin. Not pressing the push-button at reset switches to the user application Pressing the push-button at reset displays the IAP main menu Refer to Table 1.: STM32F10xxx IAP implementation for more details about the STM32100B-EVAL, STM3210B-EVAL, STM3210E-EVAL, STM3210C-EVAL and STM32100E-EVAL board push-button used to enter the IAP mode. The IAP flowchart is represented in Figure 1. a. The Ymodem protocol sends data in 1024-byte blocks. An error check is performed in data blocks transmitted to the STM32F10xxx s internal RAM to compare the transmitted and received data. Blocks unsuccessfully received are acknowledged with an NAK (Negative Acknowledgement). For more details about the Ymodem protocol, refer to existing documentation. 6/16 Doc ID 13588 Rev 8

IAP overview Figure 1. Flowchart of the IAP driver Doc ID 13588 Rev 8 7/16

Running the IAP driver AN2557 2 Running the IAP driver The IAP driver is programmed in Flash memory: From page 0 to page 11 on Low-density devices, Medium-density devices, Low-density value line devices, and Medium-density value line devices. From page 0 to page 5 on High-density, Connectivity line, XL density devices and Highdensity value line device. The user application occupies the remaining memory space. 2.1 HyperTerminal configuration To use the IAP, the user must have a PC running HyperTerminal or other Terminal program that supports ymodem protocol as shown in Figure 2. In this document the HyperTerminal is used. The following figure shows the HyperTerminal configuration. Figure 2. COM port properties Note: The baud rate value of 115200 bps is used as an example. Care must be taken when selecting the system clock frequency. To guarantee successful communication via the USART, the system clock frequency in the end application must be such that a baud rate equal to 115200 bps can be generated. 8/16 Doc ID 13588 Rev 8

Running the IAP driver 2.2 Executing the IAP driver As an example in this application note, pressing the pin connected to the push-button allows the IAP driver to run. By pressing the push-button at reset, the user can run the IAP driver to reprogram the STM32F10x s internal Flash memory. It is not mandatory to use the push-button; the user can apply a signal to this pin with respect to its active level. Refer to Table 1.: STM32F10xxx IAP implementation. Doc ID 13588 Rev 8 9/16

IAP driver menu AN2557 3 IAP driver menu Running the IAP displays the following menu in the HyperTerminal window. Figure 3. IAP Driver menu when the STM32F10x Flash memory is not protected 3.1 Download image to the internal Flash memory To download a binary file via HyperTerminal to the STM32F10x s internal Flash memory, do as follows: 1. Press 1 on the keyboard to select the Download Image To the STM32F10x Internal Flash menu 2. Select Send File in the Transfer menu 3. In the Filename field, type the name and the path of the binary file you want to download 4. From the protocol list, select the Ymodem protocol 5. Click on the Send button As a result, the IAP driver loads the binary file into the STM32F10x s internal Flash memory from the defined base address and displays the binary file name and size in the HyperTerminal window. 10/16 Doc ID 13588 Rev 8

IAP driver menu 3.2 Upload image from the internal Flash memory To upload a copy of the internal Flash memory started from the user application address, do as follows: 1. Press 2 on the keyboard to select Upload image from the STM32F10x internal Flash menu. 2. Select Receive File in the Transfer menu. 3. Choose the directory of the binary file you want to create. 4. From the protocol list, select the Ymodem protocol. 5. Click on the Receive button. 3.3 Execute the new program Once the new program has been loaded, press 3 on the keyboard to select the Execute The New Program menu and execute the code. 3.4 Disabling the write protection When the IAP starts, it checks the Flash memory pages where the user program is to be loaded to see if any are write-protected. If it is the case, the menu shown in Figure 4 appears. Figure 4. IAP driver menu when the STM32F10x Flash memory is write-protected Prior to downloading the new program, the write protection must be disabled. To do so, press 4 (Disable the write protection) on the keyboard. The write protection is disabled and a system reset is generated to reload the new option byte values. After resuming from reset, the menu shown in Figure 3 is displayed if the key push-button is pressed. Note: In this application, the read protection is not supported, so the user has to verify that the Flash memory is not read-protected. Doc ID 13588 Rev 8 11/16

STM32F10x IAP implementation summary AN2557 4 STM32F10x IAP implementation summary Table 1 provides a summary of the STM32F10x IAP implementation. Table 1. STM32F10xxx IAP implementation Firmware Hardware The IAP program is located at 0x8000000. The Flash routines (program/erase) are executed from the Flash memory. The size of this program is about 12 Kbytes and programmed on: The user application (image to be loaded with the IAP) will be programmed starting from address 0x8003000 (1). The maximum size of the image to be loaded is: The image is uploaded with the IAP from the STM32F10xxx internal Flash. The maximum size of the image to be uploaded is: Push-button (active level: low) USART used Medium-density devices (STM3210B-EVAL) page 0 to page 11 116 Kbytes (page 12 - page 127) 116 Kbytes (page 12 - page 127) Key pushbutton connected to pin PB.09 USART1 High-density devices (STM3210E-EVAL) page 0 to page 5 500 Kbytes (page 6 - page 255) 500 Kbytes (page 6 - page 255) Key pushbutton connected to pin PG.08 USART1 Connectivity line devices (STM3210C-EVAL) page 0 to page 5 244 Kbytes (page 6 - page 127) 244 Kbytes (page 6 - page 127) Key pushbutton connected to pin PB.09 USART2 (Tx/Rx pins remapped) Medium-density value line devices (STM32100B-EVAL) page 0 to page 11 116 Kbytes (page 12 - page 127) 116 Kbytes (page 12 - page 127) Key pushbutton connected to pin PB.09 USART1 XL-density devices (STM3210E-EVAL) page 0 to page 5 1012 Kbytes (page 6 - page 512) 1012 Kbytes (page 6 - page 512) Key pushbutton connected to pin PG.08 USART1 High-density value line devices (STM32100E-EVAL) page 0 to page 5 500 Kbytes (page 6 - page 255) 500 Kbytes (page 6 - page 255) Key pushbutton connected to pin PG.08 USART1 1. User application location address is defined in the common.h file as: #define ApplicationAddress 0x8003000.To modify it, change the default value to the desired one. In the previous version of the IAP implementation, the ApplicationAddress was 0x8002000. It has been changed to 0x8003000 due the additional code (~1 KBytes) needed to support the for IAP upload feature. 12/16 Doc ID 13588 Rev 8

STM32F10x IAP implementation summary The STM32F10xxx IAP package comes with: Source files and pre-configured projects for the IAP program (under Project\IAP directory) Source files and pre-configured projects that build the application to be loaded into Flash memory using the IAP (under Project\IAP\binary_template directory). The readme.txt files provided within this package describes step by step how to execute this IAP application. Doc ID 13588 Rev 8 13/16

User program conditions AN2557 5 User program conditions The user application to be loaded into the Flash memory using IAP should be built with these configuration settings: 1. Set the program load address at 0x08003000, using your toolchain linker file 2. Relocate the vector table at address 0x08003000, using the "NVIC_SetVectorTable"function or the VECT_TAB_OFFSET definition inside the "system_stm32f10x.c" An example application program to be loaded with the IAP application is provided with preconfigured projects. Figure 5. Flash memory usage 1. Top Flash memory address is equal to/ 0x0800 7FFF for Low-density and Low-density value line devices 0x0801 FFFF for Medium-density and Medium-density value line devices 0x0803 FFFF for Connectivity Line devices 0x0807 FFFF for High-density and High-density value line devices. 0x080F FFFF for XL-density devices 14/16 Doc ID 13588 Rev 8

Revision history 6 Revision history Table 2. Revision history Date Revision Changes 05-Jun-2007 1 Initial release. 05-Oct-2007 2 30-May-2008 3 The IAP driver can also be programmed from the SWD interface (see Section 1.1: Principle). Modified: Figure 3: IAP Driver menu when the STM32F10x Flash memory is not protected Figure 4: IAP driver menu when the STM32F10x Flash memory is write-protected Figure 6: IAP driver directory structure. Flash routines modified in Table 1.: STM32F10xxx IAP implementation. Section 5: User program conditions updated. Section 7: How to use the IAP driver modified, RIDE project added. Application note updated to apply to High-density devices (implemented on the STM3210E-EVAL evaluation board). Small text changes. Figure 1: Flowchart of the IAP driver on page 7 corrected. 13-Jun-2008 4 Figure 6: IAP driver directory structure modified. 31-Jul-2009 5 Updated for connectivity line devices. 28-May-2010 6 Introduction: added STM32100B-EVAL evaluation board. Section 1: IAP overview: added low-density value line and mediumdensity value line devices; updated list of devices for medium density devices and connectivity line devices; added XL-density line devices. Section 1.2: IAP driver description: updated section for addition of STM32100B-EVAL evaluation board. Section 2: Running the IAP driver: added Low-density devices, Lowdensity value line devices, Medium-density value line devices and XL-density line devices. Replaced Figure 3: IAP Driver menu when the STM32F10x Flash memory is not protected and Figure 4: IAP driver menu when the STM32F10x Flash memory is write-protected Section 3.4: Disabling the write protection: small text change. Section 4: STM32F10x IAP implementation summary: in Table 1 added Medium-density value line and XL-density devices; updated High-density devices and Connectivity line devices. Made small text change in general text. Figure 5: Flash memory usage: updated Note 1 12-Oct-2010 7 Updated for high-density value line devices. 26-Oct-2010 8 Modified Section 2.1: HyperTerminal configuration on page 8 Updated Figure 3 on page 10. Changed AppplicationAddress from 0x8002000 to 0x8003000 in Table 1: STM32F10xxx IAP implementation on page 12 and Figure 5: Flash memory usage on page 14 Doc ID 13588 Rev 8 15/16

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 AN AUTHORIZED ST REPRESENTATIVE, 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. 2010 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 16/16 Doc ID 13588 Rev 8