STM32F10xxx Flash programming.pdf

(257 KB) Pobierz
STM32F10xxx Flash programming
PM0042
Programming manual
STM32F10xxx Flash programming
Introduction
This programming manual describes how to program the Flash memory of STM32F101xx,
STM32F102xx, STM32F103xx, STM32F105xx and STM32F107xx microcontrollers. For
convenience, these will be referred to as STM32F10xxx in the rest of this document unless
otherwise specified.
The STM32F10xxx embedded Flash memory can be programmed using in-circuit
programming or in-application programming.
The in-circuit programming (ICP) method is used to update the entire contents of the
Flash memory, using the JTAG, SWD protocol or the boot loader to load the user application
into the microcontroller. ICP offers quick and efficient design iterations and eliminates
unnecessary package handling or socketing of devices.
In contrast to the ICP method, in-application programming (IAP) can use any
communication interface supported by the microcontroller (I/Os, USB, CAN, UART, I 2 C, SPI,
etc.) to download programming data into memory. IAP allows the user to re-program the
Flash memory while the application is running. Nevertheless, part of the application has to
have been previously programmed in the Flash memory using ICP.
The Flash interface implements instruction access and data access based on the AHB
protocol. It implements a prefetch buffer that speeds up CPU code execution. It also
implements the logic necessary to carry out Flash memory operations (Program/Erase).
Program/Erase operations can be performed over the whole product voltage range.
Read/Write protections and option bytes are also implemented.
June 2009
Doc ID 13259 Rev 6
1/33
219741133.002.png
Contents
PM0042
Contents
1
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.1
Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2
Flash module organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2
Reading/programming the STM32F10xxx embedded Flash memory 12
2.1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.2
Read operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.2.1
Instruction fetch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.2.2
D-Code interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.2.3
Flash access controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.3
Flash program and erase controller (FPEC) . . . . . . . . . . . . . . . . . . . . . . 13
2.3.1
Key values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.3.2
Unlocking the Flash memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.3.3
Main Flash memory programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.3.4
Flash memory erase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.3.5
Option byte programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.4
Protections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.4.1
Read protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.4.2
Write protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.4.3
Option byte block write protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.5
Option byte description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3
Register descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.1
Flash access control register (FLASH_ACR) . . . . . . . . . . . . . . . . . . . . . . 23
3.2
FPEC key register (FLASH_KEYR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.3
Flash OPTKEY register (FLASH_OPTKEYR) . . . . . . . . . . . . . . . . . . . . . 24
3.4
Flash status register (FLASH_SR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.5
Flash control register (FLASH_CR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.6
Flash address register (FLASH_AR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.7
Option byte register (FLASH_OBR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.8
Write protection register (FLASH_WRPR) . . . . . . . . . . . . . . . . . . . . . . . . 28
3.9
Flash register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2/33
Doc ID 13259 Rev 6
219741133.003.png
PM0042
Contents
4
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Doc ID 13259 Rev 6
3/33
219741133.004.png
List of tables
PM0042
List of tables
Table 1. Flash module organization (low-density devices) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Table 2. Flash module organization (medium-density devices) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Table 3. Flash module organization (high-density devices) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Table 4. Flash module organization (connectivity line devices) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Table 5. Flash memory protection status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Table 6. Option byte format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Table 7. Option byte organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Table 8. Description of the option bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Table 9. Abbreviations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Table 10. Flash interface - register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Table 11. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
4/33
Doc ID 13259 Rev 6
219741133.005.png
PM0042
List of figures
List of figures
Figure 1.
Programming procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Figure 2.
Flash memory Page Erase procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Figure 3.
Flash memory Mass Erase procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Doc ID 13259 Rev 6
5/33
219741133.001.png
Zgłoś jeśli naruszono regulamin