DM00036049 - STM32F41x In-Application Programming Using The USART
DM00036049 - STM32F41x In-Application Programming Using The USART
Application note
STM32F40x/STM32F41x in-application programming
using the USART
1 Introduction
Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 IAP overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1 Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 IAP driver description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
7 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2 IAP overview
2.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 STM32F4xx internal Flash
memory.
● Upload the STM32F4xx internal Flash memory content (starting from the defined user
application address) into a binary file.
● Execute the user program.
a. The Ymodem protocol sends data in 1024-byte blocks. An error check is performed in the data blocks
transmitted to the STM32F4xx 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 the existing documentation.
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: STM32F4xx IAP implementation for more details about the STM324xG-
EVAL board push-button used to enter the IAP mode.
The IAP flowchart is shown in Figure 1.
Start
Push-button No
is pressed?
Yes
Initialize USART
Download, upload,
switch or disable
write-protection
No
Success
Yes
Transmit image Disable the Switch to
Program the Flash
of the device internal Flash write protection user program
ai14402c
Running the IAP displays the following menu in the HyperTerminal window.
Figure 3. IAP driver menu when the STM32F4xx Flash memory is not protected
Figure 4. IAP driver menu when the STM32F4xx 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.
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 0x08004000, using your toolchain linker file
2. Relocate the vector table at address 0x08004000, using the “NVIC_SetVectorTable”
function from the misc.h/.c driver (under STM32F4xx_StdPeriph_Driver\inc) or by
modifying the value of the constant “VECT_TAB_OFFSET” defined in the
system_stm32f4xx.c file.”
An example application program to be loaded with the IAP application is provided with
preconfigured projects.
User code
User code
Vector table
0x800 4000 Vector table
0x800 4000
0x800 3FFF
0x800 3FFF
IAP code
IAP code
Vector table
0x800 0000 Vector table
0x800 0000
MM18906V1
MM18906V1
1. Top Flash memory address is equal to 0x080F FFFF for STM32F4xx devices
7 Revision history
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.
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.