📄 stm32f10x_flash.lst
字号:
##############################################################################
# #
# IAR ARM ANSI C/C++ Compiler V4.42A/W32 KICKSTART 24/Dec/2007 11:03:40 #
# Copyright 1999-2005 IAR Systems. All rights reserved. #
# #
# Cpu mode = thumb #
# Endian = little #
# Stack alignment = 4 #
# Source file = C:\Manley\EKBoard\EKSTM32F\LCDDemo(lcd+led+buttom)\L #
# CDDemo\library\src\stm32f10x_flash.c #
# Command line = "C:\Manley\EKBoard\EKSTM32F\LCDDemo(lcd+led+buttom)\ #
# LCDDemo\library\src\stm32f10x_flash.c" -D #
# VECT_TAB_FLASH -lC "C:\Manley\EKBoard\EKSTM32F\LCDDe #
# mo(lcd+led+buttom)\LCDDemo\project\EWARM\BOOT_FLASH\ #
# List\" -lA "C:\Manley\EKBoard\EKSTM32F\LCDDemo(lcd+l #
# ed+buttom)\LCDDemo\project\EWARM\BOOT_FLASH\List\" #
# -o "C:\Manley\EKBoard\EKSTM32F\LCDDemo(lcd+led+butto #
# m)\LCDDemo\project\EWARM\BOOT_FLASH\Obj\" -z3 #
# --no_cse --no_unroll --no_inline --no_code_motion #
# --no_tbaa --no_clustering --no_scheduling --debug #
# --cpu_mode thumb --endian little --cpu cortex-M3 #
# --stack_align 4 --require_prototypes --fpu None #
# --dlib_config "C:\Program Files\IAR #
# Systems\Embedded Workbench 4.0 #
# Kickstart\arm\LIB\dl7mptnnl8f.h" -I #
# "C:\Manley\EKBoard\EKSTM32F\LCDDemo(lcd+led+buttom)\ #
# LCDDemo\project\EWARM\..\" -I #
# "C:\Manley\EKBoard\EKSTM32F\LCDDemo(lcd+led+buttom)\ #
# LCDDemo\project\EWARM\..\..\library\inc\" -I #
# "C:\Program Files\IAR Systems\Embedded Workbench #
# 4.0 Kickstart\arm\INC\" #
# List file = C:\Manley\EKBoard\EKSTM32F\LCDDemo(lcd+led+buttom)\L #
# CDDemo\project\EWARM\BOOT_FLASH\List\stm32f10x_flash #
# .lst #
# Object file = C:\Manley\EKBoard\EKSTM32F\LCDDemo(lcd+led+buttom)\L #
# CDDemo\project\EWARM\BOOT_FLASH\Obj\stm32f10x_flash. #
# r79 #
# #
# #
##############################################################################
C:\Manley\EKBoard\EKSTM32F\LCDDemo(lcd+led+buttom)\LCDDemo\library\src\stm32f10x_flash.c
1 /******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
2 * File Name : stm32f10x_flash.c
3 * Author : MCD Application Team
4 * Date First Issued : 05/21/2007
5 * Description : This file provides all the FLASH firmware functions.
6 ********************************************************************************
7 * History:
8 * 05/21/2007: V0.3
9 ********************************************************************************
10 * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
11 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
12 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
13 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
14 * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
15 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
16 *******************************************************************************/
17
18 /* Includes ------------------------------------------------------------------*/
19 #include "stm32f10x_flash.h"
20
21 /* Private typedef -----------------------------------------------------------*/
22 /* Private define ------------------------------------------------------------*/
23 /* Flash Access Control Register bits */
24 #define ACR_LATENCY_Mask ((u32)0x00000038)
25 #define ACR_HLFCYA_Mask ((u32)0xFFFFFFF7)
26 #define ACR_PRFTBE_Mask ((u32)0xFFFFFFEF)
27
28 #ifdef _FLASH_PROG
29 /* Flash Access Control Register bits */
30 #define ACR_PRFTBS_Mask ((u32)0x00000020)
31
32 /* Flash Control Register bits */
33 #define CR_PG_Set ((u32)0x00000001)
34 #define CR_PG_Reset ((u32)0x00001FFE)
35
36 #define CR_PER_Set ((u32)0x00000002)
37 #define CR_PER_Reset ((u32)0x00001FFD)
38
39 #define CR_MER_Set ((u32)0x00000004)
40 #define CR_MER_Reset ((u32)0x00001FFB)
41
42 #define CR_OPTPG_Set ((u32)0x00000010)
43 #define CR_OPTPG_Reset ((u32)0x00001FEF)
44
45 #define CR_OPTER_Set ((u32)0x00000020)
46 #define CR_OPTER_Reset ((u32)0x00001FDF)
47
48 #define CR_STRT_Set ((u32)0x00000040)
49
50 #define CR_LOCK_Set ((u32)0x00000080)
51
52 /* FLASH Mask */
53 #define RDPRT_Mask ((u32)0x00000002)
54 #define WRP0_Mask ((u32)0x000000FF)
55 #define WRP1_Mask ((u32)0x0000FF00)
56 #define WRP2_Mask ((u32)0x00FF0000)
57 #define WRP3_Mask ((u32)0xFF000000)
58
59 /* FLASH Keys */
60 #define RDP_Key ((u16)0x00A5)
61 #define FLASH_KEY1 ((u32)0x45670123)
62 #define FLASH_KEY2 ((u32)0xCDEF89AB)
63
64 /* Delay definition */
65 #define EraseTimeout ((u32)0x00000FFF)
66 #define ProgramTimeout ((u32)0x0000000F)
67 #endif
68
69 /* Private macro -------------------------------------------------------------*/
70 /* Private variables ---------------------------------------------------------*/
71 /* Private function prototypes -----------------------------------------------*/
72 #ifdef _FLASH_PROG
73 static void delay(void);
74 #endif
75
76 /* Private functions ---------------------------------------------------------*/
77 /*******************************************************************************
78 * Function Name : FLASH_SetLatency
79 * Description : Sets the code latency value.
80 * Input : - FLASH_Latency: specifies the FLASH Latency value.
81 * This parameter can be one of the following values:
82 * - FLASH_Latency_0: FLASH Zero Latency cycle
83 * - FLASH_Latency_1: FLASH One Latency cycle
84 * - FLASH_Latency_2: FLASH Two Latency cycles
85 * Output : None
86 * Return : None
87 *******************************************************************************/
88 void FLASH_SetLatency(u32 FLASH_Latency)
89 {
90 /* Check the parameters */
91 assert(IS_FLASH_LATENCY(FLASH_Latency));
92
93 /* Sets the Latency value */
94 FLASH->ACR &= ACR_LATENCY_Mask;
95 FLASH->ACR |= FLASH_Latency;
96 }
97
98 /*******************************************************************************
99 * Function Name : FLASH_HalfCycleAccessCmd
100 * Description : Enables or disables the Half cycle flash access.
101 * Input : - FLASH_HalfCycle: specifies the FLASH Half cycle Access mode.
102 * This parameter can be one of the following values:
103 * - FLASH_HalfCycleAccess_Enable: FLASH Half Cycle Enable
104 * - FLASH_HalfCycleAccess_Disable: FLASH Half Cycle Disable
105 * Output : None
106 * Return : None
107 *******************************************************************************/
108 void FLASH_HalfCycleAccessCmd(u32 FLASH_HalfCycleAccess)
109 {
110 /* Check the parameters */
111 assert(IS_FLASH_HALFCYCLEACCESS_STATE(FLASH_HalfCycleAccess));
112
113 /* Enable or disable the Half cycle access */
114 FLASH->ACR &= ACR_HLFCYA_Mask;
115 FLASH->ACR |= FLASH_HalfCycleAccess;
116 }
117
118 /*******************************************************************************
119 * Function Name : FLASH_PrefetchBufferCmd
120 * Description : Enables or disables the Prefetch Buffer.
121 * Input : - FLASH_PrefetchBuffer: specifies the Prefetch buffer status.
122 * This parameter can be one of the following values:
123 * - FLASH_PrefetchBuffer_Enable: FLASH Prefetch Buffer Enable
124 * - FLASH_PrefetchBuffer_Disable: FLASH Prefetch Buffer Disable
125 * Output : None
126 * Return : None
127 *******************************************************************************/
128 void FLASH_PrefetchBufferCmd(u32 FLASH_PrefetchBuffer)
129 {
130 /* Check the parameters */
131 assert(IS_FLASH_PREFETCHBUFFER_STATE(FLASH_PrefetchBuffer));
132
133 /* Enable or disable the Prefetch Buffer */
134 FLASH->ACR &= ACR_PRFTBE_Mask;
135 FLASH->ACR |= FLASH_PrefetchBuffer;
136 }
137
138 #ifdef _FLASH_PROG
139 /*******************************************************************************
140 * Function Name : FLASH_Unlock
141 * Description : Unlocks the FLASH Program Erase Controller.
142 * Input : None
143 * Output : None
144 * Return : None
145 *******************************************************************************/
146 void FLASH_Unlock(void)
147 {
148 /* Authorize the FPEC Access */
149 FLASH->KEYR = FLASH_KEY1;
150 FLASH->KEYR = FLASH_KEY2;
151 }
152
153 /*******************************************************************************
154 * Function Name : FLASH_Lock
155 * Description : Locks the FLASH Program Erase Controller.
156 * Input : None
157 * Output : None
158 * Return : None
159 *******************************************************************************/
160 void FLASH_Lock(void)
161 {
162 /* Set the Lock Bit to lock the FPEC and the FCR */
163 FLASH->CR |= CR_LOCK_Set;
164 }
165
166 /*******************************************************************************
167 * Function Name : FLASH_ErasePage
168 * Description : Erases a specified FLASH page.
169 * Input : - Page_Address: The page address to be erased.
170 * Output : None
171 * Return : FLASH Status: The returned value can be: FLASH_BUSY,
172 * FLASH_ERROR_PG or FLASH_ERROR_WRP or FLASH_COMPLETE or
173 * FLASH_TIMEOUT.
174 *******************************************************************************/
175 FLASH_Status FLASH_ErasePage(u32 Page_Address)
176 {
177 FLASH_Status status = FLASH_COMPLETE;
178
179 /* Check the parameters */
180 assert(IS_FLASH_ADDRESS(Page_Address));
181
182 /* Wait for last operation to be completed */
183 status = FLASH_WaitForLastOperation(EraseTimeout);
184
185 if(status == FLASH_COMPLETE)
186 {
187 /* if the previous operation is completed, proceed to erase the page */
188 FLASH->CR|= CR_PER_Set;
189 FLASH->AR = Page_Address;
190 FLASH->CR|= CR_STRT_Set;
191
192 /* Wait for last operation to be completed */
193 status = FLASH_WaitForLastOperation(EraseTimeout);
194
195 if(status != FLASH_BUSY)
196 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -