Mercurial > ~darius > hgwebdir.cgi > stm32temp
comparison libs/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/FLASH/Program/main.c @ 0:c59513fd84fb
Initial commit of STM32 test code.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 03 Oct 2011 21:19:15 +1030 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c59513fd84fb |
---|---|
1 /** | |
2 ****************************************************************************** | |
3 * @file FLASH/Program/main.c | |
4 * @author MCD Application Team | |
5 * @version V3.5.0 | |
6 * @date 08-April-2011 | |
7 * @brief Main program body | |
8 ****************************************************************************** | |
9 * @attention | |
10 * | |
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS | |
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE | |
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY | |
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING | |
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE | |
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. | |
17 * | |
18 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2> | |
19 ****************************************************************************** | |
20 */ | |
21 | |
22 /* Includes ------------------------------------------------------------------*/ | |
23 #include "stm32f10x.h" | |
24 | |
25 | |
26 /** @addtogroup STM32F10x_StdPeriph_Examples | |
27 * @{ | |
28 */ | |
29 | |
30 /** @addtogroup FLASH_Program | |
31 * @{ | |
32 */ | |
33 | |
34 /* Private typedef -----------------------------------------------------------*/ | |
35 typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus; | |
36 | |
37 /* Private define ------------------------------------------------------------*/ | |
38 /* Define the STM32F10x FLASH Page Size depending on the used STM32 device */ | |
39 #if defined (STM32F10X_HD) || defined (STM32F10X_HD_VL) || defined (STM32F10X_CL) || defined (STM32F10X_XL) | |
40 #define FLASH_PAGE_SIZE ((uint16_t)0x800) | |
41 #else | |
42 #define FLASH_PAGE_SIZE ((uint16_t)0x400) | |
43 #endif | |
44 | |
45 #define BANK1_WRITE_START_ADDR ((uint32_t)0x08008000) | |
46 #define BANK1_WRITE_END_ADDR ((uint32_t)0x0800C000) | |
47 | |
48 #ifdef STM32F10X_XL | |
49 #define BANK2_WRITE_START_ADDR ((uint32_t)0x08088000) | |
50 #define BANK2_WRITE_END_ADDR ((uint32_t)0x0808C000) | |
51 #endif /* STM32F10X_XL */ | |
52 | |
53 /* Private macro -------------------------------------------------------------*/ | |
54 /* Private variables ---------------------------------------------------------*/ | |
55 uint32_t EraseCounter = 0x00, Address = 0x00; | |
56 uint32_t Data = 0x3210ABCD; | |
57 uint32_t NbrOfPage = 0x00; | |
58 volatile FLASH_Status FLASHStatus = FLASH_COMPLETE; | |
59 volatile TestStatus MemoryProgramStatus = PASSED; | |
60 | |
61 #ifdef STM32F10X_XL | |
62 volatile TestStatus MemoryProgramStatus2 = PASSED; | |
63 #endif /* STM32F10X_XL */ | |
64 | |
65 /* Private function prototypes -----------------------------------------------*/ | |
66 /* Private functions ---------------------------------------------------------*/ | |
67 | |
68 /** | |
69 * @brief Main program | |
70 * @param None | |
71 * @retval None | |
72 */ | |
73 int main(void) | |
74 { | |
75 /*!< At this stage the microcontroller clock setting is already configured, | |
76 this is done through SystemInit() function which is called from startup | |
77 file (startup_stm32f10x_xx.s) before to branch to application main. | |
78 To reconfigure the default setting of SystemInit() function, refer to | |
79 system_stm32f10x.c file | |
80 */ | |
81 | |
82 /* Porgram FLASH Bank1 ********************************************************/ | |
83 /* Unlock the Flash Bank1 Program Erase controller */ | |
84 FLASH_UnlockBank1(); | |
85 | |
86 /* Define the number of page to be erased */ | |
87 NbrOfPage = (BANK1_WRITE_END_ADDR - BANK1_WRITE_START_ADDR) / FLASH_PAGE_SIZE; | |
88 | |
89 /* Clear All pending flags */ | |
90 FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR); | |
91 | |
92 /* Erase the FLASH pages */ | |
93 for(EraseCounter = 0; (EraseCounter < NbrOfPage) && (FLASHStatus == FLASH_COMPLETE); EraseCounter++) | |
94 { | |
95 FLASHStatus = FLASH_ErasePage(BANK1_WRITE_START_ADDR + (FLASH_PAGE_SIZE * EraseCounter)); | |
96 } | |
97 | |
98 /* Program Flash Bank1 */ | |
99 Address = BANK1_WRITE_START_ADDR; | |
100 | |
101 while((Address < BANK1_WRITE_END_ADDR) && (FLASHStatus == FLASH_COMPLETE)) | |
102 { | |
103 FLASHStatus = FLASH_ProgramWord(Address, Data); | |
104 Address = Address + 4; | |
105 } | |
106 | |
107 FLASH_LockBank1(); | |
108 | |
109 /* Check the correctness of written data */ | |
110 Address = BANK1_WRITE_START_ADDR; | |
111 | |
112 while((Address < BANK1_WRITE_END_ADDR) && (MemoryProgramStatus != FAILED)) | |
113 { | |
114 if((*(__IO uint32_t*) Address) != Data) | |
115 { | |
116 MemoryProgramStatus = FAILED; | |
117 } | |
118 Address += 4; | |
119 } | |
120 | |
121 #ifdef STM32F10X_XL | |
122 /* Program FLASH Bank2 ********************************************************/ | |
123 /* Unlock the Flash Bank2 Program Erase controller */ | |
124 FLASH_UnlockBank2(); | |
125 | |
126 /* Define the number of page to be erased */ | |
127 NbrOfPage = (BANK2_WRITE_END_ADDR - BANK2_WRITE_START_ADDR) / FLASH_PAGE_SIZE; | |
128 | |
129 /* Clear All pending flags */ | |
130 FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR); | |
131 | |
132 /* Erase the FLASH pages */ | |
133 for(EraseCounter = 0; (EraseCounter < NbrOfPage) && (FLASHStatus == FLASH_COMPLETE); EraseCounter++) | |
134 { | |
135 FLASHStatus = FLASH_ErasePage(BANK2_WRITE_START_ADDR + (FLASH_PAGE_SIZE * EraseCounter)); | |
136 } | |
137 | |
138 /* Program Flash Bank2 */ | |
139 Address = BANK2_WRITE_START_ADDR; | |
140 | |
141 while((Address < BANK2_WRITE_END_ADDR) && (FLASHStatus == FLASH_COMPLETE)) | |
142 { | |
143 FLASHStatus = FLASH_ProgramWord(Address, Data); | |
144 Address = Address + 4; | |
145 } | |
146 | |
147 FLASH_LockBank2(); | |
148 | |
149 /* Check the correctness of written data */ | |
150 Address = BANK2_WRITE_START_ADDR; | |
151 | |
152 while((Address < BANK2_WRITE_END_ADDR) && (MemoryProgramStatus2 != FAILED)) | |
153 { | |
154 if((*(__IO uint32_t*) Address) != Data) | |
155 { | |
156 MemoryProgramStatus2 = FAILED; | |
157 } | |
158 Address += 4; | |
159 } | |
160 | |
161 #endif /* STM32F10X_XL */ | |
162 | |
163 while (1) | |
164 { | |
165 } | |
166 } | |
167 | |
168 #ifdef USE_FULL_ASSERT | |
169 | |
170 /** | |
171 * @brief Reports the name of the source file and the source line number | |
172 * where the assert_param error has occurred. | |
173 * @param file: pointer to the source file name | |
174 * @param line: assert_param error line source number | |
175 * @retval None | |
176 */ | |
177 void assert_failed(uint8_t* file, uint32_t line) | |
178 { | |
179 /* User can add his own implementation to report the file name and line number, | |
180 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ | |
181 | |
182 while (1) | |
183 { | |
184 } | |
185 } | |
186 | |
187 #endif | |
188 | |
189 /** | |
190 * @} | |
191 */ | |
192 | |
193 /** | |
194 * @} | |
195 */ | |
196 | |
197 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ |