annotate OtherSources/firmwareEraseProgram.c @ 656:3ccf13af4651

Added visualization of scrubber time: The remaining scrubber timer may be displayed in minutes or percentage of maximum time (both countdown). The value is displayed in the lower left corner, the overview custom view in T7 display as well as in the O2 Monitor view of the T3 display.
author Ideenmodellierer
date Sun, 25 Apr 2021 20:47:01 +0200
parents 7801c5d8a562
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1 /**
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
2 ******************************************************************************
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
3 * @file firmwareEraseProgram.c
36
7801c5d8a562 Update author name for release
heinrichsweikamp
parents: 5
diff changeset
4 * @author heinrichs weikamp gmbh
5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
5 * @version V0.0.1
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
6 * @date 05-May-2015
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
7 * @version V0.0.1
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
8 * @since 05-May-2015
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
9 * @brief erase and program the STM32F4xx internal FLASH memory
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
10 *
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
11 @verbatim
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
12 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
13 ##### How to use #####
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
14 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
15 ADDR_FLASH_SECTOR_0 to/with ADDR_FLASH_SECTOR_5 (256KB) is used for this bootloader
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
16
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
17 ADDR_FLASH_SECTOR_23 is blocked and used for Font T48 and image_heinrichs_weikamp
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
18 Font T24 for button text is not blocked / protected
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
19 other fonts should not be used here
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
20
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
21
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
22 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
23 ##### From AN2557 #####
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
24 STM32F10xxx In-Application programming CD00161640.pdf 2010
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
25 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
26 User program conditions
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
27 The user application to be loaded into the Flash memory using IAP should be built with
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
28 these configuration settings:
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
29 1. Set the program load address at 0x08003000, using your toolchain linker file
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
30 2. Relocate the vector table at address 0x08003000, using the
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
31 "NVIC_SetVectorTable"function or the VECT_TAB_OFFSET definition inside the
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
32 "system_stm32f10x.c"
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
33
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
34 can be found here system_stm32f4xx.c
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
35
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
36
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
37 @endverbatim
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
38 ******************************************************************************
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
39 * @attention
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
40 *
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
41 * <h2><center>&copy; COPYRIGHT(c) 2015 heinrichs weikamp</center></h2>
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
42 *
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
43 ******************************************************************************
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
44 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
45
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
46 /* Includes ------------------------------------------------------------------*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
47 #include "stm32f4xx_hal.h"
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
48 #include "stdio.h"
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
49 #include "firmwareEraseProgram.h"
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
50 #include "settings.h" // to access SHardwareData
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
51
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
52 /* Exported variables --------------------------------------------------------*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
53
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
54 /* Private types -------------------------------------------------------------*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
55
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
56 /* Base address of the Flash sectors Bank 1 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
57 #define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
58 #define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
59 #define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
60 #define ADDR_FLASH_SECTOR_3 ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
61 #define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
62 #define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
63 #define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
64 #define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
65 #define ADDR_FLASH_SECTOR_8 ((uint32_t)0x08080000) /* Base @ of Sector 8, 128 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
66 #define ADDR_FLASH_SECTOR_9 ((uint32_t)0x080A0000) /* Base @ of Sector 9, 128 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
67 #define ADDR_FLASH_SECTOR_10 ((uint32_t)0x080C0000) /* Base @ of Sector 10, 128 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
68 #define ADDR_FLASH_SECTOR_11 ((uint32_t)0x080E0000) /* Base @ of Sector 11, 128 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
69
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
70 /* Base address of the Flash sectors Bank 2 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
71 #define ADDR_FLASH_SECTOR_12 ((uint32_t)0x08100000) /* Base @ of Sector 0, 16 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
72 #define ADDR_FLASH_SECTOR_13 ((uint32_t)0x08104000) /* Base @ of Sector 1, 16 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
73 #define ADDR_FLASH_SECTOR_14 ((uint32_t)0x08108000) /* Base @ of Sector 2, 16 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
74 #define ADDR_FLASH_SECTOR_15 ((uint32_t)0x0810C000) /* Base @ of Sector 3, 16 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
75 #define ADDR_FLASH_SECTOR_16 ((uint32_t)0x08110000) /* Base @ of Sector 4, 64 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
76 #define ADDR_FLASH_SECTOR_17 ((uint32_t)0x08120000) /* Base @ of Sector 5, 128 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
77 #define ADDR_FLASH_SECTOR_18 ((uint32_t)0x08140000) /* Base @ of Sector 6, 128 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
78 #define ADDR_FLASH_SECTOR_19 ((uint32_t)0x08160000) /* Base @ of Sector 7, 128 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
79 #define ADDR_FLASH_SECTOR_20 ((uint32_t)0x08180000) /* Base @ of Sector 8, 128 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
80 #define ADDR_FLASH_SECTOR_21 ((uint32_t)0x081A0000) /* Base @ of Sector 9, 128 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
81 #define ADDR_FLASH_SECTOR_22 ((uint32_t)0x081C0000) /* Base @ of Sector 10, 128 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
82 #define ADDR_FLASH_SECTOR_23 ((uint32_t)0x081E0000) /* Base @ of Sector 11, 128 Kbytes */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
83
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
84 #define SECTOR_SIZE_128KB ((uint32_t)0x00020000)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
85
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
86 #define FLASH_FW_START_ADDR ADDR_FLASH_SECTOR_6
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
87 #define FLASH_FW_END_ADDR (ADDR_FLASH_SECTOR_12 - 1)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
88
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
89 #define FLASH_FW2_START_ADDR ADDR_FLASH_SECTOR_12
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
90 #define FLASH_FW2_END_ADDR (ADDR_FLASH_SECTOR_22 + SECTOR_SIZE_128KB - 1)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
91
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
92 /* Private variables ---------------------------------------------------------*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
93
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
94 static FLASH_EraseInitTypeDef EraseInitStruct; /*Variable used for Erase procedure*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
95
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
96 uint32_t FirstSector = 0, NbOfSectors = 0, Address = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
97 uint32_t SectorError = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
98 __IO uint32_t data32 = 0 , MemoryProgramStatus = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
99
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
100
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
101
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
102 /* Private function prototypes -----------------------------------------------*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
103 //static void firmware_Error_Handler(HAL_StatusTypeDef reason);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
104 static uint32_t GetSector(uint32_t Address);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
105 uint8_t hardware_programm_sub(uint8_t *buffer64, uint8_t length, uint32_t startAddress);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
106
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
107 /* Exported functions --------------------------------------------------------*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
108
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
109 const SHardwareData* hardwareDataGetPointer(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
110 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
111 return (SHardwareData*)HARDWAREDATA_ADDRESS;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
112 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
113
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
114 uint8_t hardware_programmPrimaryBluetoothNameSet(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
115 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
116 uint8_t data = 0xF0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
117 return hardware_programm_sub(&data, 1, HARDWAREDATA_ADDRESS + 7);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
118 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
119
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
120
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
121 uint8_t hardware_programmSecondaryBluetoothNameSet(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
122 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
123 uint8_t data = 0xF0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
124 return hardware_programm_sub(&data, 1, HARDWAREDATA_ADDRESS + 52 + 7);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
125 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
126
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
127
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
128 uint8_t hardware_programmProductionData(uint8_t *buffer52)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
129 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
130 buffer52[7] = 0xFF;// production_bluetooth_name_set
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
131 return hardware_programm_sub(buffer52, 52, HARDWAREDATA_ADDRESS);// check base_bootloader.c of OSTC4bootloader code and settings.h
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
132 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
133
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
134
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
135 uint8_t hardware_programmSecondarySerial(uint8_t *buffer12)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
136 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
137 buffer12[7] = 0xFF;// secondary_bluetooth_name_set
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
138 return hardware_programm_sub(buffer12, 12, HARDWAREDATA_ADDRESS + 52);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
139 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
140
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
141
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
142 uint8_t hardware_programm_sub(uint8_t *buffer, uint8_t length, uint32_t startAddress)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
143 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
144 HAL_StatusTypeDef answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
145
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
146 uint32_t ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
147 uint8_t data8;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
148
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
149 // test empty
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
150 Address = startAddress;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
151 for(int i=0;i<length;i++)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
152 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
153 if((*(uint8_t *)Address != 0xFF) && (buffer[i] != 0xFF))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
154 return 0xE0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
155 Address = Address + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
156 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
157
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
158 // start programming
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
159 HAL_FLASH_Unlock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
160
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
161 Address = startAddress;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
162 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
163 answer = HAL_OK;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
164 while (ptr < length)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
165 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
166 if(buffer[ptr] != 0xFF)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
167 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
168 answer = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, buffer[ptr]);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
169 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
170 if (answer == HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
171 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
172 Address = Address + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
173 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
174 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
175 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
176 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
177 HAL_FLASH_Lock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
178 return answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
179 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
180 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
181 HAL_FLASH_Lock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
182
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
183 /* Check if the programmed data is OK
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
184 MemoryProgramStatus = 0: data programmed correctly
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
185 MemoryProgramStatus != 0: number of words not programmed correctly ******/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
186 Address = startAddress; // check base_bootloader.c of OSTC4bootloader code
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
187 MemoryProgramStatus = 0x0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
188
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
189 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
190 while(ptr < length)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
191 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
192 data8 = *(__IO uint8_t*)Address;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
193
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
194 if((buffer[ptr] != 0xFF) && (data8 != buffer[ptr]))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
195 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
196 MemoryProgramStatus++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
197 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
198
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
199 Address = Address + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
200 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
201 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
202
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
203 /* Check if there is an issue to program data */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
204 if (MemoryProgramStatus == 0)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
205 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
206 return HAL_OK;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
207 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
208 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
209 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
210 return 0xEE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
211 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
212 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
213
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
214
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
215 uint8_t firmware2_variable_upperpart_eraseFlashMemory(uint32_t length, uint32_t offset)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
216 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
217 uint32_t startAddress, endAddress;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
218
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
219 // HAL_StatusTypeDef answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
220 HAL_FLASH_Unlock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
221
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
222 startAddress = FLASH_FW2_START_ADDR + offset;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
223 endAddress = startAddress + length;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
224
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
225 if(endAddress > FLASH_FW2_END_ADDR)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
226 endAddress = FLASH_FW2_END_ADDR;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
227
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
228 FirstSector = GetSector(startAddress);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
229 NbOfSectors = GetSector(endAddress) - FirstSector + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
230
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
231 EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
232 EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
233 EraseInitStruct.Sector = FirstSector;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
234 EraseInitStruct.NbSectors = NbOfSectors;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
235
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
236 return HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
237 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
238
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
239
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
240 uint8_t firmware2_variable_upperpart_programFlashMemory(uint32_t length, uint32_t offset, uint8_t *pBuffer1, uint32_t pBuffer1Size, uint8_t *pBuffer2)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
241 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
242 HAL_StatusTypeDef answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
243 uint32_t ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
244 uint32_t length1, length2;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
245
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
246 if((pBuffer2) && (length > pBuffer1Size))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
247 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
248 length1 = pBuffer1Size;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
249 length2 = length - length1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
250 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
251 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
252 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
253 length1 = length;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
254 length2 = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
255 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
256
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
257 Address = FLASH_FW2_START_ADDR + offset;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
258
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
259 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
260 while ((Address <= FLASH_FW2_END_ADDR) && (ptr < length1))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
261 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
262 answer = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, pBuffer1[ptr]);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
263 if (answer == HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
264 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
265 Address = Address + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
266 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
267 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
268 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
269 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
270 return answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
271 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
272 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
273 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
274 while ((Address <= FLASH_FW2_END_ADDR) && (ptr < length2))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
275 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
276 answer = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, pBuffer2[ptr]);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
277 if (answer == HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
278 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
279 Address = Address + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
280 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
281 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
282 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
283 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
284 return answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
285 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
286 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
287 HAL_FLASH_Lock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
288
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
289 Address = FLASH_FW2_START_ADDR + offset;;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
290 MemoryProgramStatus = 0x0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
291
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
292 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
293 while ((Address <= FLASH_FW2_END_ADDR) && (ptr < length1))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
294 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
295 data32 = *(__IO uint8_t*)Address;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
296
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
297 if (data32 != pBuffer1[ptr])
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
298 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
299 MemoryProgramStatus++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
300 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
301
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
302 Address = Address + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
303 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
304 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
305 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
306 while ((Address <= FLASH_FW2_END_ADDR) && (ptr < length2))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
307 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
308 data32 = *(__IO uint8_t*)Address;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
309
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
310 if (data32 != pBuffer2[ptr])
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
311 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
312 MemoryProgramStatus++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
313 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
314
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
315 Address = Address + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
316 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
317 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
318
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
319 if (MemoryProgramStatus == 0)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
320 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
321 return HAL_OK;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
322 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
323 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
324 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
325 return 0xEE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
326 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
327 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
328
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
329 uint8_t firmware_eraseFlashMemory(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
330 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
331 // HAL_StatusTypeDef answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
332 /* Unlock the Flash to enable the flash control register access *************/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
333 HAL_FLASH_Unlock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
334
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
335 /* Erase the user Flash area
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
336 (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
337
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
338 /* Get the 1st sector to erase */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
339 FirstSector = GetSector(FLASH_FW_START_ADDR);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
340 /* Get the number of sector to erase from 1st sector*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
341 NbOfSectors = GetSector(FLASH_FW_END_ADDR) - FirstSector + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
342
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
343 /* Fill EraseInit structure*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
344 EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
345 EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
346 EraseInitStruct.Sector = FirstSector;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
347 EraseInitStruct.NbSectors = NbOfSectors;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
348
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
349 /* Note: If an erase operation in Flash memory also concerns data in the data or instruction cache,
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
350 you have to make sure that these data are rewritten before they are accessed during code
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
351 execution. If this cannot be done safely, it is recommended to flush the caches by setting the
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
352 DCRST and ICRST bits in the FLASH_CR register. */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
353 return HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
354 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
355
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
356 uint8_t firmware_programFlashMemory(uint8_t *pBuffer1, uint32_t length1)//, uint8_t *pBuffer2, uint32_t length2)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
357 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
358 HAL_StatusTypeDef answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
359
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
360 /* Program the user Flash area word by word
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
361 (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
362
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
363 uint32_t ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
364
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
365 Address = FLASH_FW_START_ADDR;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
366
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
367 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
368 while ((Address <= FLASH_FW_END_ADDR) && (ptr < length1))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
369 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
370 answer = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, pBuffer1[ptr]);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
371 if (answer == HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
372 // if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address, DATA_32) == HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
373 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
374 Address = Address + 1;//4;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
375 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
376 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
377 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
378 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
379 return answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
380 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
381 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
382 /* same for pBuffer2
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
383 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
384 while ((Address < FLASH_FW_END_ADDR) && (ptr < length2))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
385 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
386
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
387 if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, pBuffer2[ptr]) == HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
388 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
389 Address = Address + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
390 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
391 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
392 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
393 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
394 firmware_Error_Handler();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
395 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
396 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
397 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
398 /* Lock the Flash to disable the flash control register access (recommended
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
399 to protect the FLASH memory against possible unwanted operation) *********/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
400 HAL_FLASH_Lock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
401
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
402 /* Check if the programmed data is OK
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
403 MemoryProgramStatus = 0: data programmed correctly
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
404 MemoryProgramStatus != 0: number of words not programmed correctly ******/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
405 Address = FLASH_FW_START_ADDR;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
406 MemoryProgramStatus = 0x0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
407
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
408 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
409 while ((Address <= FLASH_FW_END_ADDR) && (ptr < length1))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
410 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
411 data32 = *(__IO uint8_t*)Address;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
412
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
413 if (data32 != pBuffer1[ptr])
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
414 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
415 MemoryProgramStatus++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
416 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
417
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
418 Address = Address + 1;//4;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
419 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
420 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
421 /* same for pBuffer2
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
422 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
423 while ((Address < FLASH_FW_END_ADDR) && (ptr < length2))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
424 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
425 data32 = *(__IO uint32_t*)Address;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
426
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
427 if (data32 != pBuffer2[ptr])
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
428 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
429 MemoryProgramStatus++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
430 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
431
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
432 Address = Address + 1;//4;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
433 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
434 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
435 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
436 /* Check if there is an issue to program data */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
437 if (MemoryProgramStatus == 0)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
438 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
439 return HAL_OK;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
440 /* No error detected. Switch on LED3 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
441 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
442 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
443 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
444 return 0xEE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
445 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
446
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
447
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
448 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
449
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
450 /* Private functions ---------------------------------------------------------*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
451
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
452 /**
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
453 * @brief Gets the sector of a given address
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
454 * @param None
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
455 * @retval The sector of a given address
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
456 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
457 static uint32_t GetSector(uint32_t Address)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
458 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
459 uint32_t sector = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
460
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
461 if((Address < ADDR_FLASH_SECTOR_1) && (Address >= ADDR_FLASH_SECTOR_0))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
462 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
463 sector = FLASH_SECTOR_0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
464 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
465 else if((Address < ADDR_FLASH_SECTOR_2) && (Address >= ADDR_FLASH_SECTOR_1))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
466 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
467 sector = FLASH_SECTOR_1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
468 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
469 else if((Address < ADDR_FLASH_SECTOR_3) && (Address >= ADDR_FLASH_SECTOR_2))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
470 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
471 sector = FLASH_SECTOR_2;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
472 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
473 else if((Address < ADDR_FLASH_SECTOR_4) && (Address >= ADDR_FLASH_SECTOR_3))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
474 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
475 sector = FLASH_SECTOR_3;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
476 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
477 else if((Address < ADDR_FLASH_SECTOR_5) && (Address >= ADDR_FLASH_SECTOR_4))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
478 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
479 sector = FLASH_SECTOR_4;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
480 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
481 else if((Address < ADDR_FLASH_SECTOR_6) && (Address >= ADDR_FLASH_SECTOR_5))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
482 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
483 sector = FLASH_SECTOR_5;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
484 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
485 else if((Address < ADDR_FLASH_SECTOR_7) && (Address >= ADDR_FLASH_SECTOR_6))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
486 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
487 sector = FLASH_SECTOR_6;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
488 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
489 else if((Address < ADDR_FLASH_SECTOR_8) && (Address >= ADDR_FLASH_SECTOR_7))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
490 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
491 sector = FLASH_SECTOR_7;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
492 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
493 else if((Address < ADDR_FLASH_SECTOR_9) && (Address >= ADDR_FLASH_SECTOR_8))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
494 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
495 sector = FLASH_SECTOR_8;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
496 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
497 else if((Address < ADDR_FLASH_SECTOR_10) && (Address >= ADDR_FLASH_SECTOR_9))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
498 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
499 sector = FLASH_SECTOR_9;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
500 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
501 else if((Address < ADDR_FLASH_SECTOR_11) && (Address >= ADDR_FLASH_SECTOR_10))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
502 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
503 sector = FLASH_SECTOR_10;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
504 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
505 else if((Address < ADDR_FLASH_SECTOR_12) && (Address >= ADDR_FLASH_SECTOR_11))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
506 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
507 sector = FLASH_SECTOR_11;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
508 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
509 else if((Address < ADDR_FLASH_SECTOR_13) && (Address >= ADDR_FLASH_SECTOR_12))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
510 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
511 sector = FLASH_SECTOR_12;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
512 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
513 else if((Address < ADDR_FLASH_SECTOR_14) && (Address >= ADDR_FLASH_SECTOR_13))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
514 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
515 sector = FLASH_SECTOR_13;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
516 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
517 else if((Address < ADDR_FLASH_SECTOR_15) && (Address >= ADDR_FLASH_SECTOR_14))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
518 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
519 sector = FLASH_SECTOR_14;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
520 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
521 else if((Address < ADDR_FLASH_SECTOR_16) && (Address >= ADDR_FLASH_SECTOR_15))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
522 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
523 sector = FLASH_SECTOR_15;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
524 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
525 else if((Address < ADDR_FLASH_SECTOR_17) && (Address >= ADDR_FLASH_SECTOR_16))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
526 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
527 sector = FLASH_SECTOR_16;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
528 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
529 else if((Address < ADDR_FLASH_SECTOR_18) && (Address >= ADDR_FLASH_SECTOR_17))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
530 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
531 sector = FLASH_SECTOR_17;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
532 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
533 else if((Address < ADDR_FLASH_SECTOR_19) && (Address >= ADDR_FLASH_SECTOR_18))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
534 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
535 sector = FLASH_SECTOR_18;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
536 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
537 else if((Address < ADDR_FLASH_SECTOR_20) && (Address >= ADDR_FLASH_SECTOR_19))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
538 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
539 sector = FLASH_SECTOR_19;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
540 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
541 else if((Address < ADDR_FLASH_SECTOR_21) && (Address >= ADDR_FLASH_SECTOR_20))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
542 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
543 sector = FLASH_SECTOR_20;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
544 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
545 else if((Address < ADDR_FLASH_SECTOR_22) && (Address >= ADDR_FLASH_SECTOR_21))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
546 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
547 sector = FLASH_SECTOR_21;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
548 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
549 else if((Address < ADDR_FLASH_SECTOR_23) && (Address >= ADDR_FLASH_SECTOR_22))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
550 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
551 sector = FLASH_SECTOR_22;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
552 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
553 else/*(Address < FLASH_END_ADDR) && (Address >= ADDR_FLASH_SECTOR_23))*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
554 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
555 sector = FLASH_SECTOR_23;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
556 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
557
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
558 return sector;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
559 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
560
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
561 /*
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
562 static void firmware_Error_Handler(HAL_StatusTypeDef reason)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
563 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
564 static HAL_StatusTypeDef last_reason = HAL_OK;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
565
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
566 last_reason = reason;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
567 while(1)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
568 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
569 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
570 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
571 */