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