annotate OtherSources/firmwareEraseProgram.c @ 1068:3c3fb9f4edc4 Icon_Integration

Increase version number for testing
author heinrichsweikamp
date Tue, 17 Feb 2026 12:22:47 +0100
parents a7ed4eb3142b
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 /* Private variables ---------------------------------------------------------*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
57
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
58 static FLASH_EraseInitTypeDef EraseInitStruct; /*Variable used for Erase procedure*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
59
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
60 uint32_t FirstSector = 0, NbOfSectors = 0, Address = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
61 uint32_t SectorError = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
62 __IO uint32_t data32 = 0 , MemoryProgramStatus = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
63
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
64
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
65
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
66 /* Private function prototypes -----------------------------------------------*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
67 //static void firmware_Error_Handler(HAL_StatusTypeDef reason);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
68 static uint32_t GetSector(uint32_t Address);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
69 uint8_t hardware_programm_sub(uint8_t *buffer64, uint8_t length, uint32_t startAddress);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
70
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
71 /* Exported functions --------------------------------------------------------*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
72
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
73 const SHardwareData* hardwareDataGetPointer(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
74 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
75 return (SHardwareData*)HARDWAREDATA_ADDRESS;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
76 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
77
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
78 uint8_t hardware_programmPrimaryBluetoothNameSet(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
79 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
80 uint8_t data = 0xF0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
81 return hardware_programm_sub(&data, 1, HARDWAREDATA_ADDRESS + 7);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
82 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
83
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
84
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
85 uint8_t hardware_programmSecondaryBluetoothNameSet(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
86 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
87 uint8_t data = 0xF0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
88 return hardware_programm_sub(&data, 1, HARDWAREDATA_ADDRESS + 52 + 7);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
89 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
90
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
91
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
92 uint8_t hardware_programmProductionData(uint8_t *buffer52)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
93 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
94 buffer52[7] = 0xFF;// production_bluetooth_name_set
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
95 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
96 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
97
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
98
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
99 uint8_t hardware_programmSecondarySerial(uint8_t *buffer12)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
100 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
101 buffer12[7] = 0xFF;// secondary_bluetooth_name_set
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
102 return hardware_programm_sub(buffer12, 12, HARDWAREDATA_ADDRESS + 52);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
103 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
104
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
105
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
106 uint8_t hardware_programm_sub(uint8_t *buffer, uint8_t length, uint32_t startAddress)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
107 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
108 HAL_StatusTypeDef answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
109
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
110 uint32_t ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
111 uint8_t data8;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
112
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
113 // test empty
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
114 Address = startAddress;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
115 for(int i=0;i<length;i++)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
116 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
117 if((*(uint8_t *)Address != 0xFF) && (buffer[i] != 0xFF))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
118 return 0xE0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
119 Address = Address + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
120 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
121
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
122 // start programming
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
123 HAL_FLASH_Unlock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
124
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
125 Address = startAddress;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
126 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
127 answer = HAL_OK;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
128 while (ptr < length)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
129 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
130 if(buffer[ptr] != 0xFF)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
131 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
132 answer = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, buffer[ptr]);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
133 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
134 if (answer == HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
135 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
136 Address = Address + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
137 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
138 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
139 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
140 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
141 HAL_FLASH_Lock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
142 return answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
143 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
144 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
145 HAL_FLASH_Lock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
146
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
147 /* Check if the programmed data is OK
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
148 MemoryProgramStatus = 0: data programmed correctly
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
149 MemoryProgramStatus != 0: number of words not programmed correctly ******/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
150 Address = startAddress; // check base_bootloader.c of OSTC4bootloader code
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
151 MemoryProgramStatus = 0x0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
152
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
153 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
154 while(ptr < length)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
155 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
156 data8 = *(__IO uint8_t*)Address;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
157
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
158 if((buffer[ptr] != 0xFF) && (data8 != buffer[ptr]))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
159 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
160 MemoryProgramStatus++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
161 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
162
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
163 Address = Address + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
164 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
165 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
166
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
167 /* Check if there is an issue to program data */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
168 if (MemoryProgramStatus == 0)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
169 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
170 return HAL_OK;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
171 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
172 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
173 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
174 return 0xEE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
175 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
176 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
177
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
178
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
179 uint8_t firmware2_variable_upperpart_eraseFlashMemory(uint32_t length, uint32_t offset)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
180 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
181 uint32_t startAddress, endAddress;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
182
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
183 // HAL_StatusTypeDef answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
184 HAL_FLASH_Unlock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
185
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
186 startAddress = FLASH_FW2_START_ADDR + offset;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
187 endAddress = startAddress + length;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
188
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
189 if(endAddress > FLASH_FW2_END_ADDR)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
190 endAddress = FLASH_FW2_END_ADDR;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
191
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
192 FirstSector = GetSector(startAddress);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
193 NbOfSectors = GetSector(endAddress) - FirstSector + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
194
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
195 EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
196 EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
197 EraseInitStruct.Sector = FirstSector;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
198 EraseInitStruct.NbSectors = NbOfSectors;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
199
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
200 return HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError);
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
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
204 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
205 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
206 HAL_StatusTypeDef answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
207 uint32_t ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
208 uint32_t length1, length2;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
209
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
210 if((pBuffer2) && (length > pBuffer1Size))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
211 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
212 length1 = pBuffer1Size;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
213 length2 = length - length1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
214 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
215 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
216 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
217 length1 = length;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
218 length2 = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
219 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
220
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
221 Address = FLASH_FW2_START_ADDR + offset;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
222
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
223 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
224 while ((Address <= FLASH_FW2_END_ADDR) && (ptr < length1))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
225 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
226 answer = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, pBuffer1[ptr]);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
227 if (answer == HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
228 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
229 Address = Address + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
230 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
231 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
232 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
233 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
234 return answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
235 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
236 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
237 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
238 while ((Address <= FLASH_FW2_END_ADDR) && (ptr < length2))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
239 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
240 answer = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, pBuffer2[ptr]);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
241 if (answer == HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
242 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
243 Address = Address + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
244 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
245 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
246 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
247 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
248 return answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
249 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
250 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
251 HAL_FLASH_Lock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
252
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
253 Address = FLASH_FW2_START_ADDR + offset;;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
254 MemoryProgramStatus = 0x0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
255
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
256 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
257 while ((Address <= FLASH_FW2_END_ADDR) && (ptr < length1))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
258 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
259 data32 = *(__IO uint8_t*)Address;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
260
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
261 if (data32 != pBuffer1[ptr])
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
262 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
263 MemoryProgramStatus++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
264 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
265
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
266 Address = Address + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
267 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
268 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
269 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
270 while ((Address <= FLASH_FW2_END_ADDR) && (ptr < length2))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
271 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
272 data32 = *(__IO uint8_t*)Address;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
273
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
274 if (data32 != pBuffer2[ptr])
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
275 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
276 MemoryProgramStatus++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
277 }
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
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
283 if (MemoryProgramStatus == 0)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
284 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
285 return HAL_OK;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
286 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
287 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
288 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
289 return 0xEE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
290 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
291 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
292
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
293 uint8_t firmware_eraseFlashMemory(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
294 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
295 // HAL_StatusTypeDef answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
296 /* Unlock the Flash to enable the flash control register access *************/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
297 HAL_FLASH_Unlock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
298
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
299 /* Erase the user Flash area
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
300 (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
301
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
302 /* Get the 1st sector to erase */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
303 FirstSector = GetSector(FLASH_FW_START_ADDR);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
304 /* Get the number of sector to erase from 1st sector*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
305 NbOfSectors = GetSector(FLASH_FW_END_ADDR) - FirstSector + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
306
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
307 /* Fill EraseInit structure*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
308 EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
309 EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
310 EraseInitStruct.Sector = FirstSector;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
311 EraseInitStruct.NbSectors = NbOfSectors;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
312
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
313 /* 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
314 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
315 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
316 DCRST and ICRST bits in the FLASH_CR register. */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
317 return HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
318 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
319
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
320 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
321 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
322 HAL_StatusTypeDef answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
323
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
324 /* Program the user Flash area word by word
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
325 (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
326
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
327 uint32_t ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
328
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
329 Address = FLASH_FW_START_ADDR;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
330
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
331 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
332 while ((Address <= FLASH_FW_END_ADDR) && (ptr < length1))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
333 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
334 answer = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, pBuffer1[ptr]);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
335 if (answer == HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
336 // if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address, DATA_32) == HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
337 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
338 Address = Address + 1;//4;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
339 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
340 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
341 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
342 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
343 return answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
344 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
345 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
346 /* same for pBuffer2
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
347 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
348 while ((Address < FLASH_FW_END_ADDR) && (ptr < length2))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
349 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
350
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
351 if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, pBuffer2[ptr]) == HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
352 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
353 Address = Address + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
354 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
355 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
356 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
357 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
358 firmware_Error_Handler();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
359 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
360 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
361 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
362 /* Lock the Flash to disable the flash control register access (recommended
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
363 to protect the FLASH memory against possible unwanted operation) *********/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
364 HAL_FLASH_Lock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
365
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
366 /* Check if the programmed data is OK
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
367 MemoryProgramStatus = 0: data programmed correctly
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
368 MemoryProgramStatus != 0: number of words not programmed correctly ******/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
369 Address = FLASH_FW_START_ADDR;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
370 MemoryProgramStatus = 0x0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
371
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
372 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
373 while ((Address <= FLASH_FW_END_ADDR) && (ptr < length1))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
374 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
375 data32 = *(__IO uint8_t*)Address;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
376
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
377 if (data32 != pBuffer1[ptr])
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
378 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
379 MemoryProgramStatus++;
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 Address = Address + 1;//4;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
383 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
384 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
385 /* same for pBuffer2
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
386 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
387 while ((Address < FLASH_FW_END_ADDR) && (ptr < length2))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
388 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
389 data32 = *(__IO uint32_t*)Address;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
390
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
391 if (data32 != pBuffer2[ptr])
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
392 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
393 MemoryProgramStatus++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
394 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
395
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
396 Address = Address + 1;//4;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
397 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
398 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
399 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
400 /* Check if there is an issue to program data */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
401 if (MemoryProgramStatus == 0)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
402 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
403 return HAL_OK;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
404 /* No error detected. Switch on LED3 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
405 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
406 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
407 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
408 return 0xEE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
409 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
410
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
411
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
412 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
413
1017
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
414
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
415 uint8_t bootloader_eraseFlashMemory(void)
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
416 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
417 // HAL_StatusTypeDef answer;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
418 /* Unlock the Flash to enable the flash control register access *************/
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
419 HAL_FLASH_Unlock();
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
420
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
421 /* Erase the user Flash area
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
422 (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
423
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
424 /* Get the 1st sector to erase */
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
425 FirstSector = GetSector(FLASH_BOOT_START_ADDR);
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
426 /* Get the number of sector to erase from 1st sector*/
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
427 NbOfSectors = GetSector(FLASH_BOOT_END_ADDR) - FirstSector + 1;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
428
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
429 /* Fill EraseInit structure*/
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
430 EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
431 EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_1;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
432 EraseInitStruct.Sector = FirstSector;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
433 EraseInitStruct.NbSectors = NbOfSectors;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
434
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
435 /* Note: If an erase operation in Flash memory also concerns data in the data or instruction cache,
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
436 you have to make sure that these data are rewritten before they are accessed during code
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
437 execution. If this cannot be done safely, it is recommended to flush the caches by setting the
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
438 DCRST and ICRST bits in the FLASH_CR register. */
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
439 return HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError);
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
440 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
441
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
442 uint8_t bootloader_programFlashMemory(uint8_t *pBuffer1, uint32_t length1, SHardwareData* pHwInfo)
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
443 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
444 HAL_StatusTypeDef answer;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
445
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
446 /* Program the user Flash area word by word
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
447 (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
448
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
449 uint32_t index = 0;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
450 Address = FLASH_BOOT_START_ADDR;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
451
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
452 uint8_t* pHardwareInfo = (uint8_t*) pHwInfo;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
453 uint8_t tmp = 0;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
454
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
455 index = 0;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
456 while ((Address <= FLASH_FW_END_ADDR) && (index < length1))
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
457 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
458 if((Address >= HARDWAREDATA_ADDRESS) && (Address < HARDWAREDATA_ADDRESS + sizeof(SHardwareData)))
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
459 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
460 answer = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, *pHardwareInfo++);
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
461 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
462 else
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
463 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
464 answer = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, pBuffer1[index]);
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
465 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
466 if (answer == HAL_OK)
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
467 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
468 Address = Address + 1;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
469 index++;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
470 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
471 else
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
472 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
473 return answer;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
474 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
475 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
476 /* Lock the Flash to disable the flash control register access (recommended
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
477 to protect the FLASH memory against possible unwanted operation) *********/
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
478 HAL_FLASH_Lock();
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
479
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
480 /* Check if the programmed data is OK
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
481 MemoryProgramStatus = 0: data programmed correctly
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
482 MemoryProgramStatus != 0: number of words not programmed correctly ******/
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
483 Address = FLASH_BOOT_START_ADDR;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
484 MemoryProgramStatus = 0x0;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
485
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
486 index = 0;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
487 pHardwareInfo = (uint8_t*) pHwInfo;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
488
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
489 while ((Address <= FLASH_FW_END_ADDR) && (index < length1))
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
490 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
491 if((Address >= HARDWAREDATA_ADDRESS) && (Address < HARDWAREDATA_ADDRESS + sizeof(SHardwareData)))
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
492 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
493 tmp = *pHardwareInfo++;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
494 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
495 else
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
496 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
497 tmp = pBuffer1[index];
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
498 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
499
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
500 data32 = *(__IO uint8_t*)Address;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
501 if (data32 != tmp)
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
502 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
503 MemoryProgramStatus++;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
504 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
505
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
506 Address = Address + 1;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
507 index++;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
508 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
509 /* Check if there is an issue to program data */
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
510 if (MemoryProgramStatus == 0)
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
511 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
512 return HAL_OK;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
513 /* No error detected. Switch on LED3 */
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
514 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
515 else
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
516 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
517 return 0xEE;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
518 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
519 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
520
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
521
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
522 uint32_t CalcFletcher32(uint32_t startAddr, uint32_t endAddr)
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
523 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
524 uint16_t sum1 = 0;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
525 uint16_t sum2 = 0;
1051
4b6afe5551e1 Refactors CalcFletcher32 in OtherSources/firmwareEraseProgram.c to iterate over 16-bit words via a pointer instead of an index-based loop. Removes unused variables and returns the computed 32-bit Fletcher checksum directly. (mikeller)
heinrichsweikamp
parents: 1017
diff changeset
526 for (uint16_t *index = (uint16_t *)startAddr; index <= (uint16_t *)endAddr; index++) {
4b6afe5551e1 Refactors CalcFletcher32 in OtherSources/firmwareEraseProgram.c to iterate over 16-bit words via a pointer instead of an index-based loop. Removes unused variables and returns the computed 32-bit Fletcher checksum directly. (mikeller)
heinrichsweikamp
parents: 1017
diff changeset
527 sum1 = sum1 + *index;
4b6afe5551e1 Refactors CalcFletcher32 in OtherSources/firmwareEraseProgram.c to iterate over 16-bit words via a pointer instead of an index-based loop. Removes unused variables and returns the computed 32-bit Fletcher checksum directly. (mikeller)
heinrichsweikamp
parents: 1017
diff changeset
528 sum2 = (sum2 + sum1);
1017
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
529 }
1051
4b6afe5551e1 Refactors CalcFletcher32 in OtherSources/firmwareEraseProgram.c to iterate over 16-bit words via a pointer instead of an index-based loop. Removes unused variables and returns the computed 32-bit Fletcher checksum directly. (mikeller)
heinrichsweikamp
parents: 1017
diff changeset
530 return (sum2 << 16) | sum1;
1017
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
531 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
532
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
533
5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
534 /* Private functions ---------------------------------------------------------*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
535
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
536 /**
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
537 * @brief Gets the sector of a given address
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
538 * @param None
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
539 * @retval The sector of a given address
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
540 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
541 static uint32_t GetSector(uint32_t Address)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
542 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
543 uint32_t sector = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
544
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
545 if((Address < ADDR_FLASH_SECTOR_1) && (Address >= ADDR_FLASH_SECTOR_0))
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_0;
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_2) && (Address >= ADDR_FLASH_SECTOR_1))
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_1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
552 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
553 else if((Address < ADDR_FLASH_SECTOR_3) && (Address >= ADDR_FLASH_SECTOR_2))
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_2;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
556 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
557 else if((Address < ADDR_FLASH_SECTOR_4) && (Address >= ADDR_FLASH_SECTOR_3))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
558 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
559 sector = FLASH_SECTOR_3;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
560 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
561 else if((Address < ADDR_FLASH_SECTOR_5) && (Address >= ADDR_FLASH_SECTOR_4))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
562 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
563 sector = FLASH_SECTOR_4;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
564 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
565 else if((Address < ADDR_FLASH_SECTOR_6) && (Address >= ADDR_FLASH_SECTOR_5))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
566 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
567 sector = FLASH_SECTOR_5;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
568 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
569 else if((Address < ADDR_FLASH_SECTOR_7) && (Address >= ADDR_FLASH_SECTOR_6))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
570 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
571 sector = FLASH_SECTOR_6;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
572 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
573 else if((Address < ADDR_FLASH_SECTOR_8) && (Address >= ADDR_FLASH_SECTOR_7))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
574 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
575 sector = FLASH_SECTOR_7;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
576 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
577 else if((Address < ADDR_FLASH_SECTOR_9) && (Address >= ADDR_FLASH_SECTOR_8))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
578 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
579 sector = FLASH_SECTOR_8;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
580 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
581 else if((Address < ADDR_FLASH_SECTOR_10) && (Address >= ADDR_FLASH_SECTOR_9))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
582 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
583 sector = FLASH_SECTOR_9;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
584 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
585 else if((Address < ADDR_FLASH_SECTOR_11) && (Address >= ADDR_FLASH_SECTOR_10))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
586 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
587 sector = FLASH_SECTOR_10;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
588 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
589 else if((Address < ADDR_FLASH_SECTOR_12) && (Address >= ADDR_FLASH_SECTOR_11))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
590 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
591 sector = FLASH_SECTOR_11;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
592 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
593 else if((Address < ADDR_FLASH_SECTOR_13) && (Address >= ADDR_FLASH_SECTOR_12))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
594 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
595 sector = FLASH_SECTOR_12;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
596 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
597 else if((Address < ADDR_FLASH_SECTOR_14) && (Address >= ADDR_FLASH_SECTOR_13))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
598 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
599 sector = FLASH_SECTOR_13;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
600 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
601 else if((Address < ADDR_FLASH_SECTOR_15) && (Address >= ADDR_FLASH_SECTOR_14))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
602 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
603 sector = FLASH_SECTOR_14;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
604 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
605 else if((Address < ADDR_FLASH_SECTOR_16) && (Address >= ADDR_FLASH_SECTOR_15))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
606 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
607 sector = FLASH_SECTOR_15;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
608 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
609 else if((Address < ADDR_FLASH_SECTOR_17) && (Address >= ADDR_FLASH_SECTOR_16))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
610 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
611 sector = FLASH_SECTOR_16;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
612 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
613 else if((Address < ADDR_FLASH_SECTOR_18) && (Address >= ADDR_FLASH_SECTOR_17))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
614 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
615 sector = FLASH_SECTOR_17;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
616 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
617 else if((Address < ADDR_FLASH_SECTOR_19) && (Address >= ADDR_FLASH_SECTOR_18))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
618 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
619 sector = FLASH_SECTOR_18;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
620 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
621 else if((Address < ADDR_FLASH_SECTOR_20) && (Address >= ADDR_FLASH_SECTOR_19))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
622 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
623 sector = FLASH_SECTOR_19;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
624 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
625 else if((Address < ADDR_FLASH_SECTOR_21) && (Address >= ADDR_FLASH_SECTOR_20))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
626 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
627 sector = FLASH_SECTOR_20;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
628 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
629 else if((Address < ADDR_FLASH_SECTOR_22) && (Address >= ADDR_FLASH_SECTOR_21))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
630 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
631 sector = FLASH_SECTOR_21;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
632 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
633 else if((Address < ADDR_FLASH_SECTOR_23) && (Address >= ADDR_FLASH_SECTOR_22))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
634 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
635 sector = FLASH_SECTOR_22;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
636 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
637 else/*(Address < FLASH_END_ADDR) && (Address >= ADDR_FLASH_SECTOR_23))*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
638 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
639 sector = FLASH_SECTOR_23;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
640 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
641
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
642 return sector;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
643 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
644
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
645 /*
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
646 static void firmware_Error_Handler(HAL_StatusTypeDef reason)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
647 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
648 static HAL_StatusTypeDef last_reason = HAL_OK;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
649
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
650 last_reason = reason;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
651 while(1)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
652 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
653 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
654 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
655 */