comparison Discovery/Src/externCPU2bootloader.c @ 300:5ca177d2df5d cleanup-4

cleanup: remove commented/unused code, make static without any functional change. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Fri, 17 May 2019 21:19:04 +0200
parents f64cf099a7f5
children 01f40cb1057e
comparison
equal deleted inserted replaced
299:b70c26be71a0 300:5ca177d2df5d
33 33
34 34
35 /* Exported variables --------------------------------------------------------*/ 35 /* Exported variables --------------------------------------------------------*/
36 36
37 /* Private types -------------------------------------------------------------*/ 37 /* Private types -------------------------------------------------------------*/
38 #define BOOTLOADSPITIMEOUT 5000
39 38
40 /* Private variables ---------------------------------------------------------*/ 39 /* Private variables ---------------------------------------------------------*/
41 40
42 /* Private function prototypes -----------------------------------------------*/ 41 /* Private function prototypes -----------------------------------------------*/
43 42
44 uint8_t boot_sync_frame(void); 43 static uint8_t boot_sync_frame(void);
45 uint8_t boot_ack(void); 44 static uint8_t boot_ack(void);
46 uint8_t boot_get(uint8_t *RxBuffer); 45 static uint8_t boot_get_id(uint8_t *RxBuffer);
47 uint8_t boot_get_id(uint8_t *RxBuffer); 46 static uint8_t boot_get_version(uint8_t *RxBuffer);
48 uint8_t boot_get_version(uint8_t *RxBuffer); 47 static uint8_t boot_write_memory(uint32_t address, uint8_t length_minus_1, uint8_t *data);
49 //uint8_t boot_go(uint32_t address); 48 static uint8_t boot_erase_memory(void);
50 uint8_t boot_write_memory(uint32_t address, uint8_t length_minus_1, uint8_t *data); 49 static void Bootloader_send_command(uint8_t command);
51 //uint8_t boot_erase_memory(uint16_t data_frame, uint16_t *page_numbers); 50 static void Bootloader_spi_single(uint8_t TxByte);
52 uint8_t boot_erase_memory(void); 51 static void Bootloader_spi(uint16_t lengthData, uint8_t *aTxBuffer, uint8_t *aRxBuffer);
53 uint8_t boot_write_protect(uint8_t number_of_sectors_minus_one, uint8_t *sector_codes); 52 static void Bootloader_Error_Handler(void);
54 /*
55 uint8_t boot_write_unprotect(void);
56 uint8_t boot_readout_protect(void);
57 uint8_t boot_readout_unprotect(void);
58 */
59 void Bootoader_send_command(uint8_t command);
60 void Bootloader_spi_single(uint8_t TxByte);
61 void Bootloader_spi(uint16_t lengthData, uint8_t *aTxBuffer, uint8_t *aRxBuffer);
62 void Bootloader_Error_Handler(void);
63 53
64 /* Exported functions --------------------------------------------------------*/ 54 /* Exported functions --------------------------------------------------------*/
65 55
66 uint8_t extCPU2bootloader_start(uint8_t *version, uint16_t *chipID) 56 uint8_t extCPU2bootloader_start(uint8_t *version, uint16_t *chipID)
67 { 57 {
68 // uint8_t aTxBuffer[256] = { 0 };
69 uint8_t aRxBuffer[256] = { 0 }; 58 uint8_t aRxBuffer[256] = { 0 };
70 59
71 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_RESET); 60 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_RESET);
72 61
73 boot_sync_frame(); 62 boot_sync_frame();
87 76
88 uint8_t extCPU2bootloader_internal(uint8_t* buffer, uint32_t length, char* display_text) 77 uint8_t extCPU2bootloader_internal(uint8_t* buffer, uint32_t length, char* display_text)
89 { 78 {
90 uint8_t version = 0; 79 uint8_t version = 0;
91 uint16_t chipID = 0; 80 uint16_t chipID = 0;
92 // uint8_t ret; 81
93 if(!extCPU2bootloader_start(&version,&chipID)) 82 if(!extCPU2bootloader_start(&version,&chipID))
94 return 0; 83 return 0;
95 if(!boot_erase_memory()) 84 if(!boot_erase_memory())
96 return 0; 85 return 0;
97 HAL_Delay(100); 86 HAL_Delay(100);
133 return result; 122 return result;
134 } 123 }
135 124
136 /* Private functions --------------------------------------------------------*/ 125 /* Private functions --------------------------------------------------------*/
137 126
138 uint8_t boot_sync_frame(void) 127 static uint8_t boot_sync_frame(void)
139 { 128 {
140 Bootloader_spi_single(0x5a); 129 Bootloader_spi_single(0x5a);
141 return boot_ack(); 130 return boot_ack();
142 } 131 }
143 132
144 133 static uint8_t boot_get_version(uint8_t *RxBuffer)
145 uint8_t boot_get(uint8_t *RxBuffer) 134 {
146 { 135 Bootloader_spi_single(0x5a);
147 Bootloader_spi_single(0x5a); 136 Bootloader_send_command(0x01);
148 Bootoader_send_command(0x00);
149 if(!boot_ack())
150 return 0;
151 Bootloader_spi(14, NULL, RxBuffer);
152 return boot_ack();
153 }
154
155
156 uint8_t boot_get_version(uint8_t *RxBuffer)
157 {
158 Bootloader_spi_single(0x5a);
159 Bootoader_send_command(0x01);
160 if(!boot_ack()) 137 if(!boot_ack())
161 return 0; 138 return 0;
162 Bootloader_spi(3, NULL, RxBuffer); 139 Bootloader_spi(3, NULL, RxBuffer);
163 return boot_ack(); 140 return boot_ack();
164 } 141 }
165 142
166 143
167 uint8_t boot_get_id(uint8_t *RxBuffer) 144 static uint8_t boot_get_id(uint8_t *RxBuffer)
168 { 145 {
169 Bootloader_spi_single(0x5a); 146 Bootloader_spi_single(0x5a);
170 Bootoader_send_command(0x02); 147 Bootloader_send_command(0x02);
171 if(!boot_ack()) 148 if(!boot_ack())
172 return 0; 149 return 0;
173 Bootloader_spi(5, NULL, RxBuffer); 150 Bootloader_spi(5, NULL, RxBuffer);
174 return boot_ack(); 151 return boot_ack();
175 } 152 }
176
177 /*
178 uint8_t boot_go(uint32_t address)
179 {
180
181 }
182 */
183 153
184 154
185 uint8_t boot_write_memory(uint32_t address, uint8_t length_minus_1, uint8_t *data) 155 uint8_t boot_write_memory(uint32_t address, uint8_t length_minus_1, uint8_t *data)
186 { 156 {
187 uint8_t addressNew[4]; 157 uint8_t addressNew[4];
188 uint8_t checksum = 0; 158 uint8_t checksum = 0;
189 uint16_t length; 159 uint16_t length;
190 160
191 Bootloader_spi_single(0x5a); 161 Bootloader_spi_single(0x5a);
192 Bootoader_send_command(0x31); 162 Bootloader_send_command(0x31);
193 if(!boot_ack()) 163 if(!boot_ack())
194 return 1; 164 return 1;
195 HAL_Delay(5); 165 HAL_Delay(5);
196 addressNew[0] = (uint8_t)((address >> 24) & 0xFF); 166 addressNew[0] = (uint8_t)((address >> 24) & 0xFF);
197 addressNew[1] = (uint8_t)((address >> 16) & 0xFF); 167 addressNew[1] = (uint8_t)((address >> 16) & 0xFF);
221 return 0; 191 return 0;
222 HAL_Delay(1); 192 HAL_Delay(1);
223 return 1; 193 return 1;
224 } 194 }
225 195
226 //uint8_t boot_erase_memory(uint16_t data_frame, uint16_t *page_numbers) 196 static uint8_t boot_erase_memory(void)
227 uint8_t boot_erase_memory(void)
228 { 197 {
229 uint8_t special_erase_with_checksum[3] = {0xFF, 0xFF, 0x00}; 198 uint8_t special_erase_with_checksum[3] = {0xFF, 0xFF, 0x00};
230 199
231 Bootloader_spi_single(0x5a); 200 Bootloader_spi_single(0x5a);
232 Bootoader_send_command(0x44); 201 Bootloader_send_command(0x44);
233 if(!boot_ack()) 202 if(!boot_ack())
234 return 0; 203 return 0;
235 Bootloader_spi(3, special_erase_with_checksum, NULL); 204 Bootloader_spi(3, special_erase_with_checksum, NULL);
236 HAL_Delay(11000); /* 5.5 to 11 seconds */ 205 HAL_Delay(11000); /* 5.5 to 11 seconds */
237 if(!boot_ack()) 206 if(!boot_ack())
241 210
242 /* write unprotect does reset the system !! */ 211 /* write unprotect does reset the system !! */
243 uint8_t boot_write_unprotect(void) 212 uint8_t boot_write_unprotect(void)
244 { 213 {
245 Bootloader_spi_single(0x5a); 214 Bootloader_spi_single(0x5a);
246 Bootoader_send_command(0x73); 215 Bootloader_send_command(0x73);
247 if(!boot_ack()) 216 if(!boot_ack())
248 return 0; 217 return 0;
249 return boot_ack(); 218 return boot_ack();
250 } 219 }
251 220
252 /* 221 static uint8_t boot_ack(void)
253 uint8_t boot_write_protect(uint8_t number_of_sectors_minus_one, uint8_t *sector_codes)
254 {
255
256 }
257
258 uint8_t boot_readout_protect(void)
259 {
260
261 }
262
263 uint8_t boot_readout_unprotect(void)
264 {
265
266 }
267 */
268
269 uint8_t boot_ack(void)
270 { 222 {
271 uint8_t answer = 0; 223 uint8_t answer = 0;
272 224
273 Bootloader_spi_single(0x00); 225 Bootloader_spi_single(0x00);
274 for(int i=0; i< 1000; i++) 226 for(int i=0; i< 1000; i++)
285 return 1; 237 return 1;
286 else 238 else
287 return 0; 239 return 0;
288 } 240 }
289 241
290 void Bootoader_send_command(uint8_t command) 242 static void Bootloader_send_command(uint8_t command)
291 { 243 {
292 uint8_t send[2]; 244 uint8_t send[2];
293 uint8_t receive[2]; 245 uint8_t receive[2];
294 246
295 send[0] = command; 247 send[0] = command;
296 send[1] = 0xFF ^ command; 248 send[1] = 0xFF ^ command;
297 Bootloader_spi(2, send, receive); 249 Bootloader_spi(2, send, receive);
298 } 250 }
299 251
300 void Bootloader_spi_single(uint8_t TxByte) 252 static void Bootloader_spi_single(uint8_t TxByte)
301 { 253 {
302 Bootloader_spi(1,&TxByte, 0); 254 Bootloader_spi(1,&TxByte, 0);
303 } 255 }
304 256
305 257
306 void Bootloader_spi(uint16_t lengthData, uint8_t *aTxBuffer, uint8_t *aRxBuffer) 258 static void Bootloader_spi(uint16_t lengthData, uint8_t *aTxBuffer, uint8_t *aRxBuffer)
307 { 259 {
308 uint8_t dummy[256] = { 0 }; 260 uint8_t dummy[256] = { 0 };
309 uint8_t *tx_data; 261 uint8_t *tx_data;
310 uint8_t *rx_data; 262 uint8_t *rx_data;
311 263
332 HAL_GPIO_WritePin(OSCILLOSCOPE_GPIO_PORT,OSCILLOSCOPE_PIN,GPIO_PIN_SET); // only for testing with Oscilloscope 284 HAL_GPIO_WritePin(OSCILLOSCOPE_GPIO_PORT,OSCILLOSCOPE_PIN,GPIO_PIN_SET); // only for testing with Oscilloscope
333 */ 285 */
334 } 286 }
335 287
336 288
337 void Bootloader_Error_Handler(void) 289 static void Bootloader_Error_Handler(void)
338 { 290 {
339 while(1); 291 while(1);
340 } 292 }
341
342
343