Mercurial > public > ostc4
annotate BootLoader/Src/base_bootlader.c @ 961:2130d771c8db Evo_2_23
Bootloader: Activate Hardware data defaults:
The hardware data was not part of the build to avoid overwriting of existing data. For initial HW bringup the data is now active (define 0xFF values) and placed at the correct flash location (allocation was missing before).
author | Ideenmodellierer |
---|---|
date | Sun, 12 Jan 2025 19:15:20 +0100 |
parents | a8c0e6d07b8e |
children | aef5fb824675 |
rev | line source |
---|---|
30 | 1 /////////////////////////////////////////////////////////////////////////////// |
2 /// -*- coding: UTF-8 -*- | |
3 /// | |
4 /// \file BootLoader/Src/base_bootlader.c | |
5 /// \brief he beginning of it all. main() is part of this. | |
36 | 6 /// \author heinrichs weikamp gmbh |
30 | 7 /// \date 26-February-2014 |
8 /// | |
9 /// $Id$ | |
10 /////////////////////////////////////////////////////////////////////////////// | |
11 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh | |
12 /// | |
13 /// This program is free software: you can redistribute it and/or modify | |
14 /// it under the terms of the GNU General Public License as published by | |
15 /// the Free Software Foundation, either version 3 of the License, or | |
16 /// (at your option) any later version. | |
17 /// | |
18 /// This program is distributed in the hope that it will be useful, | |
19 /// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 /// GNU General Public License for more details. | |
22 /// | |
23 /// You should have received a copy of the GNU General Public License | |
24 /// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
25 ////////////////////////////////////////////////////////////////////////////// | |
26 /** | |
27 * @detail The beginning of it all. main() is part of this. | |
28 * + Do the inits for hardware | |
29 * + check for button press or update process reset trigger | |
30 * + Do the inits for sub-systems like menu, dive screen etc. | |
31 * + Start IRQs | |
32 * + Start MainTasks not in IRQs | |
33 * @bug | |
34 * @warning | |
35 @verbatim | |
36 | |
37 ============================================================================== | |
38 ##### bootloader specific ##### | |
39 ============================================================================== | |
40 | |
36 | 41 151130 hw sleep on button3 |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
42 (MX_tell_reset_logik_alles_ok() + DataEX_call() in endless loop) |
30 | 43 |
44 ============================================================================== | |
45 ##### bootloader specific ##### | |
46 ============================================================================== | |
47 | |
48 Bootloader info is set right here in this file. | |
49 The location is 0x0800A000 instead of 0x08050000 (firmware) | |
50 | |
51 on system reset (Menu Start Bootloader in firmware) the update process | |
52 is started automatically if no button is pressed | |
53 | |
54 if the right button is pressed the bootloader menu is started | |
55 | |
56 after update process (with update or empty) cleaning of EEPROM is started | |
57 afterwards the watchdog reset starts without activating the update process | |
58 | |
59 bluetooth chip is started in tComm on start of the mini bootloader firmware | |
60 | |
61 SMALLCPU_CSB_PIN must be re-set to 0 to communicate with small CPU / CPU2 / RTE | |
62 | |
63 for RealTerm to send file / firmware, Delays has to be increased to 0 | |
64 | |
65 RTE update / SPI1 with DMA gave IBUSERR, now it is working fine :-) 150828 | |
66 ============================================================================== | |
67 from standard firmware, parts might be invalid here: | |
68 ============================================================================== | |
69 ##### IRQs ##### | |
70 ============================================================================== | |
71 [..] The IRQs are very important and most functions should only run there. | |
72 | |
73 PreemptPriority are as follows | |
74 (#) 2 (low) sprintf _only_ here. Don't use in maintask or anywhere else. | |
75 Called by Buttons und Timer3 | |
76 Timer3 is 1/10 second | |
77 (#) 1 (mid) anything that should work while in IRQ2 like HalDelay(), VSYNC | |
78 and DMA2D Transfer Complete for housekeepingFrame(); | |
79 (#) 0 (high) _very very short_ interrupts like The HAL hardware part for | |
80 spi, uart, i2c. | |
81 | |
82 SubPriority within PreemptPriority give the order to execute. | |
83 Introduced 30.Oct.14 as it used by several HAL examples. | |
84 Three levelAmbients are available (2 low,1 mid,0 high) | |
85 | |
86 The STM32F4 has 4bits for IRQ levelAmbients, divided 2/2 in this code | |
87 with the NVIC_PRIORITYGROUP_2 setting. | |
88 | |
89 ============================================================================== | |
90 ##### MainTask ##### | |
91 ============================================================================== | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
92 [..] For everything slow without importance to be 'in time'. |
30 | 93 Like VPM and Buehlmann. |
94 No sprintf and probably no GFX_SetFramesTopBottom() stuff neither. | |
95 If sprintf is called while sprintf is executed it blows up everything. | |
96 | |
97 ============================================================================== | |
98 ##### Frames / the external SDRAM ##### | |
99 ============================================================================== | |
100 [..] The SDRAM is handled by getFrame() and releaseFrame(). | |
101 Each frame with 800*480*2 Bytes. | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
102 Be careful to release every frame |
30 | 103 otherwise there will be a memory leakage over time. |
104 housekeepingFrame() in the MainTask takes care of cleaning the frames. | |
105 All frames are filled with 0x00. This will be transparent with color of | |
106 CLUT_Font020 (is CLUT 0) if the alpha is set for a 16bit pair. | |
107 housekeepingFrame() delays the cleaning of frames still used as screen | |
108 buffer to prevent flickering. | |
109 | |
110 ============================================================================== | |
111 ##### Display ##### | |
112 ============================================================================== | |
113 [..] There is a Top layer, Bottom layer and background color. | |
114 All are perfectly alpha-blended by hardware. | |
115 | |
116 (#) top layer has 800x480 option function calls only | |
117 as it is not used for cursors here | |
118 (#) bottom layer has free size and start option to be used | |
119 for cursors (or sprites in the future ;-) | |
120 (#) background only black in the moment. | |
121 ToDo: Could be anything else for warnings etc. | |
122 if needed | |
123 | |
124 [..] Frame updates, switching and cursors is done with | |
125 | |
126 (#) GFX_SetFramesTopBottom() and the subset | |
127 GFX_SetFrameTop() + GFX_SetFrameBottom() | |
128 Those do not change anything on the display but give commands to.. | |
129 (#) GFX_change_LTDC() The only place that changes the pointer. | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
130 This prevents erratic behavior if several changes |
30 | 131 are made within one refresh rate of the screen. |
132 Is called in IRQ by PD4 and HAL_GPIO_EXTI_IRQHandler | |
133 from VSYNC signal. | |
134 | |
135 [..] Content | |
136 | |
137 (#) Colors by LookupTable only. This could be modified by | |
138 system settings in the future. (gfx_color.h/.c) | |
139 | |
140 (#) Text by text_multilinguage.h/.c with one char | |
141 necessary only starting from '\x80' | |
142 with automatic language switch by | |
143 selected_language in SSettings | |
144 see openEdit_Language() in tMenuEditSystem.c | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
145 Therefore there are different functions |
30 | 146 for example: |
147 write_label_fix() for single char multilanguage | |
148 write_label_var() for strings that could include | |
149 multilanguage as well | |
150 see GFX_write_string() to get an overview of the controls | |
151 as well as the command list in gfx_engine.h | |
152 There is no clear before writing, text overlay is always on. | |
153 Many options to have LargeFont.SmallFont for numbers etc. | |
154 | |
155 ============================================================================== | |
156 ##### Update, DualBoot and build-in FLASH memory usage ##### | |
157 ============================================================================== | |
158 [..] Boot0 pin, Boot1/PB2 pin and BFB2 software bit control the behaviour. | |
159 PB2 should be tied to GND. | |
160 Boot0 == VDD -> bootloader on start, otherwise boot from Bank1 or Bank2 | |
161 depending on BFB2. | |
162 Bank2 contains the Fonts and should contain a proper test code in future | |
163 Bank1 is the main code (Bank1 is 1 MB too, usage as of Oct. 14 is 200 KB) | |
164 [..] Bootloader should be either UART or USB (on FS pins _only_) | |
165 USB HS to FS like on the Eval board does not work. | |
166 [..] Bootloader for the smaller CPU2 is implemented via the SPI used for DMA copy. | |
167 | |
168 ============================================================================== | |
169 ##### Connection to CPU2 (STM32F411 as of Oct.14 ##### | |
170 ============================================================================== | |
171 [..] Connected via SPI and DMA for every purpose. | |
172 two entire arrays are transfered for data security reasons | |
173 with respect to master (STM32F429) might interrupt internal | |
174 data copy in CPU2 (like hi byte, low byte, etc.). | |
175 [..] The entire life data is calculated in CPU2. Like tissues, CNS,... | |
176 Therefore the main unit is _not_ necessarily a Real Time system. | |
177 Simulation on the main unit can be executed without disrupting life data. | |
178 [..] SPI is triggered and timed by calling DataEX_call() in data_exchange_main.c | |
179 DataEX_copy_to_LifeData() does the transfer from buffer to variables used. | |
180 | |
181 ============================================================================== | |
182 ##### Menu, MenuEdit, Info ##### | |
183 ============================================================================== | |
184 [..] tMenu.c, tMenuEdit.c and tInfo.c is the system used. | |
185 logbook is part of Info not Menu. | |
186 The Info Menu is accessed by button 'Back' | |
187 The regular Menu is accessed by button 'Enter' | |
188 [..] Menu content is kept in frame memory for fast access. | |
189 There is no need to build pages if the 'Enter' button is pressed. | |
190 This is in contrast to MenuEdit pages. | |
191 [..] Button control for new pages (and pages in general) have to implemented | |
192 in tMenu.c, tMenuEdit.c or tInfo.c | |
193 | |
194 [..] ToDo (Oct. 14) Timeout for menus via Timer3 / IRQ 2 | |
195 | |
196 ============================================================================== | |
197 ##### specials ##### | |
198 ============================================================================== | |
199 [..] There was code for vector graphics from great demos | |
200 (peridiummmm and jupiter) that can be fitted again | |
201 | |
202 @endverbatim | |
203 ****************************************************************************** | |
204 */ | |
205 | |
206 /* Includes ------------------------------------------------------------------*/ | |
207 #include "base_bootloader.h" | |
208 | |
209 // From Bootloader/Inc: | |
210 #include "tInfoBootloader.h" | |
211 | |
212 // ? | |
213 #include "externLogbookFlash.h" | |
214 #include "firmwareEraseProgram.h" | |
215 #include "firmwareJumpToApplication.h" | |
216 | |
217 // From Common/Inc: | |
218 #include "FirmwareData.h" | |
219 | |
220 // From Common/Drivers: | |
221 #include "stm32f4xx_hal.h" | |
222 #include "stm32f4xx_hal_rcc.h" | |
223 #include "stm32f4xx_hal_flash_ex.h" | |
224 #include "stm32f4xx_hal_wwdg.h" | |
225 | |
869 | 226 #ifdef BOOTLOADER_STANDALONE |
227 #include "Fonts/Font_T144_plus.h" | |
228 #include "Fonts/Font_T84.h" | |
229 #include "Fonts/Font_T105.h" | |
230 #include "Fonts/Font_T54.h" | |
231 #include "Fonts/Font_T48_plus.h" | |
232 #include "Fonts/Font_T24.h" | |
233 #include "Fonts/Font_T42.h" | |
234 #include "Fonts/image_battery.h" | |
235 #include "Fonts/image_heinrichs_weikamp.h" | |
236 #include "Fonts/image_ostc.h" | |
237 #endif | |
238 | |
30 | 239 // From Discovery/Inc (shall be shared...) |
240 #include "data_exchange_main.h" | |
241 #include "display.h" | |
242 #include "gfx_engine.h" | |
243 #include "ostc.h" | |
244 #include "tComm.h" | |
245 #include "tStructure.h" | |
246 | |
247 // From AC6 support: | |
248 #include <stdio.h> | |
249 #include <string.h> // for memcopy | |
250 | |
251 /* Private define ------------------------------------------------------------*/ | |
252 #define BUFFER_SIZE ((uint32_t)0x00177000) | |
253 #define WRITE_READ_ADDR ((uint32_t)0x0000) | |
254 #define REFRESH_COUNT ((uint32_t)0x0569) /* SDRAM refresh counter (90Mhz SD clock) */ | |
255 | |
256 /* Private macro -------------------------------------------------------------*/ | |
257 /* Private variables ---------------------------------------------------------*/ | |
258 uint8_t returnFromCommCleanUpRequest = 0; | |
259 | |
260 const SFirmwareData bootloader_FirmwareData __attribute__(( section(".bootloader_firmware_data") )) = | |
261 { | |
262 .versionFirst = 1, | |
263 .versionSecond = 0, | |
264 .versionThird = 1, | |
265 .versionBeta = 1, | |
266 | |
267 /* 4 bytes with trailing 0 */ | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
268 .signature = "mh", |
30 | 269 |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
270 .release_year = 25, |
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
271 .release_month = 1, |
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
272 .release_day = 11, |
30 | 273 .release_sub = 0, |
274 | |
275 /* max 48 with trailing 0 */ | |
276 .release_info ="tComm with all", | |
277 | |
278 /* for safety reasons and coming functions*/ | |
279 .magic[0] = FIRMWARE_MAGIC_FIRST, | |
280 .magic[1] = FIRMWARE_MAGIC_SECOND, | |
281 .magic[2] = FIRMWARE_MAGIC_FIRMWARE, /* the magic byte */ | |
282 .magic[3] = FIRMWARE_MAGIC_END | |
283 }; | |
284 | |
961
2130d771c8db
Bootloader: Activate Hardware data defaults:
Ideenmodellierer
parents:
960
diff
changeset
|
285 #if 1 |
2130d771c8db
Bootloader: Activate Hardware data defaults:
Ideenmodellierer
parents:
960
diff
changeset
|
286 const SHardwareData HardwareData __attribute__ ((section (".bootloader_hardware_data"))) = { |
30 | 287 |
288 // first 52 bytes | |
289 .primarySerial = 0xFFFF, | |
290 .primaryLicence = 0xFF, | |
291 .revision8bit = 0xFF, | |
292 .production_year = 0xFF, | |
293 .production_month = 0xFF, | |
294 .production_day = 0xFF, | |
295 .production_bluetooth_name_set = 0xFF, | |
296 | |
297 .production_info = { | |
298 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | |
299 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | |
300 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | |
301 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | |
302 | |
303 // other 12 bytes (64 in total) | |
304 .secondarySerial = 0xFFFF, | |
305 .secondaryLicence = 0xFF, | |
306 .secondaryReason8bit = 0xFF, | |
307 .secondary_year = 0xFF, | |
308 .secondary_month = 0xFF, | |
309 .secondary_day = 0xFF, | |
310 .secondary_bluetooth_name_set = 0xFF, | |
311 .secondary_info = {0xFF,0xFF,0xFF,0xFF} | |
312 }; | |
869 | 313 #endif |
30 | 314 |
315 RTC_HandleTypeDef RtcHandle; | |
316 TIM_HandleTypeDef TimHandle; /* used in stm32f4xx_it.c too */ | |
317 TIM_HandleTypeDef TimBacklightHandle; /* used in stm32f4xx_it.c too */ | |
318 | |
319 uint32_t time_before; | |
320 uint32_t time_between; | |
321 uint32_t time_after; | |
322 | |
323 /* SDRAM handler declaration */ | |
324 SDRAM_HandleTypeDef hsdram; | |
325 FMC_SDRAM_TimingTypeDef SDRAM_Timing; | |
326 FMC_SDRAM_CommandTypeDef command; | |
327 | |
328 FLASH_OBProgramInitTypeDef OBInit; | |
329 FLASH_AdvOBProgramInitTypeDef AdvOBInit; | |
330 | |
331 | |
332 /* Private variables with external access ------------------------------------*/ | |
333 | |
334 uint32_t globalStateID = 0; | |
335 uint8_t globalModeID = SURFMODE; | |
336 uint32_t time_without_button_pressed_deciseconds = 0; | |
337 uint8_t bootToBootloader = 0; | |
338 | |
339 /* Private function prototypes -----------------------------------------------*/ | |
340 | |
341 //static void LCD_ToggleFramebuffer(GFX_DrawCfgTypeDef *hconfig); | |
342 //static void LCD_Config(GFX_DrawCfgTypeDef *hconfig); | |
343 static void SystemClock_Config(void); | |
344 static void Error_Handler(void); | |
345 | |
346 static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command); | |
347 static void SDRAM_Config(void); | |
348 //static void DualBoot(void); | |
349 static void EXTILine_Buttons_Config(void); | |
350 //static void RTC_init(void); | |
351 static void TIM_init(void); | |
352 static void TIM_BACKLIGHT_init(void); | |
353 //static void TIM_BACKLIGHT_adjust(void); | |
354 static void gotoSleep(void); | |
355 uint8_t checkResetForFirmwareUpdate(void); | |
356 void DeleteResetToFirmwareUpdateRegister(void); | |
357 void reset_to_firmware_using_Watchdog(void); | |
358 void reset_to_update_using_system_reset(void); | |
359 | |
360 //static void DualBootToBootloader(void); | |
361 | |
362 /* ITM Trace-------- ---------------------------------------------------------*/ | |
363 /* | |
364 #define ITM_Port8(n) (*((volatile unsigned char *)(0xE0000000+4*n))) | |
365 #define ITM_Port16(n) (*((volatile unsigned short*)(0xE0000000+4*n))) | |
366 #define ITM_Port32(n) (*((volatile unsigned long *)(0xE0000000+4*n))) | |
367 | |
368 #define DEMCR (*((volatile unsigned long *)(0xE000EDFC))) | |
369 #define TRCENA 0x01000000 | |
370 | |
371 struct __FILE { int handle; }; | |
372 FILE __stdout; | |
373 FILE __stdin; | |
374 | |
375 int fputc(int ch, FILE *f) { | |
376 if (DEMCR & TRCENA) { | |
377 while (ITM_Port32(0) == 0); | |
378 ITM_Port8(0) = ch; | |
379 } | |
380 return(ch); | |
381 } | |
382 */ | |
383 | |
384 /* Private functions ---------------------------------------------------------*/ | |
385 | |
386 /** | |
387 * @brief Main program | |
388 * @param None | |
389 * @retval None | |
390 */ | |
391 | |
392 void GPIO_test_I2C_lines(void) | |
393 { | |
394 GPIO_InitTypeDef GPIO_InitStructure; | |
395 __GPIOA_CLK_ENABLE(); | |
396 __GPIOG_CLK_ENABLE(); | |
397 GPIO_InitStructure.Pin = GPIO_PIN_7; | |
398 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
399 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
400 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
401 HAL_GPIO_Init(GPIOG, &GPIO_InitStructure); | |
402 GPIO_InitStructure.Pin = GPIO_PIN_3; | |
403 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); | |
404 | |
405 while(1) | |
406 { | |
407 HAL_GPIO_WritePin(GPIOG,GPIO_PIN_7,GPIO_PIN_SET); | |
408 HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3,GPIO_PIN_RESET); | |
409 HAL_Delay(10); | |
410 HAL_GPIO_WritePin(GPIOG,GPIO_PIN_7,GPIO_PIN_RESET); | |
411 HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3,GPIO_PIN_SET); | |
412 HAL_Delay(10); | |
413 } | |
414 } | |
415 | |
416 | |
417 int main(void) | |
418 { | |
419 | |
420 /* | |
421 HAL_Init(); | |
422 SystemClock_Config(); | |
423 GPIO_test_I2C_lines(); | |
424 */ | |
425 uint32_t pLayerInvisible; | |
426 uint32_t firmware_load_result; | |
427 uint8_t magicbyte = 0; | |
428 uint8_t callForUpdate; | |
429 uint8_t status = 0; | |
430 char textVersion[32]; | |
431 uint8_t ptr; | |
432 uint32_t pOffset; | |
433 | |
869 | 434 const SHardwareData* HardwareData = hardwareDataGetPointer(); |
435 | |
30 | 436 set_globalState(StBoot0); |
437 | |
438 HAL_Init(); | |
439 HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_2); | |
869 | 440 SystemClock_Config(); |
441 | |
442 MX_GPIO_Init(); | |
30 | 443 |
444 /* button press is only 40 to 50 us low */ | |
445 MX_GPIO_One_Button_only_Init(); | |
446 | |
447 uint32_t i = 500000; | |
448 | |
449 callForUpdate = __HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST); | |
450 | |
451 if(callForUpdate) | |
452 { | |
453 i = 0; | |
454 } | |
455 else | |
456 if( (firmware_MainCodeIsProgammed() == 0) | |
869 | 457 || (HardwareData->primarySerial == 0xFFFF) |
458 || (HardwareData->production_bluetooth_name_set == 0xFF)) | |
30 | 459 { |
460 i = 1; | |
461 } | |
462 else | |
463 { | |
464 while(MX_GPIO_Read_The_One_Button() && i) | |
465 { | |
466 i--; | |
467 __NOP(); | |
468 } | |
469 if(i) | |
470 { | |
471 i = 200000; | |
472 while(!MX_GPIO_Read_The_One_Button() && i) | |
473 { | |
474 i--; | |
475 __NOP(); | |
476 } | |
477 if(i) | |
478 { | |
479 i = 200000; | |
480 while(MX_GPIO_Read_The_One_Button() && i) | |
481 { | |
482 i--; | |
483 __NOP(); | |
484 } | |
485 if(i) | |
486 { | |
487 i = 200000; | |
488 while(!MX_GPIO_Read_The_One_Button() && i) | |
489 { | |
490 i--; | |
491 __NOP(); | |
492 } | |
493 if(i) | |
494 { | |
495 i = 200000; | |
496 while(MX_GPIO_Read_The_One_Button() && i) | |
497 { | |
498 i--; | |
499 __NOP(); | |
500 } | |
501 } | |
502 } | |
503 } | |
504 } | |
505 } | |
506 | |
507 if((i == 0) && (callForUpdate == 0)) | |
508 firmware_JumpTo_Application(); | |
509 | |
510 MX_SPI_Init(); | |
511 SDRAM_Config(); | |
512 HAL_Delay(100); | |
513 | |
514 GFX_init1_no_DMA(&pLayerInvisible, 2); | |
515 | |
516 TIM_BACKLIGHT_init(); | |
517 | |
518 // ----------------------------- | |
519 | |
520 display_power_on__1_of_2__pre_RGB(); | |
521 GFX_LTDC_Init(); | |
522 GFX_LTDC_LayerDefaultInit(TOP_LAYER, pLayerInvisible); | |
523 GFX_LTDC_LayerDefaultInit(BACKGRD_LAYER, pLayerInvisible); | |
524 GFX_SetFramesTopBottom(pLayerInvisible,pLayerInvisible,480); | |
525 HAL_Delay(20); | |
526 display_power_on__2_of_2__post_RGB(); | |
527 | |
528 // ----------------------------- | |
529 GFX_change_LTDC(); | |
530 GFX_hwBackgroundOn(); | |
531 GFX_change_LTDC(); | |
532 // ----------------------------- | |
533 tInfoBootloader_init(); | |
534 // ----------------------------- | |
535 if(i == 0) | |
536 { | |
537 tInfo_newpage("load firmware data"); | |
538 uint8_t* pBuffer = (uint8_t*)((uint32_t)0xD0000000); /* blocked via GFX_init1_no_DMA */ | |
539 firmware_load_result = ext_flash_read_firmware(pBuffer,768000, &magicbyte); | |
540 | |
541 if((firmware_load_result > 0) && (firmware_load_result < 768000) && (magicbyte == 0xEE)) | |
542 { | |
543 ptr = ext_flash_read_firmware_version(textVersion); | |
544 textVersion[ptr++] = 'f'; | |
545 textVersion[ptr++] = 'o'; | |
546 textVersion[ptr++] = 'u'; | |
547 textVersion[ptr++] = 'n'; | |
548 textVersion[ptr++] = 'd'; | |
549 textVersion[ptr] = 0; | |
550 | |
551 tInfo_newpage(textVersion); | |
552 tInfo_write("erase flash"); | |
553 status = firmware_eraseFlashMemory(); | |
554 if(status != HAL_OK) | |
555 { | |
556 tInfo_newpage("error. try again."); | |
557 status = firmware_eraseFlashMemory(); | |
558 if(status != HAL_OK) | |
559 { | |
560 tInfo_newpage("error. skip update."); | |
561 HAL_Delay(1000); | |
562 } | |
563 } | |
564 if(status == HAL_OK) | |
565 { | |
252 | 566 tInfo_write("program flash"); |
30 | 567 status = firmware_programFlashMemory(pBuffer,firmware_load_result); |
568 if(status != HAL_OK) | |
569 { | |
570 tInfo_newpage("error. try again."); | |
571 status = firmware_programFlashMemory(pBuffer,firmware_load_result); | |
572 if(status != HAL_OK) | |
573 { | |
574 tInfo_newpage("error. skip update."); | |
575 HAL_Delay(1000); | |
576 } | |
577 } | |
578 } | |
579 } | |
580 } | |
581 | |
582 /* here comes the variable upper firmware loader */ | |
583 if((i == 0) && (status == HAL_OK)) | |
584 { | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
585 tInfo_newpage("load fontpack data"); |
30 | 586 uint8_t* pBuffer = (uint8_t*)((uint32_t)0xD0000000); /* blocked via GFX_init1_no_DMA */ |
587 firmware_load_result = ext_flash_read_firmware2(&pOffset, pBuffer,768000*2,0,0); | |
588 | |
589 if((firmware_load_result > 0) && (firmware_load_result + pOffset <= 1024000)) | |
590 { | |
591 ptr = 0; | |
592 ptr += gfx_number_to_string(7,0,&textVersion[ptr],firmware_load_result); | |
593 textVersion[ptr++] = ' '; | |
594 textVersion[ptr++] = 'b'; | |
595 textVersion[ptr++] = 'y'; | |
596 textVersion[ptr++] = 't'; | |
597 textVersion[ptr++] = 'e'; | |
598 textVersion[ptr++] = 's'; | |
599 textVersion[ptr++] = ' '; | |
600 textVersion[ptr++] = 'w'; | |
601 textVersion[ptr++] = 'i'; | |
602 textVersion[ptr++] = 't'; | |
603 textVersion[ptr++] = 'h'; | |
604 textVersion[ptr++] = ' '; | |
605 ptr += gfx_number_to_string(7,0,&textVersion[ptr],pOffset); | |
606 textVersion[ptr++] = ' '; | |
607 textVersion[ptr++] = 'o'; | |
608 textVersion[ptr++] = 'f'; | |
609 textVersion[ptr++] = 'f'; | |
610 textVersion[ptr++] = 's'; | |
611 textVersion[ptr++] = 'e'; | |
612 textVersion[ptr++] = 't'; | |
613 textVersion[ptr] = 0; | |
614 tInfo_newpage(textVersion); | |
615 | |
616 ptr = 0; | |
617 textVersion[ptr++] = 'f'; | |
618 textVersion[ptr++] = 'o'; | |
619 textVersion[ptr++] = 'u'; | |
620 textVersion[ptr++] = 'n'; | |
621 textVersion[ptr++] = 'd'; | |
622 textVersion[ptr] = 0; | |
623 | |
624 tInfo_write(textVersion); | |
625 tInfo_write("erase flash"); | |
626 status = firmware2_variable_upperpart_eraseFlashMemory(firmware_load_result,pOffset); | |
627 if(status != HAL_OK) | |
628 { | |
629 tInfo_newpage("error. try again."); | |
630 status = firmware2_variable_upperpart_eraseFlashMemory(firmware_load_result,pOffset); | |
631 if(status != HAL_OK) | |
632 { | |
633 tInfo_newpage("error. skip update."); | |
634 HAL_Delay(1000); | |
635 } | |
636 } | |
637 if(status == HAL_OK) | |
638 { | |
252 | 639 tInfo_write("program flash"); |
30 | 640 status = firmware2_variable_upperpart_programFlashMemory(firmware_load_result,pOffset,pBuffer,firmware_load_result,0); |
641 if(status != HAL_OK) | |
642 { | |
643 tInfo_newpage("error. try again."); | |
644 status = firmware2_variable_upperpart_programFlashMemory(firmware_load_result,pOffset,pBuffer,firmware_load_result,0); | |
645 if(status != HAL_OK) | |
646 { | |
647 tInfo_newpage("error. skip update."); | |
648 HAL_Delay(1000); | |
649 } | |
650 } | |
651 } | |
652 } | |
653 } | |
654 | |
655 if((i == 0) && (status == HAL_OK)) | |
656 { | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
657 tInfo_newpage("done."); |
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
658 tInfo_write("cleaning."); |
30 | 659 ext_flash_erase_firmware_if_not_empty(); |
660 ext_flash_erase_firmware2_if_not_empty(); | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
661 tInfo_write("reset device."); |
30 | 662 reset_to_firmware_using_Watchdog(); |
663 } | |
664 | |
665 ptr = 0; | |
880 | 666 textVersion[ptr++] = '\020'; |
30 | 667 textVersion[ptr++] = 's'; |
668 textVersion[ptr++] = 'e'; | |
669 textVersion[ptr++] = 'r'; | |
670 textVersion[ptr++] = 'i'; | |
671 textVersion[ptr++] = 'a'; | |
672 textVersion[ptr++] = 'l'; | |
673 textVersion[ptr++] = ' '; | |
869 | 674 if(HardwareData->primarySerial == 0xFFFF) |
30 | 675 { |
676 textVersion[ptr++] = 'n'; | |
677 textVersion[ptr++] = 'o'; | |
678 textVersion[ptr++] = 't'; | |
679 textVersion[ptr++] = ' '; | |
680 textVersion[ptr++] = 's'; | |
681 textVersion[ptr++] = 'e'; | |
682 textVersion[ptr++] = 't'; | |
683 } | |
869 | 684 else if(HardwareData->secondarySerial == 0xFFFF) |
30 | 685 { |
686 textVersion[ptr++] = '#'; | |
869 | 687 ptr += gfx_number_to_string(5,1,&textVersion[ptr],HardwareData->primarySerial); |
30 | 688 } |
689 else | |
690 { | |
691 textVersion[ptr++] = '#'; | |
869 | 692 ptr += gfx_number_to_string(5,1,&textVersion[ptr],HardwareData->secondarySerial); |
30 | 693 textVersion[ptr++] = ' '; |
694 textVersion[ptr++] = '('; | |
869 | 695 ptr += gfx_number_to_string(5,1,&textVersion[ptr],HardwareData->primarySerial); |
30 | 696 textVersion[ptr++] = ')'; |
697 } | |
698 textVersion[ptr++] = '\020'; | |
699 textVersion[ptr] = 0; | |
700 | |
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
701 TIM_init(); |
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
702 MX_UART_Init(); |
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
703 MX_Bluetooth_PowerOn(); |
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
704 tComm_init(); |
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
705 |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
706 tInfo_button_text("exit","","sleep"); |
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
707 tInfo_newpage("bootloader 250111"); |
30 | 708 tInfo_write("start bluetooth"); |
709 tInfo_write(""); | |
710 tInfo_write(textVersion); | |
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
711 if(tComm_Set_Bluetooth_Name(0) == 0xFF) |
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
712 { |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
713 tInfo_write("init bluetooth"); |
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
714 tComm_StartBlueModBaseInit(); |
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
715 } |
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
716 else |
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
717 { |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
718 tInfo_write("bluetooth set"); |
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
719 tComm_StartBlueModConfig(); |
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
720 } |
30 | 721 |
722 set_globalState_Base(); | |
723 | |
724 GFX_start_VSYNC_IRQ(); | |
725 | |
726 EXTILine_Buttons_Config(); | |
727 /* | |
728 uint8_t* pBuffer1 = (uint8_t*)getFrame(20); | |
729 firmware_load_result = ext_flash_read_firmware(pBuffer1,768000); | |
730 | |
731 if((firmware_load_result > 0) && (firmware_load_result < 768000)) | |
732 { | |
733 firmware_eraseFlashMemory(); | |
734 firmware_programFlashMemory(pBuffer1,firmware_load_result); | |
735 // not for testing | |
736 //ext_flash_erase_firmware_if_not_empty(); | |
737 reset_to_firmware_using_Watchdog(); | |
738 } | |
739 */ | |
740 while(1) | |
741 { | |
742 // if(bootToBootloader) | |
743 // DualBootToBootloader(); | |
744 | |
745 if(bootToBootloader) | |
746 reset_to_update_using_system_reset(); | |
747 | |
748 tComm_control(); // will stop while loop if tComm Mode started until exit from UART | |
749 }; | |
750 } | |
751 | |
752 | |
753 void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) | |
754 { | |
755 | |
756 SStateList status; | |
757 | |
758 get_globalStateList(&status); | |
759 | |
760 switch(status.base) | |
761 { | |
762 default: | |
763 // TIM_BACKLIGHT_adjust(); | |
764 break; | |
765 } | |
766 | |
767 if(returnFromCommCleanUpRequest) | |
768 { | |
769 tComm_exit(); | |
770 returnFromCommCleanUpRequest = 0; | |
771 GFX_hwBackgroundOn(); | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
772 tInfo_button_text("exit","","sleep"); |
30 | 773 tInfo_newpage("bluetooth disonnected"); |
774 tInfo_write(""); | |
775 tInfo_write(""); | |
776 tInfo_write(""); | |
777 tInfo_write(""); | |
778 } | |
779 | |
780 get_globalStateList(&status); | |
781 | |
782 switch(status.base) | |
783 { | |
784 case BaseComm: | |
785 if(get_globalState() == StUART_STANDARD) | |
786 tComm_refresh(); | |
787 break; | |
788 default: | |
789 break; | |
790 } | |
791 } | |
792 | |
793 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) | |
794 { | |
795 uint8_t action; | |
796 SStateList status; | |
797 static uint8_t counterToPreventSleep = 0; | |
798 if(GPIO_Pin == VSYNC_IRQ_PIN) // rechts, unten | |
799 { | |
800 GFX_change_LTDC(); | |
801 housekeepingFrame(); | |
802 if(counterToPreventSleep < 250) | |
803 counterToPreventSleep++; | |
804 else | |
805 if(counterToPreventSleep != 255) | |
806 { | |
807 counterToPreventSleep = 255; | |
808 } | |
809 | |
810 return; | |
811 } | |
812 | |
813 time_without_button_pressed_deciseconds = 0; | |
814 | |
815 if(GFX_logoStatus() != 0) | |
816 return; | |
817 | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
818 if(GPIO_Pin == BUTTON_BACK_PIN) // left |
30 | 819 action = ACTION_BUTTON_BACK; |
820 else | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
821 if(GPIO_Pin == BUTTON_ENTER_PIN) // center |
30 | 822 action = ACTION_BUTTON_ENTER; |
823 else | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
824 if(GPIO_Pin == BUTTON_NEXT_PIN) // right |
30 | 825 action = ACTION_BUTTON_NEXT; |
826 #ifdef BUTTON_CUSTOM_PIN | |
827 else | |
828 if(GPIO_Pin == BUTTON_CUSTOM_PIN) // extra | |
829 action = ACTION_BUTTON_CUSTOM; | |
830 #endif | |
831 else | |
832 action = 0; | |
833 get_globalStateList(&status); | |
834 | |
835 switch(status.base) | |
836 { | |
837 case BaseComm: | |
838 if(action == ACTION_BUTTON_BACK) | |
839 { | |
840 reset_to_firmware_using_Watchdog(); | |
841 } | |
842 break; | |
843 | |
844 default: | |
845 if((action == ACTION_BUTTON_NEXT) && (counterToPreventSleep == 255) && (get_globalState() == StS)) | |
846 { | |
847 while(1) | |
848 { | |
849 MX_tell_reset_logik_alles_ok(); | |
850 DataEX_call(); | |
851 HAL_Delay(100); | |
852 } | |
853 } | |
854 else | |
855 if(action == ACTION_BUTTON_BACK) | |
856 { | |
857 reset_to_firmware_using_Watchdog(); | |
858 } | |
859 else | |
860 if(action == ACTION_BUTTON_CUSTOM) | |
861 { | |
862 if(get_globalState() == StS) | |
863 gotoSleep(); | |
864 } | |
865 else | |
866 if(action == ACTION_BUTTON_ENTER) | |
867 { | |
868 reset_to_update_using_system_reset(); | |
869 } | |
870 break; | |
871 } | |
872 } | |
873 | |
874 | |
875 void gotoSleep(void) | |
876 { | |
877 ext_flash_erase_firmware_if_not_empty(); | |
878 set_globalState(StStop); | |
879 } | |
880 | |
881 // ----------------------------- | |
882 | |
883 | |
884 void MainBootLoaderInit(void) | |
885 { | |
886 void (*SysMemBootJump)(void); | |
887 SysMemBootJump=(void (*)(void)) (*((uint32_t *) 0x1fff0004)); | |
888 | |
889 // DMA, SPI, UART, TIM, ExtIRQ, graphics DMA, LTDC | |
890 | |
891 HAL_RCC_DeInit(); | |
892 SysTick->CTRL = 0; | |
893 SysTick->LOAD = 0; | |
894 SysTick->VAL = 0; | |
895 | |
896 __set_PRIMASK(1); | |
897 | |
898 __set_MSP(0x20002318); | |
899 SysMemBootJump(); | |
900 } | |
901 | |
902 uint32_t get_globalState(void) | |
903 { | |
904 return globalStateID; | |
905 } | |
906 | |
907 void get_globalStateList(SStateList *output) | |
908 { | |
909 output->base = (uint8_t)((globalStateID >> 28) & 0x0F); | |
910 output->page = (uint8_t)((globalStateID >> 24) & 0x0F); | |
911 output->line = (uint8_t)((globalStateID >> 16) & 0xFF); | |
912 output->field = (uint8_t)((globalStateID >> 8) & 0xFF); | |
913 output->mode = (uint8_t)((globalStateID ) & 0xFF); | |
914 } | |
915 | |
916 void get_idSpecificStateList(uint32_t id, SStateList *output) | |
917 { | |
918 output->base = (uint8_t)((id >> 28) & 0x0F); | |
919 output->page = (uint8_t)((id >> 24) & 0x0F); | |
920 output->line = (uint8_t)((id >> 16) & 0xFF); | |
921 output->field = (uint8_t)((id >> 8) & 0xFF); | |
922 output->mode = (uint8_t)((id ) & 0xFF); | |
923 } | |
924 | |
925 void set_globalState_Base(void) | |
926 { | |
927 set_globalState(StS); | |
928 } | |
929 | |
930 void set_globalState_Menu_Page(uint8_t page) | |
931 { | |
932 globalStateID = ((BaseMenu << 28) + (page << 24)); | |
933 } | |
934 | |
935 void set_globalState_Log_Page(uint8_t pageIsLine) | |
936 { | |
937 globalStateID = StILOGLIST + (pageIsLine << 16); | |
938 } | |
939 | |
940 | |
941 void set_globalState_Menu_Line(uint8_t line) | |
942 { | |
943 globalStateID = ((globalStateID & MaskLineFieldDigit) + (line << 16)); | |
944 } | |
945 | |
946 | |
947 void set_globalState(uint32_t newID) | |
948 { | |
949 globalStateID = newID; | |
950 } | |
951 | |
952 | |
953 | |
954 void delayMicros(uint32_t micros) | |
955 { | |
956 micros = micros * (168/4) - 10; | |
957 while(micros--); | |
958 } | |
959 | |
960 | |
961 void get_RTC_DateTime(RTC_DateTypeDef * sdatestructureget, RTC_TimeTypeDef * stimestructureget) | |
962 { | |
963 /* Get the RTC current Time */ | |
964 if(sdatestructureget) | |
965 HAL_RTC_GetTime(&RtcHandle, stimestructureget, FORMAT_BIN); | |
966 /* Get the RTC current Date */ | |
967 if(stimestructureget) | |
968 HAL_RTC_GetDate(&RtcHandle, sdatestructureget, FORMAT_BIN); | |
969 } | |
970 | |
971 | |
972 void set_RTC_DateTime(RTC_DateTypeDef * sdatestructure, RTC_TimeTypeDef * stimestructure) | |
973 { | |
974 if(sdatestructure) | |
975 if(HAL_RTC_SetDate(&RtcHandle,sdatestructure,FORMAT_BCD) != HAL_OK) | |
976 { | |
977 /* Initialization Error */ | |
978 Error_Handler(); | |
979 } | |
980 | |
981 if(stimestructure) | |
982 if(HAL_RTC_SetTime(&RtcHandle,stimestructure,FORMAT_BCD) != HAL_OK) | |
983 { | |
984 /* Initialization Error */ | |
985 Error_Handler(); | |
986 } | |
987 } | |
988 | |
989 static void TIM_init(void) | |
990 { | |
991 uint16_t uwPrescalerValue = 0; | |
992 | |
993 uwPrescalerValue = (uint32_t) ((SystemCoreClock /2) / 10000) - 1; | |
994 | |
995 /* Set TIMx instance */ | |
996 TimHandle.Instance = TIMx; | |
997 | |
998 /* Initialize TIM3 peripheral as follows: | |
999 + Period = 10000 - 1 | |
1000 + Prescaler = ((SystemCoreClock/2)/10000) - 1 | |
1001 + ClockDivision = 0 | |
1002 + Counter direction = Up | |
1003 */ | |
1004 TimHandle.Init.Period = 1000 - 1; | |
1005 TimHandle.Init.Prescaler = uwPrescalerValue; | |
1006 TimHandle.Init.ClockDivision = 0; | |
1007 TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; | |
1008 if(HAL_TIM_Base_Init(&TimHandle) != HAL_OK) | |
1009 { | |
1010 /* Initialization Error */ | |
1011 Error_Handler(); | |
1012 } | |
1013 | |
1014 /*##-2- Start the TIM Base generation in interrupt mode ####################*/ | |
1015 /* Start Channel1 */ | |
1016 if(HAL_TIM_Base_Start_IT(&TimHandle) != HAL_OK) | |
1017 { | |
1018 /* Starting Error */ | |
1019 Error_Handler(); | |
1020 } | |
1021 } | |
1022 | |
1023 #ifndef TIM_BACKLIGHT | |
1024 /* | |
1025 static void TIM_BACKLIGHT_adjust(void) | |
1026 { | |
1027 } | |
1028 */ | |
1029 static void TIM_BACKLIGHT_init(void) | |
1030 { | |
1031 } | |
1032 #else | |
1033 /* | |
1034 static void TIM_BACKLIGHT_adjust(void) | |
1035 { | |
1036 | |
1037 TIM_OC_InitTypeDef sConfig; | |
1038 sConfig.OCMode = TIM_OCMODE_PWM1; | |
1039 sConfig.OCPolarity = TIM_OCPOLARITY_HIGH; | |
1040 sConfig.OCFastMode = TIM_OCFAST_DISABLE; | |
1041 sConfig.Pulse = 600; | |
1042 | |
1043 HAL_TIM_PWM_ConfigChannel(&TimBacklightHandle, &sConfig, TIM_BACKLIGHT_CHANNEL); | |
1044 HAL_TIM_PWM_Start(&TimBacklightHandle, TIM_BACKLIGHT_CHANNEL); | |
1045 } | |
1046 */ | |
1047 static void TIM_BACKLIGHT_init(void) | |
1048 { | |
1049 uint32_t uwPrescalerValue = 0; | |
1050 TIM_OC_InitTypeDef sConfig; | |
1051 | |
1052 uwPrescalerValue = (uint32_t) ((SystemCoreClock /2) / 18000000) - 1; | |
1053 | |
1054 TimBacklightHandle.Instance = TIM_BACKLIGHT; | |
1055 | |
1056 // Initialize TIM3 peripheral as follows: 30 kHz | |
1057 | |
1058 TimBacklightHandle.Init.Period = 600 - 1; | |
1059 TimBacklightHandle.Init.Prescaler = uwPrescalerValue; | |
1060 TimBacklightHandle.Init.ClockDivision = 0; | |
1061 TimBacklightHandle.Init.CounterMode = TIM_COUNTERMODE_UP; | |
1062 HAL_TIM_PWM_Init(&TimBacklightHandle); | |
1063 | |
1064 sConfig.OCMode = TIM_OCMODE_PWM1; | |
1065 sConfig.OCPolarity = TIM_OCPOLARITY_HIGH; | |
1066 sConfig.OCFastMode = TIM_OCFAST_DISABLE; | |
1067 sConfig.Pulse = 50 * 6; | |
1068 | |
1069 HAL_TIM_PWM_ConfigChannel(&TimBacklightHandle, &sConfig, TIM_BACKLIGHT_CHANNEL); | |
1070 HAL_TIM_PWM_Start(&TimBacklightHandle, TIM_BACKLIGHT_CHANNEL); | |
1071 } | |
1072 #endif | |
1073 | |
1074 /* Configure RTC prescaler and RTC data registers */ | |
1075 /* RTC configured as follow: | |
1076 - Hour Format = Format 24 | |
1077 - Asynch Prediv = Value according to source clock | |
1078 - Synch Prediv = Value according to source clock | |
1079 - OutPut = Output Disable | |
1080 - OutPutPolarity = High Polarity | |
1081 - OutPutType = Open Drain */ | |
1082 /*#define RTC_ASYNCH_PREDIV 0x7F LSE as RTC clock */ | |
1083 /*LSE: #define RTC_SYNCH_PREDIV 0x00FF LSE as RTC clock */ | |
1084 /*LSI: #define RTC_SYNCH_PREDIV 0x0130 LSI as RTC clock */ | |
1085 /* | |
1086 static void RTC_init(void) | |
1087 { | |
1088 RtcHandle.Instance = RTC; | |
1089 | |
1090 | |
1091 RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24; | |
1092 RtcHandle.Init.AsynchPrediv = 0x7F; | |
1093 RtcHandle.Init.SynchPrediv = 0x0130; | |
1094 RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE; | |
1095 RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; | |
1096 RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; | |
1097 | |
1098 if(HAL_RTC_Init(&RtcHandle) != HAL_OK) | |
1099 { | |
1100 Error_Handler(); | |
1101 } | |
1102 } | |
1103 */ | |
1104 | |
1105 static void EXTILine_Buttons_Config(void) | |
1106 { | |
1107 GPIO_InitTypeDef GPIO_InitStructure; | |
1108 | |
1109 BUTTON_ENTER_GPIO_ENABLE(); | |
1110 BUTTON_NEXT_GPIO_ENABLE(); | |
1111 BUTTON_BACK_GPIO_ENABLE(); | |
1112 | |
1113 /* Configure pin as weak PULLUP input */ | |
1114 /* buttons */ | |
1115 GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING; | |
1116 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
1117 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
1118 | |
1119 GPIO_InitStructure.Pin = BUTTON_ENTER_PIN; | |
1120 HAL_GPIO_Init(BUTTON_ENTER_GPIO_PORT, &GPIO_InitStructure); | |
1121 | |
1122 GPIO_InitStructure.Pin = BUTTON_NEXT_PIN; | |
1123 HAL_GPIO_Init(BUTTON_NEXT_GPIO_PORT, &GPIO_InitStructure); | |
1124 | |
1125 GPIO_InitStructure.Pin = BUTTON_BACK_PIN; | |
1126 HAL_GPIO_Init(BUTTON_BACK_GPIO_PORT, &GPIO_InitStructure); | |
1127 | |
1128 /* Enable and set EXTI Line0 Interrupt to the lowest priority */ | |
1129 HAL_NVIC_SetPriority(BUTTON_ENTER_EXTI_IRQn, 2, 0); | |
1130 HAL_NVIC_SetPriority(BUTTON_NEXT_EXTI_IRQn, 2, 0); | |
1131 HAL_NVIC_SetPriority(BUTTON_BACK_EXTI_IRQn, 2, 0); | |
1132 HAL_NVIC_EnableIRQ(BUTTON_ENTER_EXTI_IRQn); | |
1133 HAL_NVIC_EnableIRQ(BUTTON_NEXT_EXTI_IRQn); | |
1134 HAL_NVIC_EnableIRQ(BUTTON_BACK_EXTI_IRQn); | |
1135 | |
1136 #ifdef BUTTON_CUSTOM_PIN | |
1137 BUTTON_CUSTOM_GPIO_ENABLE(); | |
1138 GPIO_InitStructure.Pin = BUTTON_CUSTOM_PIN; | |
1139 HAL_GPIO_Init(BUTTON_CUSTOM_GPIO_PORT, &GPIO_InitStructure); | |
1140 HAL_NVIC_SetPriority(BUTTON_CUSTOM_EXTI_IRQn, 2, 0); | |
1141 HAL_NVIC_EnableIRQ(BUTTON_CUSTOM_EXTI_IRQn); | |
1142 #endif | |
1143 } | |
1144 | |
1145 | |
1146 /** | |
1147 * @brief System Clock Configuration | |
1148 * The system Clock is configured as follow : | |
1149 * System Clock source = PLL (HSE) | |
1150 * SYSCLK(Hz) = 180000000 | |
1151 * HCLK(Hz) = 180000000 | |
1152 * AHB Prescaler = 1 | |
1153 * APB1 Prescaler = 4 | |
1154 * APB2 Prescaler = 2 | |
1155 * HSE Frequency(Hz) = 8000000 | |
1156 * PLL_M = 8 | |
1157 * PLL_N = 360 | |
1158 * PLL_P = 2 | |
1159 * PLL_Q = 7 | |
1160 * VDD(V) = 3.3 | |
1161 * Main regulator output voltage = Scale1 mode | |
1162 * Flash Latency(WS) = 5 | |
1163 * The LTDC Clock is configured as follow : | |
1164 * PLLSAIN = 192 | |
1165 * PLLSAIR = 4 | |
1166 * PLLSAIDivR = 8 | |
1167 * @param None | |
1168 * @retval None | |
1169 */ | |
1170 static void SystemClock_Config(void) | |
1171 { | |
869 | 1172 /* Enable Power Control clock */ |
1173 __PWR_CLK_ENABLE(); | |
30 | 1174 |
869 | 1175 /* The voltage scaling allows optimizing the power consumption when the device is |
1176 clocked below the maximum system frequency, to update the voltage scaling value | |
1177 regarding system frequency refer to product datasheet. */ | |
1178 __HAL_PWR_VOLTAGESCALING_CONFIG( PWR_REGULATOR_VOLTAGE_SCALE1 ); | |
30 | 1179 |
869 | 1180 /*##-1- System Clock Configuration #########################################*/ |
1181 /* Enable HighSpeed Oscillator and activate PLL with HSE/HSI as source */ | |
1182 RCC_OscInitTypeDef RCC_OscInitStruct = { 0 }; | |
1183 #ifdef DISC1_BOARD | |
1184 // Use High Speed Internal (HSI) oscillator, running at 16MHz. | |
1185 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; | |
1186 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |
1187 RCC_OscInitStruct.HSICalibrationValue = 0x10; | |
1188 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; | |
1189 RCC_OscInitStruct.PLL.PLLM = 16; // HSI/16 is 1Mhz. | |
1190 #else | |
1191 // Use High Speed External oscillator, running at 8MHz | |
1192 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; | |
1193 RCC_OscInitStruct.HSEState = RCC_HSE_ON; | |
1194 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; | |
1195 RCC_OscInitStruct.PLL.PLLM = 8; // HSE/8 is 1Mhz. | |
1196 #endif | |
1197 // System clock = PLL (1MHz) * N/p = 180 MHz. | |
1198 RCC_OscInitStruct.PLL.PLLN = 360; | |
1199 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; | |
1200 RCC_OscInitStruct.PLL.PLLQ = 7; | |
1201 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
1202 HAL_RCC_OscConfig( &RCC_OscInitStruct ); | |
30 | 1203 |
1204 // HAL_PWREx_ActivateOverDrive(); | |
869 | 1205 HAL_PWREx_DeactivateOverDrive(); |
1206 | |
1207 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ | |
1208 RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 }; | |
1209 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | |
1210 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; | |
1211 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
1212 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
1213 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; | |
1214 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; | |
1215 HAL_RCC_ClockConfig( &RCC_ClkInitStruct, FLASH_LATENCY_8 ); //FLASH_LATENCY_5); | |
30 | 1216 |
869 | 1217 /*##-2- LTDC Clock Configuration ###########################################*/ |
1218 /* LCD clock configuration */ | |
1219 /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */ | |
1220 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */ | |
1221 /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 Mhz */ | |
1222 /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDIVR_8 = 48/8 = 6 Mhz */ | |
30 | 1223 |
869 | 1224 /* neu: 8MHz/8*300/5/8 = 7,5 MHz = 19,5 Hz bei 800 x 480 */ |
1225 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; | |
1226 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC; | |
1227 PeriphClkInitStruct.PLLSAI.PLLSAIN = 300; //192; | |
1228 PeriphClkInitStruct.PLLSAI.PLLSAIR = 5; //4; | |
1229 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;//RCC_PLLSAIDIVR_4;// RCC_PLLSAIDIVR_2; // RCC_PLLSAIDIVR_8 | |
1230 HAL_RCCEx_PeriphCLKConfig( &PeriphClkInitStruct ); | |
30 | 1231 } |
1232 | |
1233 | |
1234 /** | |
1235 * @brief This function is executed in case of error occurrence. | |
1236 * @param None | |
1237 * @retval None | |
1238 */ | |
1239 static void Error_Handler(void) | |
1240 { | |
1241 /* Turn LED3 on */ | |
1242 // BSP_LED_On(LED3); | |
1243 while(1) | |
1244 { | |
1245 } | |
1246 } | |
1247 | |
1248 /** | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
1249 * @brief Perform the SDRAM external memory initialization sequence |
30 | 1250 * @param hsdram: SDRAM handle |
1251 * @param Command: Pointer to SDRAM command structure | |
1252 * @retval None | |
1253 */ | |
1254 static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command) | |
1255 { | |
1256 __IO uint32_t tmpmrd =0; | |
1257 /* Step 3: Configure a clock configuration enable command */ | |
1258 Command->CommandMode = FMC_SDRAM_CMD_CLK_ENABLE; | |
1259 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
1260 Command->AutoRefreshNumber = 1; | |
1261 Command->ModeRegisterDefinition = 0; | |
1262 | |
1263 /* Send the command */ | |
1264 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
1265 | |
1266 /* Step 4: Insert 100 ms delay */ | |
1267 HAL_Delay(100); | |
1268 | |
1269 /* Step 5: Configure a PALL (precharge all) command */ | |
1270 Command->CommandMode = FMC_SDRAM_CMD_PALL; | |
1271 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
1272 Command->AutoRefreshNumber = 1; | |
1273 Command->ModeRegisterDefinition = 0; | |
1274 | |
1275 /* Send the command */ | |
1276 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
1277 | |
1278 /* Step 6 : Configure a Auto-Refresh command */ | |
1279 Command->CommandMode = FMC_SDRAM_CMD_AUTOREFRESH_MODE; | |
1280 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
1281 Command->AutoRefreshNumber = 4; | |
1282 Command->ModeRegisterDefinition = 0; | |
1283 | |
1284 /* Send the command */ | |
1285 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
1286 | |
1287 /* Step 7: Program the external memory mode register */ | |
1288 tmpmrd = (uint32_t)SDRAM_MODEREG_BURST_LENGTH_2 | | |
1289 SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL | | |
1290 SDRAM_MODEREG_CAS_LATENCY_3 | | |
1291 SDRAM_MODEREG_OPERATING_MODE_STANDARD | | |
1292 SDRAM_MODEREG_WRITEBURST_MODE_SINGLE; | |
1293 | |
1294 Command->CommandMode = FMC_SDRAM_CMD_LOAD_MODE; | |
1295 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
1296 Command->AutoRefreshNumber = 1; | |
1297 Command->ModeRegisterDefinition = tmpmrd; | |
1298 | |
1299 /* Send the command */ | |
1300 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
1301 | |
1302 /* Step 8: Set the refresh rate counter */ | |
1303 /* (15.62 us x Freq) - 20 */ | |
1304 /* neu: (8 us x Freq) - 20 */ | |
1305 /* Set the device refresh counter */ | |
1306 HAL_SDRAM_ProgramRefreshRate(hsdram, REFRESH_COUNT); | |
1307 } | |
1308 | |
1309 /* | |
1310 static void DualBoot(void) | |
1311 { | |
1312 // Set BFB2 bit to enable boot from Flash Bank2 | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
1313 // Allow Access to Flash control registers and user Flash |
30 | 1314 HAL_FLASH_Unlock(); |
1315 | |
1316 // Allow Access to option bytes sector | |
1317 HAL_FLASH_OB_Unlock(); | |
1318 | |
1319 // Get the Dual boot configuration status | |
1320 AdvOBInit.OptionType = OBEX_BOOTCONFIG; | |
1321 HAL_FLASHEx_AdvOBGetConfig(&AdvOBInit); | |
1322 | |
1323 // Enable/Disable dual boot feature | |
1324 if (((AdvOBInit.BootConfig) & (FLASH_OPTCR_BFB2)) == FLASH_OPTCR_BFB2) | |
1325 { | |
1326 AdvOBInit.BootConfig = OB_DUAL_BOOT_DISABLE; | |
1327 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
1328 } | |
1329 else | |
1330 { | |
1331 AdvOBInit.BootConfig = OB_DUAL_BOOT_ENABLE; | |
1332 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
1333 } | |
1334 | |
1335 // Start the Option Bytes programming process | |
1336 if (HAL_FLASH_OB_Launch() != HAL_OK) | |
1337 { | |
1338 // User can add here some code to deal with this error | |
1339 while (1) | |
1340 { | |
1341 } | |
1342 } | |
1343 // Prevent Access to option bytes sector | |
1344 HAL_FLASH_OB_Lock(); | |
1345 | |
1346 // Disable the Flash option control register access (recommended to protect | |
1347 // the option Bytes against possible unwanted operations) | |
1348 HAL_FLASH_Lock(); | |
1349 | |
1350 // Initiates a system reset request to reset the MCU | |
1351 reset_to_firmware_using_Watchdog(); | |
1352 } | |
1353 */ | |
1354 /** | |
1355 ****************************************************************************** | |
1356 ****************************************************************************** | |
1357 ****************************************************************************** | |
1358 */ | |
1359 | |
1360 | |
1361 /** | |
1362 * @brief DMA2D configuration. | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
1363 * @note This function Configure the DMA2D peripheral : |
30 | 1364 * 1) Configure the transfer mode : memory to memory W/ pixel format conversion |
1365 * 2) Configure the output color mode as ARGB4444 | |
1366 * 3) Configure the output memory address at SRAM memory | |
1367 * 4) Configure the data size : 320x120 (pixels) | |
1368 * 5) Configure the input color mode as ARGB8888 | |
1369 * 6) Configure the input memory address at FLASH memory | |
1370 * @retval | |
1371 * None | |
1372 */ | |
1373 | |
1374 static void SDRAM_Config(void) | |
1375 { | |
1376 /*##-1- Configure the SDRAM device #########################################*/ | |
1377 /* SDRAM device configuration */ | |
1378 hsdram.Instance = FMC_SDRAM_DEVICE; | |
1379 | |
1380 /* Timing configuration for 90 Mhz of SD clock frequency (180Mhz/2) */ | |
1381 /* TMRD: 2 Clock cycles */ | |
1382 SDRAM_Timing.LoadToActiveDelay = 2; | |
1383 /* TXSR: min=70ns (6x11.90ns) */ | |
1384 SDRAM_Timing.ExitSelfRefreshDelay = 7; | |
1385 /* TRAS: min=42ns (4x11.90ns) max=120k (ns) */ | |
1386 SDRAM_Timing.SelfRefreshTime = 4; | |
1387 /* TRC: min=63 (6x11.90ns) */ | |
1388 SDRAM_Timing.RowCycleDelay = 7; | |
1389 /* TWR: 2 Clock cycles */ | |
1390 SDRAM_Timing.WriteRecoveryTime = 2; | |
1391 /* TRP: 15ns => 2x11.90ns */ | |
1392 SDRAM_Timing.RPDelay = 2; | |
1393 /* TRCD: 15ns => 2x11.90ns */ | |
1394 SDRAM_Timing.RCDDelay = 2; | |
1395 | |
1396 hsdram.Init.SDBank = FMC_SDRAM_BANK2; | |
1397 hsdram.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_9; | |
1398 hsdram.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_13; | |
1399 hsdram.Init.MemoryDataWidth = SDRAM_MEMORY_WIDTH; | |
1400 hsdram.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4; | |
1401 hsdram.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3; | |
1402 hsdram.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE; | |
1403 hsdram.Init.SDClockPeriod = SDCLOCK_PERIOD; | |
1404 hsdram.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE; | |
1405 hsdram.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_1; | |
1406 | |
1407 /* Initialize the SDRAM controller */ | |
1408 if(HAL_SDRAM_Init(&hsdram, &SDRAM_Timing) != HAL_OK) | |
1409 { | |
1410 /* Initialization Error */ | |
1411 Error_Handler(); | |
1412 } | |
1413 | |
1414 /* Program the SDRAM external device */ | |
1415 SDRAM_Initialization_Sequence(&hsdram, &command); | |
1416 } | |
1417 | |
1418 | |
1419 uint8_t checkResetForFirmwareUpdate(void) | |
1420 { | |
1421 uint32_t backupRegisterContent; | |
1422 | |
1423 RTC_HandleTypeDef RtcHandle; | |
1424 RtcHandle.Instance = RTC; | |
1425 backupRegisterContent = HAL_RTCEx_BKUPRead(&RtcHandle,RTC_BKP_DR0); | |
1426 | |
1427 if(backupRegisterContent == 0x12345678) | |
1428 return 1; | |
1429 else | |
1430 return 0; | |
1431 } | |
1432 | |
1433 void DeleteResetToFirmwareUpdateRegister(void) | |
1434 { | |
1435 RTC_HandleTypeDef RtcHandle; | |
1436 RtcHandle.Instance = RTC; | |
1437 __HAL_RTC_WRITEPROTECTION_DISABLE(&RtcHandle); | |
1438 HAL_RTCEx_BKUPWrite(&RtcHandle,RTC_BKP_DR0,0x00); | |
1439 __HAL_RTC_WRITEPROTECTION_ENABLE(&RtcHandle); | |
1440 } | |
1441 | |
1442 #ifdef USE_FULL_ASSERT | |
1443 | |
1444 /** | |
1445 * @brief Reports the name of the source file and the source line number | |
1446 * where the assert_param error has occurred. | |
1447 * @param file: pointer to the source file name | |
1448 * @param line: assert_param error line source number | |
1449 * @retval None | |
1450 */ | |
1451 void assert_failed(uint8_t* file, uint32_t line) | |
1452 { | |
1453 /* User can add his own implementation to report the file name and line number, | |
1454 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ | |
1455 | |
1456 /* Infinite loop */ | |
1457 while (1) | |
1458 { | |
1459 } | |
1460 } | |
1461 #endif | |
1462 | |
1463 /* | |
1464 static void DualBootToBootloader(void) | |
1465 { | |
1466 // Set BFB2 bit to enable boot from Flash Bank2 | |
1467 // Allow Access to Flash control registers and user Falsh | |
1468 HAL_FLASH_Unlock(); | |
1469 | |
1470 // Allow Access to option bytes sector | |
1471 HAL_FLASH_OB_Unlock(); | |
1472 | |
1473 // Get the Dual boot configuration status | |
1474 AdvOBInit.OptionType = OPTIONBYTE_BOOTCONFIG; | |
1475 HAL_FLASHEx_AdvOBGetConfig(&AdvOBInit); | |
1476 | |
1477 // Enable/Disable dual boot feature | |
1478 if (((AdvOBInit.BootConfig) & (FLASH_OPTCR_BFB2)) == FLASH_OPTCR_BFB2) | |
1479 { | |
1480 AdvOBInit.BootConfig = OB_DUAL_BOOT_DISABLE; | |
1481 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
1482 if (HAL_FLASH_OB_Launch() != HAL_OK) | |
1483 { | |
1484 while (1) | |
1485 { | |
1486 } | |
1487 } | |
1488 } | |
1489 else | |
1490 { | |
1491 | |
1492 AdvOBInit.BootConfig = OB_DUAL_BOOT_ENABLE; | |
1493 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
1494 if (HAL_FLASH_OB_Launch() != HAL_OK) | |
1495 { | |
1496 while (1) | |
1497 { | |
1498 } | |
1499 } | |
1500 } | |
1501 | |
1502 // Prevent Access to option bytes sector | |
1503 HAL_FLASH_OB_Lock(); | |
1504 | |
1505 / Disable the Flash option control register access (recommended to protect | |
1506 // the option Bytes against possible unwanted operations) | |
1507 HAL_FLASH_Lock(); | |
1508 | |
1509 // Initiates a system reset request to reset the MCU | |
1510 reset_to_firmware_using_Watchdog(); | |
1511 } | |
1512 */ | |
1513 | |
1514 void reset_to_update_using_system_reset(void) | |
1515 { | |
1516 __HAL_RCC_CLEAR_RESET_FLAGS(); | |
1517 HAL_NVIC_SystemReset(); | |
1518 } | |
1519 | |
1520 void reset_to_firmware_using_Watchdog(void) | |
1521 { | |
1522 __HAL_RCC_CLEAR_RESET_FLAGS(); | |
1523 __HAL_RCC_WWDG_CLK_ENABLE(); | |
1524 | |
1525 WWDG_HandleTypeDef WwdgHandle; | |
1526 WwdgHandle.Instance = WWDG; | |
1527 | |
1528 WwdgHandle.Init.Prescaler = WWDG_PRESCALER_8; | |
1529 WwdgHandle.Init.Window = 80; | |
1530 WwdgHandle.Init.Counter = 127; | |
1531 | |
1532 HAL_WWDG_Init(&WwdgHandle); | |
869 | 1533 /* HAL_WWDG_Start(&WwdgHandle); has been removed from HAL library starting_V120 */ |
30 | 1534 while(1); |
1535 } | |
1536 | |
1537 | |
1538 void set_returnFromComm(void) | |
1539 { | |
1540 returnFromCommCleanUpRequest = 1; | |
1541 } | |
1542 | |
1543 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |