annotate OtherSources/firmwareEraseProgram.c @ 1028:3d9552e4997c GasConsumption

Code improvment: line <=> menu id function: In generell the structure of the menus is defined by the tStructure.h using global state defines. In some implementation hardcoded line numbers are used. Risk: In case the order of menu items change the update of other code sections could be forgotten (in the case the update of the top menu) causing unintended behavior. To avoid this the hard coded lines have been replaced by a function connecting the intended function to the menu item defined in the tstructure.h.
author Ideenmodellierer
date Sun, 07 Sep 2025 19:08:43 +0200
parents 5924a2d1d3ba
children 4b6afe5551e1
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
1017
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
86 #define FLASH_BOOT_START_ADDR ADDR_FLASH_SECTOR_0
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
87 #define FLASH_BOOT_END_ADDR (ADDR_FLASH_SECTOR_5 - 1)
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
88
5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
89 #define FLASH_FW_START_ADDR ADDR_FLASH_SECTOR_6
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
90 #define FLASH_FW_END_ADDR (ADDR_FLASH_SECTOR_12 - 1)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
91
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
92 #define FLASH_FW2_START_ADDR ADDR_FLASH_SECTOR_12
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
93 #define FLASH_FW2_END_ADDR (ADDR_FLASH_SECTOR_22 + SECTOR_SIZE_128KB - 1)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
94
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
95 /* Private variables ---------------------------------------------------------*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
96
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
97 static FLASH_EraseInitTypeDef EraseInitStruct; /*Variable used for Erase procedure*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
98
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
99 uint32_t FirstSector = 0, NbOfSectors = 0, Address = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
100 uint32_t SectorError = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
101 __IO uint32_t data32 = 0 , MemoryProgramStatus = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
102
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 /* Private function prototypes -----------------------------------------------*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
106 //static void firmware_Error_Handler(HAL_StatusTypeDef reason);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
107 static uint32_t GetSector(uint32_t Address);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
108 uint8_t hardware_programm_sub(uint8_t *buffer64, uint8_t length, uint32_t startAddress);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
109
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
110 /* Exported functions --------------------------------------------------------*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
111
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
112 const SHardwareData* hardwareDataGetPointer(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
113 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
114 return (SHardwareData*)HARDWAREDATA_ADDRESS;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
115 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
116
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
117 uint8_t hardware_programmPrimaryBluetoothNameSet(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
118 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
119 uint8_t data = 0xF0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
120 return hardware_programm_sub(&data, 1, HARDWAREDATA_ADDRESS + 7);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
121 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
122
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
123
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
124 uint8_t hardware_programmSecondaryBluetoothNameSet(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
125 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
126 uint8_t data = 0xF0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
127 return hardware_programm_sub(&data, 1, HARDWAREDATA_ADDRESS + 52 + 7);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
128 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
129
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
130
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
131 uint8_t hardware_programmProductionData(uint8_t *buffer52)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
132 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
133 buffer52[7] = 0xFF;// production_bluetooth_name_set
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
134 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
135 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
136
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
137
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
138 uint8_t hardware_programmSecondarySerial(uint8_t *buffer12)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
139 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
140 buffer12[7] = 0xFF;// secondary_bluetooth_name_set
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
141 return hardware_programm_sub(buffer12, 12, HARDWAREDATA_ADDRESS + 52);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
142 }
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 uint8_t hardware_programm_sub(uint8_t *buffer, uint8_t length, uint32_t startAddress)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
146 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
147 HAL_StatusTypeDef answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
148
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
149 uint32_t ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
150 uint8_t data8;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
151
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
152 // test empty
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
153 Address = startAddress;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
154 for(int i=0;i<length;i++)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
155 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
156 if((*(uint8_t *)Address != 0xFF) && (buffer[i] != 0xFF))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
157 return 0xE0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
158 Address = Address + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
159 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
160
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
161 // start programming
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
162 HAL_FLASH_Unlock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
163
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
164 Address = startAddress;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
165 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
166 answer = HAL_OK;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
167 while (ptr < length)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
168 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
169 if(buffer[ptr] != 0xFF)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
170 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
171 answer = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, buffer[ptr]);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
172 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
173 if (answer == HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
174 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
175 Address = Address + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
176 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
177 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
178 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
179 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
180 HAL_FLASH_Lock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
181 return answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
182 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
183 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
184 HAL_FLASH_Lock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
185
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
186 /* Check if the programmed data is OK
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
187 MemoryProgramStatus = 0: data programmed correctly
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
188 MemoryProgramStatus != 0: number of words not programmed correctly ******/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
189 Address = startAddress; // check base_bootloader.c of OSTC4bootloader code
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
190 MemoryProgramStatus = 0x0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
191
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
192 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
193 while(ptr < length)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
194 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
195 data8 = *(__IO uint8_t*)Address;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
196
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
197 if((buffer[ptr] != 0xFF) && (data8 != buffer[ptr]))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
198 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
199 MemoryProgramStatus++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
200 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
201
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
202 Address = Address + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
203 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
204 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
205
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
206 /* Check if there is an issue to program data */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
207 if (MemoryProgramStatus == 0)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
208 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
209 return HAL_OK;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
210 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
211 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
212 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
213 return 0xEE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
214 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
215 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
216
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
217
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
218 uint8_t firmware2_variable_upperpart_eraseFlashMemory(uint32_t length, uint32_t offset)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
219 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
220 uint32_t startAddress, endAddress;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
221
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
222 // HAL_StatusTypeDef answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
223 HAL_FLASH_Unlock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
224
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
225 startAddress = FLASH_FW2_START_ADDR + offset;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
226 endAddress = startAddress + length;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
227
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
228 if(endAddress > FLASH_FW2_END_ADDR)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
229 endAddress = FLASH_FW2_END_ADDR;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
230
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
231 FirstSector = GetSector(startAddress);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
232 NbOfSectors = GetSector(endAddress) - FirstSector + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
233
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
234 EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
235 EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
236 EraseInitStruct.Sector = FirstSector;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
237 EraseInitStruct.NbSectors = NbOfSectors;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
238
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
239 return HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
240 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
241
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
242
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
243 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
244 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
245 HAL_StatusTypeDef answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
246 uint32_t ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
247 uint32_t length1, length2;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
248
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
249 if((pBuffer2) && (length > pBuffer1Size))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
250 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
251 length1 = pBuffer1Size;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
252 length2 = length - length1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
253 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
254 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
255 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
256 length1 = length;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
257 length2 = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
258 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
259
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
260 Address = FLASH_FW2_START_ADDR + offset;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
261
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
262 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
263 while ((Address <= FLASH_FW2_END_ADDR) && (ptr < length1))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
264 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
265 answer = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, pBuffer1[ptr]);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
266 if (answer == HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
267 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
268 Address = Address + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
269 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
270 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
271 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
272 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
273 return answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
274 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
275 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
276 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
277 while ((Address <= FLASH_FW2_END_ADDR) && (ptr < length2))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
278 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
279 answer = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, pBuffer2[ptr]);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
280 if (answer == HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
281 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
282 Address = Address + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
283 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
284 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
285 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
286 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
287 return answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
288 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
289 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
290 HAL_FLASH_Lock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
291
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
292 Address = FLASH_FW2_START_ADDR + offset;;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
293 MemoryProgramStatus = 0x0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
294
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
295 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
296 while ((Address <= FLASH_FW2_END_ADDR) && (ptr < length1))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
297 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
298 data32 = *(__IO uint8_t*)Address;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
299
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
300 if (data32 != pBuffer1[ptr])
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
301 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
302 MemoryProgramStatus++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
303 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
304
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
305 Address = Address + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
306 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
307 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
308 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
309 while ((Address <= FLASH_FW2_END_ADDR) && (ptr < length2))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
310 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
311 data32 = *(__IO uint8_t*)Address;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
312
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
313 if (data32 != pBuffer2[ptr])
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
314 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
315 MemoryProgramStatus++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
316 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
317
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
318 Address = Address + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
319 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
320 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
321
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
322 if (MemoryProgramStatus == 0)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
323 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
324 return HAL_OK;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
325 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
326 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
327 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
328 return 0xEE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
329 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
330 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
331
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
332 uint8_t firmware_eraseFlashMemory(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
333 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
334 // HAL_StatusTypeDef answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
335 /* Unlock the Flash to enable the flash control register access *************/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
336 HAL_FLASH_Unlock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
337
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
338 /* Erase the user Flash area
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
339 (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
340
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
341 /* Get the 1st sector to erase */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
342 FirstSector = GetSector(FLASH_FW_START_ADDR);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
343 /* Get the number of sector to erase from 1st sector*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
344 NbOfSectors = GetSector(FLASH_FW_END_ADDR) - FirstSector + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
345
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
346 /* Fill EraseInit structure*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
347 EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
348 EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
349 EraseInitStruct.Sector = FirstSector;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
350 EraseInitStruct.NbSectors = NbOfSectors;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
351
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
352 /* 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
353 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
354 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
355 DCRST and ICRST bits in the FLASH_CR register. */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
356 return HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
357 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
358
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
359 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
360 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
361 HAL_StatusTypeDef answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
362
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
363 /* Program the user Flash area word by word
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
364 (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
365
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
366 uint32_t ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
367
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
368 Address = FLASH_FW_START_ADDR;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
369
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
370 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
371 while ((Address <= FLASH_FW_END_ADDR) && (ptr < length1))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
372 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
373 answer = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, pBuffer1[ptr]);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
374 if (answer == HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
375 // if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address, DATA_32) == HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
376 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
377 Address = Address + 1;//4;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
378 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
379 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
380 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
381 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
382 return answer;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
383 }
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
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
390 if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, pBuffer2[ptr]) == HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
391 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
392 Address = Address + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
393 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
394 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
395 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
396 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
397 firmware_Error_Handler();
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 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
401 /* Lock the Flash to disable the flash control register access (recommended
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
402 to protect the FLASH memory against possible unwanted operation) *********/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
403 HAL_FLASH_Lock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
404
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
405 /* Check if the programmed data is OK
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
406 MemoryProgramStatus = 0: data programmed correctly
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
407 MemoryProgramStatus != 0: number of words not programmed correctly ******/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
408 Address = FLASH_FW_START_ADDR;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
409 MemoryProgramStatus = 0x0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
410
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
411 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
412 while ((Address <= FLASH_FW_END_ADDR) && (ptr < length1))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
413 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
414 data32 = *(__IO uint8_t*)Address;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
415
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
416 if (data32 != pBuffer1[ptr])
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
417 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
418 MemoryProgramStatus++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
419 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
420
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
421 Address = Address + 1;//4;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
422 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
423 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
424 /* same for pBuffer2
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
425 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
426 while ((Address < FLASH_FW_END_ADDR) && (ptr < length2))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
427 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
428 data32 = *(__IO uint32_t*)Address;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
429
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
430 if (data32 != pBuffer2[ptr])
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
431 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
432 MemoryProgramStatus++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
433 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
434
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
435 Address = Address + 1;//4;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
436 ptr++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
437 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
438 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
439 /* Check if there is an issue to program data */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
440 if (MemoryProgramStatus == 0)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
441 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
442 return HAL_OK;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
443 /* No error detected. Switch on LED3 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
444 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
445 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
446 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
447 return 0xEE;
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
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
451 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
452
1017
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
453
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
454 uint8_t bootloader_eraseFlashMemory(void)
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
455 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
456 // HAL_StatusTypeDef answer;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
457 /* Unlock the Flash to enable the flash control register access *************/
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
458 HAL_FLASH_Unlock();
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
459
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
460 /* Erase the user Flash area
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
461 (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
462
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
463 /* Get the 1st sector to erase */
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
464 FirstSector = GetSector(FLASH_BOOT_START_ADDR);
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
465 /* Get the number of sector to erase from 1st sector*/
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
466 NbOfSectors = GetSector(FLASH_BOOT_END_ADDR) - FirstSector + 1;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
467
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
468 /* Fill EraseInit structure*/
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
469 EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
470 EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_1;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
471 EraseInitStruct.Sector = FirstSector;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
472 EraseInitStruct.NbSectors = NbOfSectors;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
473
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
474 /* 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
475 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
476 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
477 DCRST and ICRST bits in the FLASH_CR register. */
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
478 return HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError);
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
479 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
480
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
481 uint8_t bootloader_programFlashMemory(uint8_t *pBuffer1, uint32_t length1, SHardwareData* pHwInfo)
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
482 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
483 HAL_StatusTypeDef answer;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
484
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
485 /* Program the user Flash area word by word
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
486 (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
487
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
488 uint32_t index = 0;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
489 Address = FLASH_BOOT_START_ADDR;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
490
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
491 uint8_t* pHardwareInfo = (uint8_t*) pHwInfo;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
492 uint8_t tmp = 0;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
493
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
494 index = 0;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
495 while ((Address <= FLASH_FW_END_ADDR) && (index < length1))
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
496 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
497 if((Address >= HARDWAREDATA_ADDRESS) && (Address < HARDWAREDATA_ADDRESS + sizeof(SHardwareData)))
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
498 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
499 answer = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, *pHardwareInfo++);
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
500 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
501 else
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
502 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
503 answer = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, pBuffer1[index]);
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
504 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
505 if (answer == HAL_OK)
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
506 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
507 Address = Address + 1;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
508 index++;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
509 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
510 else
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 answer;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
513 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
514 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
515 /* Lock the Flash to disable the flash control register access (recommended
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
516 to protect the FLASH memory against possible unwanted operation) *********/
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
517 HAL_FLASH_Lock();
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
518
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
519 /* Check if the programmed data is OK
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
520 MemoryProgramStatus = 0: data programmed correctly
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
521 MemoryProgramStatus != 0: number of words not programmed correctly ******/
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
522 Address = FLASH_BOOT_START_ADDR;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
523 MemoryProgramStatus = 0x0;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
524
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
525 index = 0;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
526 pHardwareInfo = (uint8_t*) pHwInfo;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
527
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
528 while ((Address <= FLASH_FW_END_ADDR) && (index < length1))
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
529 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
530 if((Address >= HARDWAREDATA_ADDRESS) && (Address < HARDWAREDATA_ADDRESS + sizeof(SHardwareData)))
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
531 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
532 tmp = *pHardwareInfo++;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
533 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
534 else
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
535 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
536 tmp = pBuffer1[index];
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
537 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
538
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
539 data32 = *(__IO uint8_t*)Address;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
540 if (data32 != tmp)
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
541 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
542 MemoryProgramStatus++;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
543 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
544
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
545 Address = Address + 1;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
546 index++;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
547 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
548 /* Check if there is an issue to program data */
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
549 if (MemoryProgramStatus == 0)
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
550 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
551 return HAL_OK;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
552 /* No error detected. Switch on LED3 */
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
553 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
554 else
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
555 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
556 return 0xEE;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
557 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
558 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
559
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
560
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
561 uint32_t CalcFletcher32(uint32_t startAddr, uint32_t endAddr)
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
562 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
563 uint32_t fletcher = 0;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
564 uint16_t* pData = (uint16_t*) startAddr;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
565 uint32_t index = 0;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
566
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
567 uint16_t sum1 = 0;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
568 uint16_t sum2 = 0;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
569 for(index = startAddr; index <= endAddr; index +=2)
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
570 {
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
571 sum1 = sum1 + *pData++;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
572 sum2 = (sum2 + sum1);
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
573 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
574 fletcher = (sum2 << 16) | sum1;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
575
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
576 return fletcher;
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
577 }
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
578
5924a2d1d3ba Prepare custom block update function:
Ideenmodellierer
parents: 36
diff changeset
579
5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
580 /* Private functions ---------------------------------------------------------*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
581
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
582 /**
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
583 * @brief Gets the sector of a given address
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
584 * @param None
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
585 * @retval The sector of a given address
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
586 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
587 static uint32_t GetSector(uint32_t Address)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
588 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
589 uint32_t sector = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
590
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
591 if((Address < ADDR_FLASH_SECTOR_1) && (Address >= ADDR_FLASH_SECTOR_0))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
592 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
593 sector = FLASH_SECTOR_0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
594 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
595 else if((Address < ADDR_FLASH_SECTOR_2) && (Address >= ADDR_FLASH_SECTOR_1))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
596 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
597 sector = FLASH_SECTOR_1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
598 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
599 else if((Address < ADDR_FLASH_SECTOR_3) && (Address >= ADDR_FLASH_SECTOR_2))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
600 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
601 sector = FLASH_SECTOR_2;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
602 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
603 else if((Address < ADDR_FLASH_SECTOR_4) && (Address >= ADDR_FLASH_SECTOR_3))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
604 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
605 sector = FLASH_SECTOR_3;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
606 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
607 else if((Address < ADDR_FLASH_SECTOR_5) && (Address >= ADDR_FLASH_SECTOR_4))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
608 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
609 sector = FLASH_SECTOR_4;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
610 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
611 else if((Address < ADDR_FLASH_SECTOR_6) && (Address >= ADDR_FLASH_SECTOR_5))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
612 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
613 sector = FLASH_SECTOR_5;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
614 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
615 else if((Address < ADDR_FLASH_SECTOR_7) && (Address >= ADDR_FLASH_SECTOR_6))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
616 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
617 sector = FLASH_SECTOR_6;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
618 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
619 else if((Address < ADDR_FLASH_SECTOR_8) && (Address >= ADDR_FLASH_SECTOR_7))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
620 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
621 sector = FLASH_SECTOR_7;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
622 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
623 else if((Address < ADDR_FLASH_SECTOR_9) && (Address >= ADDR_FLASH_SECTOR_8))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
624 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
625 sector = FLASH_SECTOR_8;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
626 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
627 else if((Address < ADDR_FLASH_SECTOR_10) && (Address >= ADDR_FLASH_SECTOR_9))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
628 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
629 sector = FLASH_SECTOR_9;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
630 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
631 else if((Address < ADDR_FLASH_SECTOR_11) && (Address >= ADDR_FLASH_SECTOR_10))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
632 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
633 sector = FLASH_SECTOR_10;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
634 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
635 else if((Address < ADDR_FLASH_SECTOR_12) && (Address >= ADDR_FLASH_SECTOR_11))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
636 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
637 sector = FLASH_SECTOR_11;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
638 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
639 else if((Address < ADDR_FLASH_SECTOR_13) && (Address >= ADDR_FLASH_SECTOR_12))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
640 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
641 sector = FLASH_SECTOR_12;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
642 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
643 else if((Address < ADDR_FLASH_SECTOR_14) && (Address >= ADDR_FLASH_SECTOR_13))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
644 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
645 sector = FLASH_SECTOR_13;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
646 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
647 else if((Address < ADDR_FLASH_SECTOR_15) && (Address >= ADDR_FLASH_SECTOR_14))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
648 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
649 sector = FLASH_SECTOR_14;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
650 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
651 else if((Address < ADDR_FLASH_SECTOR_16) && (Address >= ADDR_FLASH_SECTOR_15))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
652 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
653 sector = FLASH_SECTOR_15;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
654 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
655 else if((Address < ADDR_FLASH_SECTOR_17) && (Address >= ADDR_FLASH_SECTOR_16))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
656 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
657 sector = FLASH_SECTOR_16;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
658 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
659 else if((Address < ADDR_FLASH_SECTOR_18) && (Address >= ADDR_FLASH_SECTOR_17))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
660 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
661 sector = FLASH_SECTOR_17;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
662 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
663 else if((Address < ADDR_FLASH_SECTOR_19) && (Address >= ADDR_FLASH_SECTOR_18))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
664 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
665 sector = FLASH_SECTOR_18;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
666 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
667 else if((Address < ADDR_FLASH_SECTOR_20) && (Address >= ADDR_FLASH_SECTOR_19))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
668 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
669 sector = FLASH_SECTOR_19;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
670 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
671 else if((Address < ADDR_FLASH_SECTOR_21) && (Address >= ADDR_FLASH_SECTOR_20))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
672 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
673 sector = FLASH_SECTOR_20;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
674 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
675 else if((Address < ADDR_FLASH_SECTOR_22) && (Address >= ADDR_FLASH_SECTOR_21))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
676 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
677 sector = FLASH_SECTOR_21;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
678 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
679 else if((Address < ADDR_FLASH_SECTOR_23) && (Address >= ADDR_FLASH_SECTOR_22))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
680 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
681 sector = FLASH_SECTOR_22;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
682 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
683 else/*(Address < FLASH_END_ADDR) && (Address >= ADDR_FLASH_SECTOR_23))*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
684 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
685 sector = FLASH_SECTOR_23;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
686 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
687
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
688 return sector;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
689 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
690
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
691 /*
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
692 static void firmware_Error_Handler(HAL_StatusTypeDef reason)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
693 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
694 static HAL_StatusTypeDef last_reason = HAL_OK;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
695
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
696 last_reason = reason;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
697 while(1)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
698 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
699 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
700 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
701 */