Mercurial > public > ostc4
annotate BootLoader/Src/base_bootlader.c @ 986:5e7ad81e9ac2 BootloaderOstc5
Removed dependencies to OSTC HW version
author | Ideenmodellierer |
---|---|
date | Sun, 30 Mar 2025 21:33:18 +0200 (5 weeks ago) |
parents | d29e752660c5 |
children | 45a2bd04b156 |
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 #include "Fonts/Font_T144_plus.h" |
227 #include "Fonts/Font_T84.h" | |
228 #include "Fonts/Font_T105.h" | |
229 #include "Fonts/Font_T54.h" | |
230 #include "Fonts/Font_T48_plus.h" | |
231 #include "Fonts/Font_T24.h" | |
232 #include "Fonts/Font_T42.h" | |
233 #include "Fonts/image_battery.h" | |
234 #include "Fonts/image_heinrichs_weikamp.h" | |
235 #include "Fonts/image_ostc.h" | |
236 | |
30 | 237 // From Discovery/Inc (shall be shared...) |
238 #include "data_exchange_main.h" | |
239 #include "display.h" | |
240 #include "gfx_engine.h" | |
241 #include "ostc.h" | |
242 #include "tComm.h" | |
243 #include "tStructure.h" | |
244 | |
245 // From AC6 support: | |
246 #include <stdio.h> | |
247 #include <string.h> // for memcopy | |
248 | |
249 /* Private define ------------------------------------------------------------*/ | |
250 #define BUFFER_SIZE ((uint32_t)0x00177000) | |
251 #define WRITE_READ_ADDR ((uint32_t)0x0000) | |
252 #define REFRESH_COUNT ((uint32_t)0x0569) /* SDRAM refresh counter (90Mhz SD clock) */ | |
253 | |
254 /* Private macro -------------------------------------------------------------*/ | |
255 /* Private variables ---------------------------------------------------------*/ | |
256 uint8_t returnFromCommCleanUpRequest = 0; | |
257 | |
258 const SFirmwareData bootloader_FirmwareData __attribute__(( section(".bootloader_firmware_data") )) = | |
259 { | |
260 .versionFirst = 1, | |
261 .versionSecond = 0, | |
262 .versionThird = 1, | |
263 .versionBeta = 1, | |
264 | |
265 /* 4 bytes with trailing 0 */ | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
266 .signature = "mh", |
30 | 267 |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
268 .release_year = 25, |
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
269 .release_month = 1, |
963
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
270 .release_day = 13, |
30 | 271 .release_sub = 0, |
272 | |
273 /* max 48 with trailing 0 */ | |
274 .release_info ="tComm with all", | |
275 | |
276 /* for safety reasons and coming functions*/ | |
277 .magic[0] = FIRMWARE_MAGIC_FIRST, | |
278 .magic[1] = FIRMWARE_MAGIC_SECOND, | |
279 .magic[2] = FIRMWARE_MAGIC_FIRMWARE, /* the magic byte */ | |
280 .magic[3] = FIRMWARE_MAGIC_END | |
281 }; | |
282 | |
965 | 283 const SHardwareData HardwareData __attribute__((section(".bootloader_hardware_data"))) = |
963
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
284 { |
30 | 285 |
286 // first 52 bytes | |
287 .primarySerial = 0xFFFF, | |
963
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
288 .primaryLicence = 0x00, |
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
289 .revision8bit = 0x02, |
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
290 .production_year = 0x19, |
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
291 .production_month = 0x01, |
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
292 .production_day = 0x10, |
30 | 293 .production_bluetooth_name_set = 0xFF, |
294 | |
295 .production_info = { | |
963
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
296 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x4F,0x53,0x54,0x43, |
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
297 0x20,0x35,0x20,0x65,0x6E,0x64,0x2D,0x32,0x30,0x32,0x34, |
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
298 0x20,0x68,0x61,0x72,0x64,0x77,0x61,0x72,0x65,0x20,0x20, |
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
299 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20}, |
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
300 |
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
301 /* 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
30 | 302 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
303 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | |
304 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | |
963
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
305 */ |
30 | 306 // other 12 bytes (64 in total) |
307 .secondarySerial = 0xFFFF, | |
308 .secondaryLicence = 0xFF, | |
309 .secondaryReason8bit = 0xFF, | |
310 .secondary_year = 0xFF, | |
311 .secondary_month = 0xFF, | |
312 .secondary_day = 0xFF, | |
313 .secondary_bluetooth_name_set = 0xFF, | |
314 .secondary_info = {0xFF,0xFF,0xFF,0xFF} | |
315 }; | |
963
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
316 |
30 | 317 |
318 RTC_HandleTypeDef RtcHandle; | |
319 TIM_HandleTypeDef TimHandle; /* used in stm32f4xx_it.c too */ | |
320 TIM_HandleTypeDef TimBacklightHandle; /* used in stm32f4xx_it.c too */ | |
321 | |
322 uint32_t time_before; | |
323 uint32_t time_between; | |
324 uint32_t time_after; | |
325 | |
326 /* SDRAM handler declaration */ | |
327 SDRAM_HandleTypeDef hsdram; | |
328 FMC_SDRAM_TimingTypeDef SDRAM_Timing; | |
329 FMC_SDRAM_CommandTypeDef command; | |
330 | |
331 FLASH_OBProgramInitTypeDef OBInit; | |
332 FLASH_AdvOBProgramInitTypeDef AdvOBInit; | |
333 | |
334 | |
335 /* Private variables with external access ------------------------------------*/ | |
336 | |
337 uint32_t globalStateID = 0; | |
338 uint8_t globalModeID = SURFMODE; | |
339 uint32_t time_without_button_pressed_deciseconds = 0; | |
340 uint8_t bootToBootloader = 0; | |
341 | |
342 /* Private function prototypes -----------------------------------------------*/ | |
343 | |
344 //static void LCD_ToggleFramebuffer(GFX_DrawCfgTypeDef *hconfig); | |
345 //static void LCD_Config(GFX_DrawCfgTypeDef *hconfig); | |
346 static void SystemClock_Config(void); | |
347 static void Error_Handler(void); | |
348 | |
349 static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command); | |
350 static void SDRAM_Config(void); | |
351 //static void DualBoot(void); | |
352 static void EXTILine_Buttons_Config(void); | |
353 //static void RTC_init(void); | |
354 static void TIM_init(void); | |
355 static void TIM_BACKLIGHT_init(void); | |
356 //static void TIM_BACKLIGHT_adjust(void); | |
357 static void gotoSleep(void); | |
358 uint8_t checkResetForFirmwareUpdate(void); | |
359 void DeleteResetToFirmwareUpdateRegister(void); | |
360 void reset_to_firmware_using_Watchdog(void); | |
361 void reset_to_update_using_system_reset(void); | |
362 | |
363 //static void DualBootToBootloader(void); | |
364 | |
365 /* ITM Trace-------- ---------------------------------------------------------*/ | |
366 /* | |
367 #define ITM_Port8(n) (*((volatile unsigned char *)(0xE0000000+4*n))) | |
368 #define ITM_Port16(n) (*((volatile unsigned short*)(0xE0000000+4*n))) | |
369 #define ITM_Port32(n) (*((volatile unsigned long *)(0xE0000000+4*n))) | |
370 | |
371 #define DEMCR (*((volatile unsigned long *)(0xE000EDFC))) | |
372 #define TRCENA 0x01000000 | |
373 | |
374 struct __FILE { int handle; }; | |
375 FILE __stdout; | |
376 FILE __stdin; | |
377 | |
378 int fputc(int ch, FILE *f) { | |
379 if (DEMCR & TRCENA) { | |
380 while (ITM_Port32(0) == 0); | |
381 ITM_Port8(0) = ch; | |
382 } | |
383 return(ch); | |
384 } | |
385 */ | |
386 | |
387 /* Private functions ---------------------------------------------------------*/ | |
388 | |
389 /** | |
390 * @brief Main program | |
391 * @param None | |
392 * @retval None | |
393 */ | |
394 | |
395 void GPIO_test_I2C_lines(void) | |
396 { | |
397 GPIO_InitTypeDef GPIO_InitStructure; | |
398 __GPIOA_CLK_ENABLE(); | |
399 __GPIOG_CLK_ENABLE(); | |
400 GPIO_InitStructure.Pin = GPIO_PIN_7; | |
401 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
402 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
403 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
404 HAL_GPIO_Init(GPIOG, &GPIO_InitStructure); | |
405 GPIO_InitStructure.Pin = GPIO_PIN_3; | |
406 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); | |
407 | |
408 while(1) | |
409 { | |
410 HAL_GPIO_WritePin(GPIOG,GPIO_PIN_7,GPIO_PIN_SET); | |
411 HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3,GPIO_PIN_RESET); | |
412 HAL_Delay(10); | |
413 HAL_GPIO_WritePin(GPIOG,GPIO_PIN_7,GPIO_PIN_RESET); | |
414 HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3,GPIO_PIN_SET); | |
415 HAL_Delay(10); | |
416 } | |
417 } | |
418 | |
419 | |
420 int main(void) | |
421 { | |
422 | |
423 /* | |
424 HAL_Init(); | |
425 SystemClock_Config(); | |
426 GPIO_test_I2C_lines(); | |
427 */ | |
428 uint32_t pLayerInvisible; | |
429 uint32_t firmware_load_result; | |
430 uint8_t magicbyte = 0; | |
431 uint8_t callForUpdate; | |
432 uint8_t status = 0; | |
433 char textVersion[32]; | |
434 uint8_t ptr; | |
435 uint32_t pOffset; | |
436 | |
869 | 437 const SHardwareData* HardwareData = hardwareDataGetPointer(); |
438 | |
30 | 439 set_globalState(StBoot0); |
440 | |
441 HAL_Init(); | |
442 HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_2); | |
869 | 443 SystemClock_Config(); |
444 | |
445 MX_GPIO_Init(); | |
30 | 446 |
447 /* button press is only 40 to 50 us low */ | |
448 MX_GPIO_One_Button_only_Init(); | |
449 | |
450 uint32_t i = 500000; | |
451 | |
452 callForUpdate = __HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST); | |
453 | |
454 if(callForUpdate) | |
455 { | |
456 i = 0; | |
457 } | |
458 else | |
459 if( (firmware_MainCodeIsProgammed() == 0) | |
869 | 460 || (HardwareData->primarySerial == 0xFFFF) |
461 || (HardwareData->production_bluetooth_name_set == 0xFF)) | |
30 | 462 { |
463 i = 1; | |
464 } | |
465 else | |
466 { | |
467 while(MX_GPIO_Read_The_One_Button() && i) | |
468 { | |
469 i--; | |
470 __NOP(); | |
471 } | |
472 if(i) | |
473 { | |
474 i = 200000; | |
475 while(!MX_GPIO_Read_The_One_Button() && i) | |
476 { | |
477 i--; | |
478 __NOP(); | |
479 } | |
480 if(i) | |
481 { | |
482 i = 200000; | |
483 while(MX_GPIO_Read_The_One_Button() && i) | |
484 { | |
485 i--; | |
486 __NOP(); | |
487 } | |
488 if(i) | |
489 { | |
490 i = 200000; | |
491 while(!MX_GPIO_Read_The_One_Button() && i) | |
492 { | |
493 i--; | |
494 __NOP(); | |
495 } | |
496 if(i) | |
497 { | |
498 i = 200000; | |
499 while(MX_GPIO_Read_The_One_Button() && i) | |
500 { | |
501 i--; | |
502 __NOP(); | |
503 } | |
504 } | |
505 } | |
506 } | |
507 } | |
508 } | |
509 | |
510 if((i == 0) && (callForUpdate == 0)) | |
511 firmware_JumpTo_Application(); | |
512 | |
513 MX_SPI_Init(); | |
514 SDRAM_Config(); | |
515 HAL_Delay(100); | |
516 | |
517 GFX_init1_no_DMA(&pLayerInvisible, 2); | |
518 | |
519 TIM_BACKLIGHT_init(); | |
520 | |
521 // ----------------------------- | |
522 | |
523 display_power_on__1_of_2__pre_RGB(); | |
524 GFX_LTDC_Init(); | |
525 GFX_LTDC_LayerDefaultInit(TOP_LAYER, pLayerInvisible); | |
526 GFX_LTDC_LayerDefaultInit(BACKGRD_LAYER, pLayerInvisible); | |
527 GFX_SetFramesTopBottom(pLayerInvisible,pLayerInvisible,480); | |
528 HAL_Delay(20); | |
529 display_power_on__2_of_2__post_RGB(); | |
530 | |
531 // ----------------------------- | |
532 GFX_change_LTDC(); | |
533 GFX_hwBackgroundOn(); | |
534 GFX_change_LTDC(); | |
535 // ----------------------------- | |
536 tInfoBootloader_init(); | |
537 // ----------------------------- | |
538 if(i == 0) | |
539 { | |
540 tInfo_newpage("load firmware data"); | |
541 uint8_t* pBuffer = (uint8_t*)((uint32_t)0xD0000000); /* blocked via GFX_init1_no_DMA */ | |
542 firmware_load_result = ext_flash_read_firmware(pBuffer,768000, &magicbyte); | |
543 | |
544 if((firmware_load_result > 0) && (firmware_load_result < 768000) && (magicbyte == 0xEE)) | |
545 { | |
546 ptr = ext_flash_read_firmware_version(textVersion); | |
547 textVersion[ptr++] = 'f'; | |
548 textVersion[ptr++] = 'o'; | |
549 textVersion[ptr++] = 'u'; | |
550 textVersion[ptr++] = 'n'; | |
551 textVersion[ptr++] = 'd'; | |
552 textVersion[ptr] = 0; | |
553 | |
554 tInfo_newpage(textVersion); | |
555 tInfo_write("erase flash"); | |
556 status = firmware_eraseFlashMemory(); | |
557 if(status != HAL_OK) | |
558 { | |
559 tInfo_newpage("error. try again."); | |
560 status = firmware_eraseFlashMemory(); | |
561 if(status != HAL_OK) | |
562 { | |
563 tInfo_newpage("error. skip update."); | |
564 HAL_Delay(1000); | |
565 } | |
566 } | |
567 if(status == HAL_OK) | |
568 { | |
252 | 569 tInfo_write("program flash"); |
30 | 570 status = firmware_programFlashMemory(pBuffer,firmware_load_result); |
571 if(status != HAL_OK) | |
572 { | |
573 tInfo_newpage("error. try again."); | |
574 status = firmware_programFlashMemory(pBuffer,firmware_load_result); | |
575 if(status != HAL_OK) | |
576 { | |
577 tInfo_newpage("error. skip update."); | |
578 HAL_Delay(1000); | |
579 } | |
580 } | |
581 } | |
582 } | |
583 } | |
584 | |
585 /* here comes the variable upper firmware loader */ | |
586 if((i == 0) && (status == HAL_OK)) | |
587 { | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
588 tInfo_newpage("load fontpack data"); |
30 | 589 uint8_t* pBuffer = (uint8_t*)((uint32_t)0xD0000000); /* blocked via GFX_init1_no_DMA */ |
590 firmware_load_result = ext_flash_read_firmware2(&pOffset, pBuffer,768000*2,0,0); | |
591 | |
592 if((firmware_load_result > 0) && (firmware_load_result + pOffset <= 1024000)) | |
593 { | |
594 ptr = 0; | |
595 ptr += gfx_number_to_string(7,0,&textVersion[ptr],firmware_load_result); | |
596 textVersion[ptr++] = ' '; | |
597 textVersion[ptr++] = 'b'; | |
598 textVersion[ptr++] = 'y'; | |
599 textVersion[ptr++] = 't'; | |
600 textVersion[ptr++] = 'e'; | |
601 textVersion[ptr++] = 's'; | |
602 textVersion[ptr++] = ' '; | |
603 textVersion[ptr++] = 'w'; | |
604 textVersion[ptr++] = 'i'; | |
605 textVersion[ptr++] = 't'; | |
606 textVersion[ptr++] = 'h'; | |
607 textVersion[ptr++] = ' '; | |
608 ptr += gfx_number_to_string(7,0,&textVersion[ptr],pOffset); | |
609 textVersion[ptr++] = ' '; | |
610 textVersion[ptr++] = 'o'; | |
611 textVersion[ptr++] = 'f'; | |
612 textVersion[ptr++] = 'f'; | |
613 textVersion[ptr++] = 's'; | |
614 textVersion[ptr++] = 'e'; | |
615 textVersion[ptr++] = 't'; | |
616 textVersion[ptr] = 0; | |
617 tInfo_newpage(textVersion); | |
618 | |
619 ptr = 0; | |
620 textVersion[ptr++] = 'f'; | |
621 textVersion[ptr++] = 'o'; | |
622 textVersion[ptr++] = 'u'; | |
623 textVersion[ptr++] = 'n'; | |
624 textVersion[ptr++] = 'd'; | |
625 textVersion[ptr] = 0; | |
626 | |
627 tInfo_write(textVersion); | |
628 tInfo_write("erase flash"); | |
629 status = firmware2_variable_upperpart_eraseFlashMemory(firmware_load_result,pOffset); | |
630 if(status != HAL_OK) | |
631 { | |
632 tInfo_newpage("error. try again."); | |
633 status = firmware2_variable_upperpart_eraseFlashMemory(firmware_load_result,pOffset); | |
634 if(status != HAL_OK) | |
635 { | |
636 tInfo_newpage("error. skip update."); | |
637 HAL_Delay(1000); | |
638 } | |
639 } | |
640 if(status == HAL_OK) | |
641 { | |
252 | 642 tInfo_write("program flash"); |
30 | 643 status = firmware2_variable_upperpart_programFlashMemory(firmware_load_result,pOffset,pBuffer,firmware_load_result,0); |
644 if(status != HAL_OK) | |
645 { | |
646 tInfo_newpage("error. try again."); | |
647 status = firmware2_variable_upperpart_programFlashMemory(firmware_load_result,pOffset,pBuffer,firmware_load_result,0); | |
648 if(status != HAL_OK) | |
649 { | |
650 tInfo_newpage("error. skip update."); | |
651 HAL_Delay(1000); | |
652 } | |
653 } | |
654 } | |
655 } | |
656 } | |
657 | |
658 if((i == 0) && (status == HAL_OK)) | |
659 { | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
660 tInfo_newpage("done."); |
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
661 tInfo_write("cleaning."); |
30 | 662 ext_flash_erase_firmware_if_not_empty(); |
663 ext_flash_erase_firmware2_if_not_empty(); | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
664 tInfo_write("reset device."); |
30 | 665 reset_to_firmware_using_Watchdog(); |
666 } | |
667 | |
668 ptr = 0; | |
880 | 669 textVersion[ptr++] = '\020'; |
30 | 670 textVersion[ptr++] = 's'; |
671 textVersion[ptr++] = 'e'; | |
672 textVersion[ptr++] = 'r'; | |
673 textVersion[ptr++] = 'i'; | |
674 textVersion[ptr++] = 'a'; | |
675 textVersion[ptr++] = 'l'; | |
676 textVersion[ptr++] = ' '; | |
869 | 677 if(HardwareData->primarySerial == 0xFFFF) |
30 | 678 { |
679 textVersion[ptr++] = 'n'; | |
680 textVersion[ptr++] = 'o'; | |
681 textVersion[ptr++] = 't'; | |
682 textVersion[ptr++] = ' '; | |
683 textVersion[ptr++] = 's'; | |
684 textVersion[ptr++] = 'e'; | |
685 textVersion[ptr++] = 't'; | |
686 } | |
869 | 687 else if(HardwareData->secondarySerial == 0xFFFF) |
30 | 688 { |
689 textVersion[ptr++] = '#'; | |
869 | 690 ptr += gfx_number_to_string(5,1,&textVersion[ptr],HardwareData->primarySerial); |
30 | 691 } |
692 else | |
693 { | |
694 textVersion[ptr++] = '#'; | |
869 | 695 ptr += gfx_number_to_string(5,1,&textVersion[ptr],HardwareData->secondarySerial); |
30 | 696 textVersion[ptr++] = ' '; |
697 textVersion[ptr++] = '('; | |
869 | 698 ptr += gfx_number_to_string(5,1,&textVersion[ptr],HardwareData->primarySerial); |
30 | 699 textVersion[ptr++] = ')'; |
700 } | |
701 textVersion[ptr++] = '\020'; | |
702 textVersion[ptr] = 0; | |
703 | |
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
704 TIM_init(); |
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
705 MX_UART_Init(); |
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
706 MX_Bluetooth_PowerOn(); |
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
707 tComm_init(); |
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
708 |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
709 tInfo_button_text("exit","","sleep"); |
963
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
710 tInfo_newpage("bootloader 250113"); |
30 | 711 tInfo_write("start bluetooth"); |
712 tInfo_write(""); | |
713 tInfo_write(textVersion); | |
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
714 if(tComm_Set_Bluetooth_Name(0) == 0xFF) |
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
715 { |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
716 tInfo_write("init bluetooth"); |
986 | 717 tComm_StartBlueModBaseInit(); |
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
718 } |
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
719 else |
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
720 { |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
721 tInfo_write("bluetooth set"); |
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
722 tComm_StartBlueModConfig(); |
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
723 } |
30 | 724 |
725 set_globalState_Base(); | |
726 | |
727 GFX_start_VSYNC_IRQ(); | |
728 | |
729 EXTILine_Buttons_Config(); | |
730 /* | |
731 uint8_t* pBuffer1 = (uint8_t*)getFrame(20); | |
732 firmware_load_result = ext_flash_read_firmware(pBuffer1,768000); | |
733 | |
734 if((firmware_load_result > 0) && (firmware_load_result < 768000)) | |
735 { | |
736 firmware_eraseFlashMemory(); | |
737 firmware_programFlashMemory(pBuffer1,firmware_load_result); | |
738 // not for testing | |
739 //ext_flash_erase_firmware_if_not_empty(); | |
740 reset_to_firmware_using_Watchdog(); | |
741 } | |
742 */ | |
743 while(1) | |
744 { | |
745 // if(bootToBootloader) | |
746 // DualBootToBootloader(); | |
747 | |
748 if(bootToBootloader) | |
749 reset_to_update_using_system_reset(); | |
750 | |
751 tComm_control(); // will stop while loop if tComm Mode started until exit from UART | |
752 }; | |
753 } | |
754 | |
755 | |
756 void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) | |
757 { | |
758 | |
759 SStateList status; | |
760 | |
761 get_globalStateList(&status); | |
762 | |
763 switch(status.base) | |
764 { | |
765 default: | |
766 // TIM_BACKLIGHT_adjust(); | |
767 break; | |
768 } | |
769 | |
770 if(returnFromCommCleanUpRequest) | |
771 { | |
772 tComm_exit(); | |
773 returnFromCommCleanUpRequest = 0; | |
774 GFX_hwBackgroundOn(); | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
775 tInfo_button_text("exit","","sleep"); |
30 | 776 tInfo_newpage("bluetooth disonnected"); |
777 tInfo_write(""); | |
778 tInfo_write(""); | |
779 tInfo_write(""); | |
780 tInfo_write(""); | |
781 } | |
782 | |
783 get_globalStateList(&status); | |
784 | |
785 switch(status.base) | |
786 { | |
787 case BaseComm: | |
788 if(get_globalState() == StUART_STANDARD) | |
789 tComm_refresh(); | |
790 break; | |
791 default: | |
792 break; | |
793 } | |
794 } | |
795 | |
796 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) | |
797 { | |
798 uint8_t action; | |
799 SStateList status; | |
800 static uint8_t counterToPreventSleep = 0; | |
801 if(GPIO_Pin == VSYNC_IRQ_PIN) // rechts, unten | |
802 { | |
803 GFX_change_LTDC(); | |
804 housekeepingFrame(); | |
805 if(counterToPreventSleep < 250) | |
806 counterToPreventSleep++; | |
807 else | |
808 if(counterToPreventSleep != 255) | |
809 { | |
810 counterToPreventSleep = 255; | |
811 } | |
812 | |
813 return; | |
814 } | |
815 | |
816 time_without_button_pressed_deciseconds = 0; | |
817 | |
818 if(GFX_logoStatus() != 0) | |
819 return; | |
820 | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
821 if(GPIO_Pin == BUTTON_BACK_PIN) // left |
30 | 822 action = ACTION_BUTTON_BACK; |
823 else | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
824 if(GPIO_Pin == BUTTON_ENTER_PIN) // center |
30 | 825 action = ACTION_BUTTON_ENTER; |
826 else | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
827 if(GPIO_Pin == BUTTON_NEXT_PIN) // right |
30 | 828 action = ACTION_BUTTON_NEXT; |
829 #ifdef BUTTON_CUSTOM_PIN | |
830 else | |
831 if(GPIO_Pin == BUTTON_CUSTOM_PIN) // extra | |
832 action = ACTION_BUTTON_CUSTOM; | |
833 #endif | |
834 else | |
835 action = 0; | |
836 get_globalStateList(&status); | |
837 | |
971 | 838 if(status.base == BaseComm) |
30 | 839 { |
840 if(action == ACTION_BUTTON_BACK) | |
841 { | |
842 reset_to_firmware_using_Watchdog(); | |
843 } | |
971 | 844 } |
845 else | |
846 { | |
847 switch (action) | |
848 { | |
849 case ACTION_BUTTON_NEXT: if((counterToPreventSleep == 255) && (get_globalState() == StS)) | |
850 { | |
851 while(1) | |
852 { | |
853 MX_tell_reset_logik_alles_ok(); | |
854 DataEX_call(); | |
855 HAL_Delay(100); | |
856 } | |
857 } | |
858 break; | |
859 case ACTION_BUTTON_BACK: reset_to_firmware_using_Watchdog(); | |
860 break; | |
861 case ACTION_BUTTON_CUSTOM: if(get_globalState() == StS) | |
862 { | |
863 gotoSleep(); | |
864 } | |
865 break; | |
866 case ACTION_BUTTON_ENTER: /* reset_to_update_using_system_reset(); old function */ | |
867 tComm_StartBlueModBaseInit(); /* new: factory reset bluetooth */ | |
868 break; | |
869 default: | |
870 break; | |
871 } | |
30 | 872 } |
873 } | |
874 | |
875 | |
876 void gotoSleep(void) | |
877 { | |
878 ext_flash_erase_firmware_if_not_empty(); | |
879 set_globalState(StStop); | |
880 } | |
881 | |
882 // ----------------------------- | |
883 | |
884 | |
885 void MainBootLoaderInit(void) | |
886 { | |
887 void (*SysMemBootJump)(void); | |
888 SysMemBootJump=(void (*)(void)) (*((uint32_t *) 0x1fff0004)); | |
889 | |
890 // DMA, SPI, UART, TIM, ExtIRQ, graphics DMA, LTDC | |
891 | |
892 HAL_RCC_DeInit(); | |
893 SysTick->CTRL = 0; | |
894 SysTick->LOAD = 0; | |
895 SysTick->VAL = 0; | |
896 | |
897 __set_PRIMASK(1); | |
898 | |
899 __set_MSP(0x20002318); | |
900 SysMemBootJump(); | |
901 } | |
902 | |
903 uint32_t get_globalState(void) | |
904 { | |
905 return globalStateID; | |
906 } | |
907 | |
908 void get_globalStateList(SStateList *output) | |
909 { | |
910 output->base = (uint8_t)((globalStateID >> 28) & 0x0F); | |
911 output->page = (uint8_t)((globalStateID >> 24) & 0x0F); | |
912 output->line = (uint8_t)((globalStateID >> 16) & 0xFF); | |
913 output->field = (uint8_t)((globalStateID >> 8) & 0xFF); | |
914 output->mode = (uint8_t)((globalStateID ) & 0xFF); | |
915 } | |
916 | |
917 void get_idSpecificStateList(uint32_t id, SStateList *output) | |
918 { | |
919 output->base = (uint8_t)((id >> 28) & 0x0F); | |
920 output->page = (uint8_t)((id >> 24) & 0x0F); | |
921 output->line = (uint8_t)((id >> 16) & 0xFF); | |
922 output->field = (uint8_t)((id >> 8) & 0xFF); | |
923 output->mode = (uint8_t)((id ) & 0xFF); | |
924 } | |
925 | |
926 void set_globalState_Base(void) | |
927 { | |
928 set_globalState(StS); | |
929 } | |
930 | |
931 void set_globalState_Menu_Page(uint8_t page) | |
932 { | |
933 globalStateID = ((BaseMenu << 28) + (page << 24)); | |
934 } | |
935 | |
936 void set_globalState_Log_Page(uint8_t pageIsLine) | |
937 { | |
938 globalStateID = StILOGLIST + (pageIsLine << 16); | |
939 } | |
940 | |
941 | |
942 void set_globalState_Menu_Line(uint8_t line) | |
943 { | |
944 globalStateID = ((globalStateID & MaskLineFieldDigit) + (line << 16)); | |
945 } | |
946 | |
947 | |
948 void set_globalState(uint32_t newID) | |
949 { | |
950 globalStateID = newID; | |
951 } | |
952 | |
953 | |
954 | |
955 void delayMicros(uint32_t micros) | |
956 { | |
957 micros = micros * (168/4) - 10; | |
958 while(micros--); | |
959 } | |
960 | |
961 | |
962 void get_RTC_DateTime(RTC_DateTypeDef * sdatestructureget, RTC_TimeTypeDef * stimestructureget) | |
963 { | |
964 /* Get the RTC current Time */ | |
965 if(sdatestructureget) | |
966 HAL_RTC_GetTime(&RtcHandle, stimestructureget, FORMAT_BIN); | |
967 /* Get the RTC current Date */ | |
968 if(stimestructureget) | |
969 HAL_RTC_GetDate(&RtcHandle, sdatestructureget, FORMAT_BIN); | |
970 } | |
971 | |
972 | |
973 void set_RTC_DateTime(RTC_DateTypeDef * sdatestructure, RTC_TimeTypeDef * stimestructure) | |
974 { | |
975 if(sdatestructure) | |
976 if(HAL_RTC_SetDate(&RtcHandle,sdatestructure,FORMAT_BCD) != HAL_OK) | |
977 { | |
978 /* Initialization Error */ | |
979 Error_Handler(); | |
980 } | |
981 | |
982 if(stimestructure) | |
983 if(HAL_RTC_SetTime(&RtcHandle,stimestructure,FORMAT_BCD) != HAL_OK) | |
984 { | |
985 /* Initialization Error */ | |
986 Error_Handler(); | |
987 } | |
988 } | |
989 | |
990 static void TIM_init(void) | |
991 { | |
992 uint16_t uwPrescalerValue = 0; | |
993 | |
994 uwPrescalerValue = (uint32_t) ((SystemCoreClock /2) / 10000) - 1; | |
995 | |
996 /* Set TIMx instance */ | |
997 TimHandle.Instance = TIMx; | |
998 | |
999 /* Initialize TIM3 peripheral as follows: | |
1000 + Period = 10000 - 1 | |
1001 + Prescaler = ((SystemCoreClock/2)/10000) - 1 | |
1002 + ClockDivision = 0 | |
1003 + Counter direction = Up | |
1004 */ | |
1005 TimHandle.Init.Period = 1000 - 1; | |
1006 TimHandle.Init.Prescaler = uwPrescalerValue; | |
1007 TimHandle.Init.ClockDivision = 0; | |
1008 TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; | |
1009 if(HAL_TIM_Base_Init(&TimHandle) != HAL_OK) | |
1010 { | |
1011 /* Initialization Error */ | |
1012 Error_Handler(); | |
1013 } | |
1014 | |
1015 /*##-2- Start the TIM Base generation in interrupt mode ####################*/ | |
1016 /* Start Channel1 */ | |
1017 if(HAL_TIM_Base_Start_IT(&TimHandle) != HAL_OK) | |
1018 { | |
1019 /* Starting Error */ | |
1020 Error_Handler(); | |
1021 } | |
1022 } | |
1023 | |
1024 #ifndef TIM_BACKLIGHT | |
1025 /* | |
1026 static void TIM_BACKLIGHT_adjust(void) | |
1027 { | |
1028 } | |
1029 */ | |
1030 static void TIM_BACKLIGHT_init(void) | |
1031 { | |
1032 } | |
1033 #else | |
1034 /* | |
1035 static void TIM_BACKLIGHT_adjust(void) | |
1036 { | |
1037 | |
1038 TIM_OC_InitTypeDef sConfig; | |
1039 sConfig.OCMode = TIM_OCMODE_PWM1; | |
1040 sConfig.OCPolarity = TIM_OCPOLARITY_HIGH; | |
1041 sConfig.OCFastMode = TIM_OCFAST_DISABLE; | |
1042 sConfig.Pulse = 600; | |
1043 | |
1044 HAL_TIM_PWM_ConfigChannel(&TimBacklightHandle, &sConfig, TIM_BACKLIGHT_CHANNEL); | |
1045 HAL_TIM_PWM_Start(&TimBacklightHandle, TIM_BACKLIGHT_CHANNEL); | |
1046 } | |
1047 */ | |
1048 static void TIM_BACKLIGHT_init(void) | |
1049 { | |
1050 uint32_t uwPrescalerValue = 0; | |
1051 TIM_OC_InitTypeDef sConfig; | |
1052 | |
1053 uwPrescalerValue = (uint32_t) ((SystemCoreClock /2) / 18000000) - 1; | |
1054 | |
1055 TimBacklightHandle.Instance = TIM_BACKLIGHT; | |
1056 | |
1057 // Initialize TIM3 peripheral as follows: 30 kHz | |
1058 | |
1059 TimBacklightHandle.Init.Period = 600 - 1; | |
1060 TimBacklightHandle.Init.Prescaler = uwPrescalerValue; | |
1061 TimBacklightHandle.Init.ClockDivision = 0; | |
1062 TimBacklightHandle.Init.CounterMode = TIM_COUNTERMODE_UP; | |
1063 HAL_TIM_PWM_Init(&TimBacklightHandle); | |
1064 | |
1065 sConfig.OCMode = TIM_OCMODE_PWM1; | |
1066 sConfig.OCPolarity = TIM_OCPOLARITY_HIGH; | |
1067 sConfig.OCFastMode = TIM_OCFAST_DISABLE; | |
1068 sConfig.Pulse = 50 * 6; | |
1069 | |
1070 HAL_TIM_PWM_ConfigChannel(&TimBacklightHandle, &sConfig, TIM_BACKLIGHT_CHANNEL); | |
1071 HAL_TIM_PWM_Start(&TimBacklightHandle, TIM_BACKLIGHT_CHANNEL); | |
1072 } | |
1073 #endif | |
1074 | |
1075 /* Configure RTC prescaler and RTC data registers */ | |
1076 /* RTC configured as follow: | |
1077 - Hour Format = Format 24 | |
1078 - Asynch Prediv = Value according to source clock | |
1079 - Synch Prediv = Value according to source clock | |
1080 - OutPut = Output Disable | |
1081 - OutPutPolarity = High Polarity | |
1082 - OutPutType = Open Drain */ | |
1083 /*#define RTC_ASYNCH_PREDIV 0x7F LSE as RTC clock */ | |
1084 /*LSE: #define RTC_SYNCH_PREDIV 0x00FF LSE as RTC clock */ | |
1085 /*LSI: #define RTC_SYNCH_PREDIV 0x0130 LSI as RTC clock */ | |
1086 /* | |
1087 static void RTC_init(void) | |
1088 { | |
1089 RtcHandle.Instance = RTC; | |
1090 | |
1091 | |
1092 RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24; | |
1093 RtcHandle.Init.AsynchPrediv = 0x7F; | |
1094 RtcHandle.Init.SynchPrediv = 0x0130; | |
1095 RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE; | |
1096 RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; | |
1097 RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; | |
1098 | |
1099 if(HAL_RTC_Init(&RtcHandle) != HAL_OK) | |
1100 { | |
1101 Error_Handler(); | |
1102 } | |
1103 } | |
1104 */ | |
1105 | |
1106 static void EXTILine_Buttons_Config(void) | |
1107 { | |
1108 GPIO_InitTypeDef GPIO_InitStructure; | |
1109 | |
1110 BUTTON_ENTER_GPIO_ENABLE(); | |
1111 BUTTON_NEXT_GPIO_ENABLE(); | |
1112 BUTTON_BACK_GPIO_ENABLE(); | |
1113 | |
1114 /* Configure pin as weak PULLUP input */ | |
1115 /* buttons */ | |
1116 GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING; | |
1117 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
1118 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
1119 | |
1120 GPIO_InitStructure.Pin = BUTTON_ENTER_PIN; | |
1121 HAL_GPIO_Init(BUTTON_ENTER_GPIO_PORT, &GPIO_InitStructure); | |
1122 | |
1123 GPIO_InitStructure.Pin = BUTTON_NEXT_PIN; | |
1124 HAL_GPIO_Init(BUTTON_NEXT_GPIO_PORT, &GPIO_InitStructure); | |
1125 | |
1126 GPIO_InitStructure.Pin = BUTTON_BACK_PIN; | |
1127 HAL_GPIO_Init(BUTTON_BACK_GPIO_PORT, &GPIO_InitStructure); | |
1128 | |
1129 /* Enable and set EXTI Line0 Interrupt to the lowest priority */ | |
1130 HAL_NVIC_SetPriority(BUTTON_ENTER_EXTI_IRQn, 2, 0); | |
1131 HAL_NVIC_SetPriority(BUTTON_NEXT_EXTI_IRQn, 2, 0); | |
1132 HAL_NVIC_SetPriority(BUTTON_BACK_EXTI_IRQn, 2, 0); | |
1133 HAL_NVIC_EnableIRQ(BUTTON_ENTER_EXTI_IRQn); | |
1134 HAL_NVIC_EnableIRQ(BUTTON_NEXT_EXTI_IRQn); | |
1135 HAL_NVIC_EnableIRQ(BUTTON_BACK_EXTI_IRQn); | |
1136 | |
1137 #ifdef BUTTON_CUSTOM_PIN | |
1138 BUTTON_CUSTOM_GPIO_ENABLE(); | |
1139 GPIO_InitStructure.Pin = BUTTON_CUSTOM_PIN; | |
1140 HAL_GPIO_Init(BUTTON_CUSTOM_GPIO_PORT, &GPIO_InitStructure); | |
1141 HAL_NVIC_SetPriority(BUTTON_CUSTOM_EXTI_IRQn, 2, 0); | |
1142 HAL_NVIC_EnableIRQ(BUTTON_CUSTOM_EXTI_IRQn); | |
1143 #endif | |
1144 } | |
1145 | |
1146 | |
1147 /** | |
1148 * @brief System Clock Configuration | |
1149 * The system Clock is configured as follow : | |
1150 * System Clock source = PLL (HSE) | |
1151 * SYSCLK(Hz) = 180000000 | |
1152 * HCLK(Hz) = 180000000 | |
1153 * AHB Prescaler = 1 | |
1154 * APB1 Prescaler = 4 | |
1155 * APB2 Prescaler = 2 | |
1156 * HSE Frequency(Hz) = 8000000 | |
1157 * PLL_M = 8 | |
1158 * PLL_N = 360 | |
1159 * PLL_P = 2 | |
1160 * PLL_Q = 7 | |
1161 * VDD(V) = 3.3 | |
1162 * Main regulator output voltage = Scale1 mode | |
1163 * Flash Latency(WS) = 5 | |
1164 * The LTDC Clock is configured as follow : | |
1165 * PLLSAIN = 192 | |
1166 * PLLSAIR = 4 | |
1167 * PLLSAIDivR = 8 | |
1168 * @param None | |
1169 * @retval None | |
1170 */ | |
1171 static void SystemClock_Config(void) | |
1172 { | |
869 | 1173 /* Enable Power Control clock */ |
1174 __PWR_CLK_ENABLE(); | |
30 | 1175 |
869 | 1176 /* The voltage scaling allows optimizing the power consumption when the device is |
1177 clocked below the maximum system frequency, to update the voltage scaling value | |
1178 regarding system frequency refer to product datasheet. */ | |
1179 __HAL_PWR_VOLTAGESCALING_CONFIG( PWR_REGULATOR_VOLTAGE_SCALE1 ); | |
30 | 1180 |
869 | 1181 /*##-1- System Clock Configuration #########################################*/ |
1182 /* Enable HighSpeed Oscillator and activate PLL with HSE/HSI as source */ | |
1183 RCC_OscInitTypeDef RCC_OscInitStruct = { 0 }; | |
1184 #ifdef DISC1_BOARD | |
1185 // Use High Speed Internal (HSI) oscillator, running at 16MHz. | |
1186 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; | |
1187 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |
1188 RCC_OscInitStruct.HSICalibrationValue = 0x10; | |
1189 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; | |
1190 RCC_OscInitStruct.PLL.PLLM = 16; // HSI/16 is 1Mhz. | |
1191 #else | |
1192 // Use High Speed External oscillator, running at 8MHz | |
1193 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; | |
1194 RCC_OscInitStruct.HSEState = RCC_HSE_ON; | |
1195 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; | |
1196 RCC_OscInitStruct.PLL.PLLM = 8; // HSE/8 is 1Mhz. | |
1197 #endif | |
1198 // System clock = PLL (1MHz) * N/p = 180 MHz. | |
1199 RCC_OscInitStruct.PLL.PLLN = 360; | |
1200 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; | |
1201 RCC_OscInitStruct.PLL.PLLQ = 7; | |
1202 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
1203 HAL_RCC_OscConfig( &RCC_OscInitStruct ); | |
30 | 1204 |
1205 // HAL_PWREx_ActivateOverDrive(); | |
869 | 1206 HAL_PWREx_DeactivateOverDrive(); |
1207 | |
1208 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ | |
1209 RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 }; | |
1210 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | |
1211 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; | |
1212 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
1213 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
1214 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; | |
1215 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; | |
1216 HAL_RCC_ClockConfig( &RCC_ClkInitStruct, FLASH_LATENCY_8 ); //FLASH_LATENCY_5); | |
30 | 1217 |
869 | 1218 /*##-2- LTDC Clock Configuration ###########################################*/ |
1219 /* LCD clock configuration */ | |
1220 /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */ | |
1221 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */ | |
1222 /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 Mhz */ | |
1223 /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDIVR_8 = 48/8 = 6 Mhz */ | |
30 | 1224 |
869 | 1225 /* neu: 8MHz/8*300/5/8 = 7,5 MHz = 19,5 Hz bei 800 x 480 */ |
1226 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; | |
1227 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC; | |
1228 PeriphClkInitStruct.PLLSAI.PLLSAIN = 300; //192; | |
1229 PeriphClkInitStruct.PLLSAI.PLLSAIR = 5; //4; | |
1230 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;//RCC_PLLSAIDIVR_4;// RCC_PLLSAIDIVR_2; // RCC_PLLSAIDIVR_8 | |
1231 HAL_RCCEx_PeriphCLKConfig( &PeriphClkInitStruct ); | |
30 | 1232 } |
1233 | |
1234 | |
1235 /** | |
1236 * @brief This function is executed in case of error occurrence. | |
1237 * @param None | |
1238 * @retval None | |
1239 */ | |
1240 static void Error_Handler(void) | |
1241 { | |
1242 /* Turn LED3 on */ | |
1243 // BSP_LED_On(LED3); | |
1244 while(1) | |
1245 { | |
1246 } | |
1247 } | |
1248 | |
1249 /** | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
1250 * @brief Perform the SDRAM external memory initialization sequence |
30 | 1251 * @param hsdram: SDRAM handle |
1252 * @param Command: Pointer to SDRAM command structure | |
1253 * @retval None | |
1254 */ | |
1255 static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command) | |
1256 { | |
1257 __IO uint32_t tmpmrd =0; | |
1258 /* Step 3: Configure a clock configuration enable command */ | |
1259 Command->CommandMode = FMC_SDRAM_CMD_CLK_ENABLE; | |
1260 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
1261 Command->AutoRefreshNumber = 1; | |
1262 Command->ModeRegisterDefinition = 0; | |
1263 | |
1264 /* Send the command */ | |
1265 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
1266 | |
1267 /* Step 4: Insert 100 ms delay */ | |
1268 HAL_Delay(100); | |
1269 | |
1270 /* Step 5: Configure a PALL (precharge all) command */ | |
1271 Command->CommandMode = FMC_SDRAM_CMD_PALL; | |
1272 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
1273 Command->AutoRefreshNumber = 1; | |
1274 Command->ModeRegisterDefinition = 0; | |
1275 | |
1276 /* Send the command */ | |
1277 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
1278 | |
1279 /* Step 6 : Configure a Auto-Refresh command */ | |
1280 Command->CommandMode = FMC_SDRAM_CMD_AUTOREFRESH_MODE; | |
1281 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
1282 Command->AutoRefreshNumber = 4; | |
1283 Command->ModeRegisterDefinition = 0; | |
1284 | |
1285 /* Send the command */ | |
1286 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
1287 | |
1288 /* Step 7: Program the external memory mode register */ | |
1289 tmpmrd = (uint32_t)SDRAM_MODEREG_BURST_LENGTH_2 | | |
1290 SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL | | |
1291 SDRAM_MODEREG_CAS_LATENCY_3 | | |
1292 SDRAM_MODEREG_OPERATING_MODE_STANDARD | | |
1293 SDRAM_MODEREG_WRITEBURST_MODE_SINGLE; | |
1294 | |
1295 Command->CommandMode = FMC_SDRAM_CMD_LOAD_MODE; | |
1296 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
1297 Command->AutoRefreshNumber = 1; | |
1298 Command->ModeRegisterDefinition = tmpmrd; | |
1299 | |
1300 /* Send the command */ | |
1301 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
1302 | |
1303 /* Step 8: Set the refresh rate counter */ | |
1304 /* (15.62 us x Freq) - 20 */ | |
1305 /* neu: (8 us x Freq) - 20 */ | |
1306 /* Set the device refresh counter */ | |
1307 HAL_SDRAM_ProgramRefreshRate(hsdram, REFRESH_COUNT); | |
1308 } | |
1309 | |
1310 /* | |
1311 static void DualBoot(void) | |
1312 { | |
1313 // Set BFB2 bit to enable boot from Flash Bank2 | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
1314 // Allow Access to Flash control registers and user Flash |
30 | 1315 HAL_FLASH_Unlock(); |
1316 | |
1317 // Allow Access to option bytes sector | |
1318 HAL_FLASH_OB_Unlock(); | |
1319 | |
1320 // Get the Dual boot configuration status | |
1321 AdvOBInit.OptionType = OBEX_BOOTCONFIG; | |
1322 HAL_FLASHEx_AdvOBGetConfig(&AdvOBInit); | |
1323 | |
1324 // Enable/Disable dual boot feature | |
1325 if (((AdvOBInit.BootConfig) & (FLASH_OPTCR_BFB2)) == FLASH_OPTCR_BFB2) | |
1326 { | |
1327 AdvOBInit.BootConfig = OB_DUAL_BOOT_DISABLE; | |
1328 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
1329 } | |
1330 else | |
1331 { | |
1332 AdvOBInit.BootConfig = OB_DUAL_BOOT_ENABLE; | |
1333 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
1334 } | |
1335 | |
1336 // Start the Option Bytes programming process | |
1337 if (HAL_FLASH_OB_Launch() != HAL_OK) | |
1338 { | |
1339 // User can add here some code to deal with this error | |
1340 while (1) | |
1341 { | |
1342 } | |
1343 } | |
1344 // Prevent Access to option bytes sector | |
1345 HAL_FLASH_OB_Lock(); | |
1346 | |
1347 // Disable the Flash option control register access (recommended to protect | |
1348 // the option Bytes against possible unwanted operations) | |
1349 HAL_FLASH_Lock(); | |
1350 | |
1351 // Initiates a system reset request to reset the MCU | |
1352 reset_to_firmware_using_Watchdog(); | |
1353 } | |
1354 */ | |
1355 /** | |
1356 ****************************************************************************** | |
1357 ****************************************************************************** | |
1358 ****************************************************************************** | |
1359 */ | |
1360 | |
1361 | |
1362 /** | |
1363 * @brief DMA2D configuration. | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
1364 * @note This function Configure the DMA2D peripheral : |
30 | 1365 * 1) Configure the transfer mode : memory to memory W/ pixel format conversion |
1366 * 2) Configure the output color mode as ARGB4444 | |
1367 * 3) Configure the output memory address at SRAM memory | |
1368 * 4) Configure the data size : 320x120 (pixels) | |
1369 * 5) Configure the input color mode as ARGB8888 | |
1370 * 6) Configure the input memory address at FLASH memory | |
1371 * @retval | |
1372 * None | |
1373 */ | |
1374 | |
1375 static void SDRAM_Config(void) | |
1376 { | |
1377 /*##-1- Configure the SDRAM device #########################################*/ | |
1378 /* SDRAM device configuration */ | |
1379 hsdram.Instance = FMC_SDRAM_DEVICE; | |
1380 | |
1381 /* Timing configuration for 90 Mhz of SD clock frequency (180Mhz/2) */ | |
1382 /* TMRD: 2 Clock cycles */ | |
1383 SDRAM_Timing.LoadToActiveDelay = 2; | |
1384 /* TXSR: min=70ns (6x11.90ns) */ | |
1385 SDRAM_Timing.ExitSelfRefreshDelay = 7; | |
1386 /* TRAS: min=42ns (4x11.90ns) max=120k (ns) */ | |
1387 SDRAM_Timing.SelfRefreshTime = 4; | |
1388 /* TRC: min=63 (6x11.90ns) */ | |
1389 SDRAM_Timing.RowCycleDelay = 7; | |
1390 /* TWR: 2 Clock cycles */ | |
1391 SDRAM_Timing.WriteRecoveryTime = 2; | |
1392 /* TRP: 15ns => 2x11.90ns */ | |
1393 SDRAM_Timing.RPDelay = 2; | |
1394 /* TRCD: 15ns => 2x11.90ns */ | |
1395 SDRAM_Timing.RCDDelay = 2; | |
1396 | |
1397 hsdram.Init.SDBank = FMC_SDRAM_BANK2; | |
1398 hsdram.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_9; | |
1399 hsdram.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_13; | |
1400 hsdram.Init.MemoryDataWidth = SDRAM_MEMORY_WIDTH; | |
1401 hsdram.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4; | |
1402 hsdram.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3; | |
1403 hsdram.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE; | |
1404 hsdram.Init.SDClockPeriod = SDCLOCK_PERIOD; | |
1405 hsdram.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE; | |
1406 hsdram.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_1; | |
1407 | |
1408 /* Initialize the SDRAM controller */ | |
1409 if(HAL_SDRAM_Init(&hsdram, &SDRAM_Timing) != HAL_OK) | |
1410 { | |
1411 /* Initialization Error */ | |
1412 Error_Handler(); | |
1413 } | |
1414 | |
1415 /* Program the SDRAM external device */ | |
1416 SDRAM_Initialization_Sequence(&hsdram, &command); | |
1417 } | |
1418 | |
1419 | |
1420 uint8_t checkResetForFirmwareUpdate(void) | |
1421 { | |
1422 uint32_t backupRegisterContent; | |
1423 | |
1424 RTC_HandleTypeDef RtcHandle; | |
1425 RtcHandle.Instance = RTC; | |
1426 backupRegisterContent = HAL_RTCEx_BKUPRead(&RtcHandle,RTC_BKP_DR0); | |
1427 | |
1428 if(backupRegisterContent == 0x12345678) | |
1429 return 1; | |
1430 else | |
1431 return 0; | |
1432 } | |
1433 | |
1434 void DeleteResetToFirmwareUpdateRegister(void) | |
1435 { | |
1436 RTC_HandleTypeDef RtcHandle; | |
1437 RtcHandle.Instance = RTC; | |
1438 __HAL_RTC_WRITEPROTECTION_DISABLE(&RtcHandle); | |
1439 HAL_RTCEx_BKUPWrite(&RtcHandle,RTC_BKP_DR0,0x00); | |
1440 __HAL_RTC_WRITEPROTECTION_ENABLE(&RtcHandle); | |
1441 } | |
1442 | |
1443 #ifdef USE_FULL_ASSERT | |
1444 | |
1445 /** | |
1446 * @brief Reports the name of the source file and the source line number | |
1447 * where the assert_param error has occurred. | |
1448 * @param file: pointer to the source file name | |
1449 * @param line: assert_param error line source number | |
1450 * @retval None | |
1451 */ | |
1452 void assert_failed(uint8_t* file, uint32_t line) | |
1453 { | |
1454 /* User can add his own implementation to report the file name and line number, | |
1455 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ | |
1456 | |
1457 /* Infinite loop */ | |
1458 while (1) | |
1459 { | |
1460 } | |
1461 } | |
1462 #endif | |
1463 | |
1464 /* | |
1465 static void DualBootToBootloader(void) | |
1466 { | |
1467 // Set BFB2 bit to enable boot from Flash Bank2 | |
1468 // Allow Access to Flash control registers and user Falsh | |
1469 HAL_FLASH_Unlock(); | |
1470 | |
1471 // Allow Access to option bytes sector | |
1472 HAL_FLASH_OB_Unlock(); | |
1473 | |
1474 // Get the Dual boot configuration status | |
1475 AdvOBInit.OptionType = OPTIONBYTE_BOOTCONFIG; | |
1476 HAL_FLASHEx_AdvOBGetConfig(&AdvOBInit); | |
1477 | |
1478 // Enable/Disable dual boot feature | |
1479 if (((AdvOBInit.BootConfig) & (FLASH_OPTCR_BFB2)) == FLASH_OPTCR_BFB2) | |
1480 { | |
1481 AdvOBInit.BootConfig = OB_DUAL_BOOT_DISABLE; | |
1482 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
1483 if (HAL_FLASH_OB_Launch() != HAL_OK) | |
1484 { | |
1485 while (1) | |
1486 { | |
1487 } | |
1488 } | |
1489 } | |
1490 else | |
1491 { | |
1492 | |
1493 AdvOBInit.BootConfig = OB_DUAL_BOOT_ENABLE; | |
1494 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
1495 if (HAL_FLASH_OB_Launch() != HAL_OK) | |
1496 { | |
1497 while (1) | |
1498 { | |
1499 } | |
1500 } | |
1501 } | |
1502 | |
1503 // Prevent Access to option bytes sector | |
1504 HAL_FLASH_OB_Lock(); | |
1505 | |
1506 / Disable the Flash option control register access (recommended to protect | |
1507 // the option Bytes against possible unwanted operations) | |
1508 HAL_FLASH_Lock(); | |
1509 | |
1510 // Initiates a system reset request to reset the MCU | |
1511 reset_to_firmware_using_Watchdog(); | |
1512 } | |
1513 */ | |
1514 | |
1515 void reset_to_update_using_system_reset(void) | |
1516 { | |
1517 __HAL_RCC_CLEAR_RESET_FLAGS(); | |
1518 HAL_NVIC_SystemReset(); | |
1519 } | |
1520 | |
1521 void reset_to_firmware_using_Watchdog(void) | |
1522 { | |
1523 __HAL_RCC_CLEAR_RESET_FLAGS(); | |
1524 __HAL_RCC_WWDG_CLK_ENABLE(); | |
1525 | |
1526 WWDG_HandleTypeDef WwdgHandle; | |
1527 WwdgHandle.Instance = WWDG; | |
1528 | |
1529 WwdgHandle.Init.Prescaler = WWDG_PRESCALER_8; | |
1530 WwdgHandle.Init.Window = 80; | |
1531 WwdgHandle.Init.Counter = 127; | |
1532 | |
1533 HAL_WWDG_Init(&WwdgHandle); | |
869 | 1534 /* HAL_WWDG_Start(&WwdgHandle); has been removed from HAL library starting_V120 */ |
30 | 1535 while(1); |
1536 } | |
1537 | |
1538 | |
1539 void set_returnFromComm(void) | |
1540 { | |
1541 returnFromCommCleanUpRequest = 1; | |
1542 } | |
1543 | |
1544 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |