Mercurial > public > ostc4
annotate BootLoader/Src/base_bootlader.c @ 966:90edc237d60f Evo_2_23
Bluetooth commands for new module:
The new Bluetooth module has a slightly different protocol then the previous => Some configuration steps needs to be skip because parameter is not supported and command structures need to be adapted. In the first step this is done for the Bootloader only.
author | Ideenmodellierer |
---|---|
date | Mon, 13 Jan 2025 20:42:24 +0100 |
parents | 58cc980ee848 |
children | d29e752660c5 |
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"); |
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
719 tComm_StartBlueModBaseInit(); |
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
720 } |
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
721 else |
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
722 { |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
723 tInfo_write("bluetooth set"); |
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
724 tComm_StartBlueModConfig(); |
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
725 } |
30 | 726 |
727 set_globalState_Base(); | |
728 | |
729 GFX_start_VSYNC_IRQ(); | |
730 | |
731 EXTILine_Buttons_Config(); | |
732 /* | |
733 uint8_t* pBuffer1 = (uint8_t*)getFrame(20); | |
734 firmware_load_result = ext_flash_read_firmware(pBuffer1,768000); | |
735 | |
736 if((firmware_load_result > 0) && (firmware_load_result < 768000)) | |
737 { | |
738 firmware_eraseFlashMemory(); | |
739 firmware_programFlashMemory(pBuffer1,firmware_load_result); | |
740 // not for testing | |
741 //ext_flash_erase_firmware_if_not_empty(); | |
742 reset_to_firmware_using_Watchdog(); | |
743 } | |
744 */ | |
745 while(1) | |
746 { | |
747 // if(bootToBootloader) | |
748 // DualBootToBootloader(); | |
749 | |
750 if(bootToBootloader) | |
751 reset_to_update_using_system_reset(); | |
752 | |
753 tComm_control(); // will stop while loop if tComm Mode started until exit from UART | |
754 }; | |
755 } | |
756 | |
757 | |
758 void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) | |
759 { | |
760 | |
761 SStateList status; | |
762 | |
763 get_globalStateList(&status); | |
764 | |
765 switch(status.base) | |
766 { | |
767 default: | |
768 // TIM_BACKLIGHT_adjust(); | |
769 break; | |
770 } | |
771 | |
772 if(returnFromCommCleanUpRequest) | |
773 { | |
774 tComm_exit(); | |
775 returnFromCommCleanUpRequest = 0; | |
776 GFX_hwBackgroundOn(); | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
777 tInfo_button_text("exit","","sleep"); |
30 | 778 tInfo_newpage("bluetooth disonnected"); |
779 tInfo_write(""); | |
780 tInfo_write(""); | |
781 tInfo_write(""); | |
782 tInfo_write(""); | |
783 } | |
784 | |
785 get_globalStateList(&status); | |
786 | |
787 switch(status.base) | |
788 { | |
789 case BaseComm: | |
790 if(get_globalState() == StUART_STANDARD) | |
791 tComm_refresh(); | |
792 break; | |
793 default: | |
794 break; | |
795 } | |
796 } | |
797 | |
798 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) | |
799 { | |
800 uint8_t action; | |
801 SStateList status; | |
802 static uint8_t counterToPreventSleep = 0; | |
803 if(GPIO_Pin == VSYNC_IRQ_PIN) // rechts, unten | |
804 { | |
805 GFX_change_LTDC(); | |
806 housekeepingFrame(); | |
807 if(counterToPreventSleep < 250) | |
808 counterToPreventSleep++; | |
809 else | |
810 if(counterToPreventSleep != 255) | |
811 { | |
812 counterToPreventSleep = 255; | |
813 } | |
814 | |
815 return; | |
816 } | |
817 | |
818 time_without_button_pressed_deciseconds = 0; | |
819 | |
820 if(GFX_logoStatus() != 0) | |
821 return; | |
822 | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
823 if(GPIO_Pin == BUTTON_BACK_PIN) // left |
30 | 824 action = ACTION_BUTTON_BACK; |
825 else | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
826 if(GPIO_Pin == BUTTON_ENTER_PIN) // center |
30 | 827 action = ACTION_BUTTON_ENTER; |
828 else | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
829 if(GPIO_Pin == BUTTON_NEXT_PIN) // right |
30 | 830 action = ACTION_BUTTON_NEXT; |
831 #ifdef BUTTON_CUSTOM_PIN | |
832 else | |
833 if(GPIO_Pin == BUTTON_CUSTOM_PIN) // extra | |
834 action = ACTION_BUTTON_CUSTOM; | |
835 #endif | |
836 else | |
837 action = 0; | |
838 get_globalStateList(&status); | |
839 | |
840 switch(status.base) | |
841 { | |
842 case BaseComm: | |
843 if(action == ACTION_BUTTON_BACK) | |
844 { | |
845 reset_to_firmware_using_Watchdog(); | |
846 } | |
847 break; | |
848 | |
849 default: | |
850 if((action == ACTION_BUTTON_NEXT) && (counterToPreventSleep == 255) && (get_globalState() == StS)) | |
851 { | |
852 while(1) | |
853 { | |
854 MX_tell_reset_logik_alles_ok(); | |
855 DataEX_call(); | |
856 HAL_Delay(100); | |
857 } | |
858 } | |
859 else | |
860 if(action == ACTION_BUTTON_BACK) | |
861 { | |
862 reset_to_firmware_using_Watchdog(); | |
863 } | |
864 else | |
865 if(action == ACTION_BUTTON_CUSTOM) | |
866 { | |
867 if(get_globalState() == StS) | |
868 gotoSleep(); | |
869 } | |
870 else | |
871 if(action == ACTION_BUTTON_ENTER) | |
872 { | |
873 reset_to_update_using_system_reset(); | |
874 } | |
875 break; | |
876 } | |
877 } | |
878 | |
879 | |
880 void gotoSleep(void) | |
881 { | |
882 ext_flash_erase_firmware_if_not_empty(); | |
883 set_globalState(StStop); | |
884 } | |
885 | |
886 // ----------------------------- | |
887 | |
888 | |
889 void MainBootLoaderInit(void) | |
890 { | |
891 void (*SysMemBootJump)(void); | |
892 SysMemBootJump=(void (*)(void)) (*((uint32_t *) 0x1fff0004)); | |
893 | |
894 // DMA, SPI, UART, TIM, ExtIRQ, graphics DMA, LTDC | |
895 | |
896 HAL_RCC_DeInit(); | |
897 SysTick->CTRL = 0; | |
898 SysTick->LOAD = 0; | |
899 SysTick->VAL = 0; | |
900 | |
901 __set_PRIMASK(1); | |
902 | |
903 __set_MSP(0x20002318); | |
904 SysMemBootJump(); | |
905 } | |
906 | |
907 uint32_t get_globalState(void) | |
908 { | |
909 return globalStateID; | |
910 } | |
911 | |
912 void get_globalStateList(SStateList *output) | |
913 { | |
914 output->base = (uint8_t)((globalStateID >> 28) & 0x0F); | |
915 output->page = (uint8_t)((globalStateID >> 24) & 0x0F); | |
916 output->line = (uint8_t)((globalStateID >> 16) & 0xFF); | |
917 output->field = (uint8_t)((globalStateID >> 8) & 0xFF); | |
918 output->mode = (uint8_t)((globalStateID ) & 0xFF); | |
919 } | |
920 | |
921 void get_idSpecificStateList(uint32_t id, SStateList *output) | |
922 { | |
923 output->base = (uint8_t)((id >> 28) & 0x0F); | |
924 output->page = (uint8_t)((id >> 24) & 0x0F); | |
925 output->line = (uint8_t)((id >> 16) & 0xFF); | |
926 output->field = (uint8_t)((id >> 8) & 0xFF); | |
927 output->mode = (uint8_t)((id ) & 0xFF); | |
928 } | |
929 | |
930 void set_globalState_Base(void) | |
931 { | |
932 set_globalState(StS); | |
933 } | |
934 | |
935 void set_globalState_Menu_Page(uint8_t page) | |
936 { | |
937 globalStateID = ((BaseMenu << 28) + (page << 24)); | |
938 } | |
939 | |
940 void set_globalState_Log_Page(uint8_t pageIsLine) | |
941 { | |
942 globalStateID = StILOGLIST + (pageIsLine << 16); | |
943 } | |
944 | |
945 | |
946 void set_globalState_Menu_Line(uint8_t line) | |
947 { | |
948 globalStateID = ((globalStateID & MaskLineFieldDigit) + (line << 16)); | |
949 } | |
950 | |
951 | |
952 void set_globalState(uint32_t newID) | |
953 { | |
954 globalStateID = newID; | |
955 } | |
956 | |
957 | |
958 | |
959 void delayMicros(uint32_t micros) | |
960 { | |
961 micros = micros * (168/4) - 10; | |
962 while(micros--); | |
963 } | |
964 | |
965 | |
966 void get_RTC_DateTime(RTC_DateTypeDef * sdatestructureget, RTC_TimeTypeDef * stimestructureget) | |
967 { | |
968 /* Get the RTC current Time */ | |
969 if(sdatestructureget) | |
970 HAL_RTC_GetTime(&RtcHandle, stimestructureget, FORMAT_BIN); | |
971 /* Get the RTC current Date */ | |
972 if(stimestructureget) | |
973 HAL_RTC_GetDate(&RtcHandle, sdatestructureget, FORMAT_BIN); | |
974 } | |
975 | |
976 | |
977 void set_RTC_DateTime(RTC_DateTypeDef * sdatestructure, RTC_TimeTypeDef * stimestructure) | |
978 { | |
979 if(sdatestructure) | |
980 if(HAL_RTC_SetDate(&RtcHandle,sdatestructure,FORMAT_BCD) != HAL_OK) | |
981 { | |
982 /* Initialization Error */ | |
983 Error_Handler(); | |
984 } | |
985 | |
986 if(stimestructure) | |
987 if(HAL_RTC_SetTime(&RtcHandle,stimestructure,FORMAT_BCD) != HAL_OK) | |
988 { | |
989 /* Initialization Error */ | |
990 Error_Handler(); | |
991 } | |
992 } | |
993 | |
994 static void TIM_init(void) | |
995 { | |
996 uint16_t uwPrescalerValue = 0; | |
997 | |
998 uwPrescalerValue = (uint32_t) ((SystemCoreClock /2) / 10000) - 1; | |
999 | |
1000 /* Set TIMx instance */ | |
1001 TimHandle.Instance = TIMx; | |
1002 | |
1003 /* Initialize TIM3 peripheral as follows: | |
1004 + Period = 10000 - 1 | |
1005 + Prescaler = ((SystemCoreClock/2)/10000) - 1 | |
1006 + ClockDivision = 0 | |
1007 + Counter direction = Up | |
1008 */ | |
1009 TimHandle.Init.Period = 1000 - 1; | |
1010 TimHandle.Init.Prescaler = uwPrescalerValue; | |
1011 TimHandle.Init.ClockDivision = 0; | |
1012 TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; | |
1013 if(HAL_TIM_Base_Init(&TimHandle) != HAL_OK) | |
1014 { | |
1015 /* Initialization Error */ | |
1016 Error_Handler(); | |
1017 } | |
1018 | |
1019 /*##-2- Start the TIM Base generation in interrupt mode ####################*/ | |
1020 /* Start Channel1 */ | |
1021 if(HAL_TIM_Base_Start_IT(&TimHandle) != HAL_OK) | |
1022 { | |
1023 /* Starting Error */ | |
1024 Error_Handler(); | |
1025 } | |
1026 } | |
1027 | |
1028 #ifndef TIM_BACKLIGHT | |
1029 /* | |
1030 static void TIM_BACKLIGHT_adjust(void) | |
1031 { | |
1032 } | |
1033 */ | |
1034 static void TIM_BACKLIGHT_init(void) | |
1035 { | |
1036 } | |
1037 #else | |
1038 /* | |
1039 static void TIM_BACKLIGHT_adjust(void) | |
1040 { | |
1041 | |
1042 TIM_OC_InitTypeDef sConfig; | |
1043 sConfig.OCMode = TIM_OCMODE_PWM1; | |
1044 sConfig.OCPolarity = TIM_OCPOLARITY_HIGH; | |
1045 sConfig.OCFastMode = TIM_OCFAST_DISABLE; | |
1046 sConfig.Pulse = 600; | |
1047 | |
1048 HAL_TIM_PWM_ConfigChannel(&TimBacklightHandle, &sConfig, TIM_BACKLIGHT_CHANNEL); | |
1049 HAL_TIM_PWM_Start(&TimBacklightHandle, TIM_BACKLIGHT_CHANNEL); | |
1050 } | |
1051 */ | |
1052 static void TIM_BACKLIGHT_init(void) | |
1053 { | |
1054 uint32_t uwPrescalerValue = 0; | |
1055 TIM_OC_InitTypeDef sConfig; | |
1056 | |
1057 uwPrescalerValue = (uint32_t) ((SystemCoreClock /2) / 18000000) - 1; | |
1058 | |
1059 TimBacklightHandle.Instance = TIM_BACKLIGHT; | |
1060 | |
1061 // Initialize TIM3 peripheral as follows: 30 kHz | |
1062 | |
1063 TimBacklightHandle.Init.Period = 600 - 1; | |
1064 TimBacklightHandle.Init.Prescaler = uwPrescalerValue; | |
1065 TimBacklightHandle.Init.ClockDivision = 0; | |
1066 TimBacklightHandle.Init.CounterMode = TIM_COUNTERMODE_UP; | |
1067 HAL_TIM_PWM_Init(&TimBacklightHandle); | |
1068 | |
1069 sConfig.OCMode = TIM_OCMODE_PWM1; | |
1070 sConfig.OCPolarity = TIM_OCPOLARITY_HIGH; | |
1071 sConfig.OCFastMode = TIM_OCFAST_DISABLE; | |
1072 sConfig.Pulse = 50 * 6; | |
1073 | |
1074 HAL_TIM_PWM_ConfigChannel(&TimBacklightHandle, &sConfig, TIM_BACKLIGHT_CHANNEL); | |
1075 HAL_TIM_PWM_Start(&TimBacklightHandle, TIM_BACKLIGHT_CHANNEL); | |
1076 } | |
1077 #endif | |
1078 | |
1079 /* Configure RTC prescaler and RTC data registers */ | |
1080 /* RTC configured as follow: | |
1081 - Hour Format = Format 24 | |
1082 - Asynch Prediv = Value according to source clock | |
1083 - Synch Prediv = Value according to source clock | |
1084 - OutPut = Output Disable | |
1085 - OutPutPolarity = High Polarity | |
1086 - OutPutType = Open Drain */ | |
1087 /*#define RTC_ASYNCH_PREDIV 0x7F LSE as RTC clock */ | |
1088 /*LSE: #define RTC_SYNCH_PREDIV 0x00FF LSE as RTC clock */ | |
1089 /*LSI: #define RTC_SYNCH_PREDIV 0x0130 LSI as RTC clock */ | |
1090 /* | |
1091 static void RTC_init(void) | |
1092 { | |
1093 RtcHandle.Instance = RTC; | |
1094 | |
1095 | |
1096 RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24; | |
1097 RtcHandle.Init.AsynchPrediv = 0x7F; | |
1098 RtcHandle.Init.SynchPrediv = 0x0130; | |
1099 RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE; | |
1100 RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; | |
1101 RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; | |
1102 | |
1103 if(HAL_RTC_Init(&RtcHandle) != HAL_OK) | |
1104 { | |
1105 Error_Handler(); | |
1106 } | |
1107 } | |
1108 */ | |
1109 | |
1110 static void EXTILine_Buttons_Config(void) | |
1111 { | |
1112 GPIO_InitTypeDef GPIO_InitStructure; | |
1113 | |
1114 BUTTON_ENTER_GPIO_ENABLE(); | |
1115 BUTTON_NEXT_GPIO_ENABLE(); | |
1116 BUTTON_BACK_GPIO_ENABLE(); | |
1117 | |
1118 /* Configure pin as weak PULLUP input */ | |
1119 /* buttons */ | |
1120 GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING; | |
1121 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
1122 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
1123 | |
1124 GPIO_InitStructure.Pin = BUTTON_ENTER_PIN; | |
1125 HAL_GPIO_Init(BUTTON_ENTER_GPIO_PORT, &GPIO_InitStructure); | |
1126 | |
1127 GPIO_InitStructure.Pin = BUTTON_NEXT_PIN; | |
1128 HAL_GPIO_Init(BUTTON_NEXT_GPIO_PORT, &GPIO_InitStructure); | |
1129 | |
1130 GPIO_InitStructure.Pin = BUTTON_BACK_PIN; | |
1131 HAL_GPIO_Init(BUTTON_BACK_GPIO_PORT, &GPIO_InitStructure); | |
1132 | |
1133 /* Enable and set EXTI Line0 Interrupt to the lowest priority */ | |
1134 HAL_NVIC_SetPriority(BUTTON_ENTER_EXTI_IRQn, 2, 0); | |
1135 HAL_NVIC_SetPriority(BUTTON_NEXT_EXTI_IRQn, 2, 0); | |
1136 HAL_NVIC_SetPriority(BUTTON_BACK_EXTI_IRQn, 2, 0); | |
1137 HAL_NVIC_EnableIRQ(BUTTON_ENTER_EXTI_IRQn); | |
1138 HAL_NVIC_EnableIRQ(BUTTON_NEXT_EXTI_IRQn); | |
1139 HAL_NVIC_EnableIRQ(BUTTON_BACK_EXTI_IRQn); | |
1140 | |
1141 #ifdef BUTTON_CUSTOM_PIN | |
1142 BUTTON_CUSTOM_GPIO_ENABLE(); | |
1143 GPIO_InitStructure.Pin = BUTTON_CUSTOM_PIN; | |
1144 HAL_GPIO_Init(BUTTON_CUSTOM_GPIO_PORT, &GPIO_InitStructure); | |
1145 HAL_NVIC_SetPriority(BUTTON_CUSTOM_EXTI_IRQn, 2, 0); | |
1146 HAL_NVIC_EnableIRQ(BUTTON_CUSTOM_EXTI_IRQn); | |
1147 #endif | |
1148 } | |
1149 | |
1150 | |
1151 /** | |
1152 * @brief System Clock Configuration | |
1153 * The system Clock is configured as follow : | |
1154 * System Clock source = PLL (HSE) | |
1155 * SYSCLK(Hz) = 180000000 | |
1156 * HCLK(Hz) = 180000000 | |
1157 * AHB Prescaler = 1 | |
1158 * APB1 Prescaler = 4 | |
1159 * APB2 Prescaler = 2 | |
1160 * HSE Frequency(Hz) = 8000000 | |
1161 * PLL_M = 8 | |
1162 * PLL_N = 360 | |
1163 * PLL_P = 2 | |
1164 * PLL_Q = 7 | |
1165 * VDD(V) = 3.3 | |
1166 * Main regulator output voltage = Scale1 mode | |
1167 * Flash Latency(WS) = 5 | |
1168 * The LTDC Clock is configured as follow : | |
1169 * PLLSAIN = 192 | |
1170 * PLLSAIR = 4 | |
1171 * PLLSAIDivR = 8 | |
1172 * @param None | |
1173 * @retval None | |
1174 */ | |
1175 static void SystemClock_Config(void) | |
1176 { | |
869 | 1177 /* Enable Power Control clock */ |
1178 __PWR_CLK_ENABLE(); | |
30 | 1179 |
869 | 1180 /* The voltage scaling allows optimizing the power consumption when the device is |
1181 clocked below the maximum system frequency, to update the voltage scaling value | |
1182 regarding system frequency refer to product datasheet. */ | |
1183 __HAL_PWR_VOLTAGESCALING_CONFIG( PWR_REGULATOR_VOLTAGE_SCALE1 ); | |
30 | 1184 |
869 | 1185 /*##-1- System Clock Configuration #########################################*/ |
1186 /* Enable HighSpeed Oscillator and activate PLL with HSE/HSI as source */ | |
1187 RCC_OscInitTypeDef RCC_OscInitStruct = { 0 }; | |
1188 #ifdef DISC1_BOARD | |
1189 // Use High Speed Internal (HSI) oscillator, running at 16MHz. | |
1190 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; | |
1191 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |
1192 RCC_OscInitStruct.HSICalibrationValue = 0x10; | |
1193 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; | |
1194 RCC_OscInitStruct.PLL.PLLM = 16; // HSI/16 is 1Mhz. | |
1195 #else | |
1196 // Use High Speed External oscillator, running at 8MHz | |
1197 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; | |
1198 RCC_OscInitStruct.HSEState = RCC_HSE_ON; | |
1199 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; | |
1200 RCC_OscInitStruct.PLL.PLLM = 8; // HSE/8 is 1Mhz. | |
1201 #endif | |
1202 // System clock = PLL (1MHz) * N/p = 180 MHz. | |
1203 RCC_OscInitStruct.PLL.PLLN = 360; | |
1204 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; | |
1205 RCC_OscInitStruct.PLL.PLLQ = 7; | |
1206 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
1207 HAL_RCC_OscConfig( &RCC_OscInitStruct ); | |
30 | 1208 |
1209 // HAL_PWREx_ActivateOverDrive(); | |
869 | 1210 HAL_PWREx_DeactivateOverDrive(); |
1211 | |
1212 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ | |
1213 RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 }; | |
1214 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | |
1215 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; | |
1216 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
1217 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
1218 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; | |
1219 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; | |
1220 HAL_RCC_ClockConfig( &RCC_ClkInitStruct, FLASH_LATENCY_8 ); //FLASH_LATENCY_5); | |
30 | 1221 |
869 | 1222 /*##-2- LTDC Clock Configuration ###########################################*/ |
1223 /* LCD clock configuration */ | |
1224 /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */ | |
1225 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */ | |
1226 /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 Mhz */ | |
1227 /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDIVR_8 = 48/8 = 6 Mhz */ | |
30 | 1228 |
869 | 1229 /* neu: 8MHz/8*300/5/8 = 7,5 MHz = 19,5 Hz bei 800 x 480 */ |
1230 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; | |
1231 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC; | |
1232 PeriphClkInitStruct.PLLSAI.PLLSAIN = 300; //192; | |
1233 PeriphClkInitStruct.PLLSAI.PLLSAIR = 5; //4; | |
1234 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;//RCC_PLLSAIDIVR_4;// RCC_PLLSAIDIVR_2; // RCC_PLLSAIDIVR_8 | |
1235 HAL_RCCEx_PeriphCLKConfig( &PeriphClkInitStruct ); | |
30 | 1236 } |
1237 | |
1238 | |
1239 /** | |
1240 * @brief This function is executed in case of error occurrence. | |
1241 * @param None | |
1242 * @retval None | |
1243 */ | |
1244 static void Error_Handler(void) | |
1245 { | |
1246 /* Turn LED3 on */ | |
1247 // BSP_LED_On(LED3); | |
1248 while(1) | |
1249 { | |
1250 } | |
1251 } | |
1252 | |
1253 /** | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
1254 * @brief Perform the SDRAM external memory initialization sequence |
30 | 1255 * @param hsdram: SDRAM handle |
1256 * @param Command: Pointer to SDRAM command structure | |
1257 * @retval None | |
1258 */ | |
1259 static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command) | |
1260 { | |
1261 __IO uint32_t tmpmrd =0; | |
1262 /* Step 3: Configure a clock configuration enable command */ | |
1263 Command->CommandMode = FMC_SDRAM_CMD_CLK_ENABLE; | |
1264 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
1265 Command->AutoRefreshNumber = 1; | |
1266 Command->ModeRegisterDefinition = 0; | |
1267 | |
1268 /* Send the command */ | |
1269 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
1270 | |
1271 /* Step 4: Insert 100 ms delay */ | |
1272 HAL_Delay(100); | |
1273 | |
1274 /* Step 5: Configure a PALL (precharge all) command */ | |
1275 Command->CommandMode = FMC_SDRAM_CMD_PALL; | |
1276 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
1277 Command->AutoRefreshNumber = 1; | |
1278 Command->ModeRegisterDefinition = 0; | |
1279 | |
1280 /* Send the command */ | |
1281 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
1282 | |
1283 /* Step 6 : Configure a Auto-Refresh command */ | |
1284 Command->CommandMode = FMC_SDRAM_CMD_AUTOREFRESH_MODE; | |
1285 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
1286 Command->AutoRefreshNumber = 4; | |
1287 Command->ModeRegisterDefinition = 0; | |
1288 | |
1289 /* Send the command */ | |
1290 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
1291 | |
1292 /* Step 7: Program the external memory mode register */ | |
1293 tmpmrd = (uint32_t)SDRAM_MODEREG_BURST_LENGTH_2 | | |
1294 SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL | | |
1295 SDRAM_MODEREG_CAS_LATENCY_3 | | |
1296 SDRAM_MODEREG_OPERATING_MODE_STANDARD | | |
1297 SDRAM_MODEREG_WRITEBURST_MODE_SINGLE; | |
1298 | |
1299 Command->CommandMode = FMC_SDRAM_CMD_LOAD_MODE; | |
1300 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
1301 Command->AutoRefreshNumber = 1; | |
1302 Command->ModeRegisterDefinition = tmpmrd; | |
1303 | |
1304 /* Send the command */ | |
1305 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
1306 | |
1307 /* Step 8: Set the refresh rate counter */ | |
1308 /* (15.62 us x Freq) - 20 */ | |
1309 /* neu: (8 us x Freq) - 20 */ | |
1310 /* Set the device refresh counter */ | |
1311 HAL_SDRAM_ProgramRefreshRate(hsdram, REFRESH_COUNT); | |
1312 } | |
1313 | |
1314 /* | |
1315 static void DualBoot(void) | |
1316 { | |
1317 // Set BFB2 bit to enable boot from Flash Bank2 | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
1318 // Allow Access to Flash control registers and user Flash |
30 | 1319 HAL_FLASH_Unlock(); |
1320 | |
1321 // Allow Access to option bytes sector | |
1322 HAL_FLASH_OB_Unlock(); | |
1323 | |
1324 // Get the Dual boot configuration status | |
1325 AdvOBInit.OptionType = OBEX_BOOTCONFIG; | |
1326 HAL_FLASHEx_AdvOBGetConfig(&AdvOBInit); | |
1327 | |
1328 // Enable/Disable dual boot feature | |
1329 if (((AdvOBInit.BootConfig) & (FLASH_OPTCR_BFB2)) == FLASH_OPTCR_BFB2) | |
1330 { | |
1331 AdvOBInit.BootConfig = OB_DUAL_BOOT_DISABLE; | |
1332 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
1333 } | |
1334 else | |
1335 { | |
1336 AdvOBInit.BootConfig = OB_DUAL_BOOT_ENABLE; | |
1337 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
1338 } | |
1339 | |
1340 // Start the Option Bytes programming process | |
1341 if (HAL_FLASH_OB_Launch() != HAL_OK) | |
1342 { | |
1343 // User can add here some code to deal with this error | |
1344 while (1) | |
1345 { | |
1346 } | |
1347 } | |
1348 // Prevent Access to option bytes sector | |
1349 HAL_FLASH_OB_Lock(); | |
1350 | |
1351 // Disable the Flash option control register access (recommended to protect | |
1352 // the option Bytes against possible unwanted operations) | |
1353 HAL_FLASH_Lock(); | |
1354 | |
1355 // Initiates a system reset request to reset the MCU | |
1356 reset_to_firmware_using_Watchdog(); | |
1357 } | |
1358 */ | |
1359 /** | |
1360 ****************************************************************************** | |
1361 ****************************************************************************** | |
1362 ****************************************************************************** | |
1363 */ | |
1364 | |
1365 | |
1366 /** | |
1367 * @brief DMA2D configuration. | |
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
1368 * @note This function Configure the DMA2D peripheral : |
30 | 1369 * 1) Configure the transfer mode : memory to memory W/ pixel format conversion |
1370 * 2) Configure the output color mode as ARGB4444 | |
1371 * 3) Configure the output memory address at SRAM memory | |
1372 * 4) Configure the data size : 320x120 (pixels) | |
1373 * 5) Configure the input color mode as ARGB8888 | |
1374 * 6) Configure the input memory address at FLASH memory | |
1375 * @retval | |
1376 * None | |
1377 */ | |
1378 | |
1379 static void SDRAM_Config(void) | |
1380 { | |
1381 /*##-1- Configure the SDRAM device #########################################*/ | |
1382 /* SDRAM device configuration */ | |
1383 hsdram.Instance = FMC_SDRAM_DEVICE; | |
1384 | |
1385 /* Timing configuration for 90 Mhz of SD clock frequency (180Mhz/2) */ | |
1386 /* TMRD: 2 Clock cycles */ | |
1387 SDRAM_Timing.LoadToActiveDelay = 2; | |
1388 /* TXSR: min=70ns (6x11.90ns) */ | |
1389 SDRAM_Timing.ExitSelfRefreshDelay = 7; | |
1390 /* TRAS: min=42ns (4x11.90ns) max=120k (ns) */ | |
1391 SDRAM_Timing.SelfRefreshTime = 4; | |
1392 /* TRC: min=63 (6x11.90ns) */ | |
1393 SDRAM_Timing.RowCycleDelay = 7; | |
1394 /* TWR: 2 Clock cycles */ | |
1395 SDRAM_Timing.WriteRecoveryTime = 2; | |
1396 /* TRP: 15ns => 2x11.90ns */ | |
1397 SDRAM_Timing.RPDelay = 2; | |
1398 /* TRCD: 15ns => 2x11.90ns */ | |
1399 SDRAM_Timing.RCDDelay = 2; | |
1400 | |
1401 hsdram.Init.SDBank = FMC_SDRAM_BANK2; | |
1402 hsdram.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_9; | |
1403 hsdram.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_13; | |
1404 hsdram.Init.MemoryDataWidth = SDRAM_MEMORY_WIDTH; | |
1405 hsdram.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4; | |
1406 hsdram.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3; | |
1407 hsdram.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE; | |
1408 hsdram.Init.SDClockPeriod = SDCLOCK_PERIOD; | |
1409 hsdram.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE; | |
1410 hsdram.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_1; | |
1411 | |
1412 /* Initialize the SDRAM controller */ | |
1413 if(HAL_SDRAM_Init(&hsdram, &SDRAM_Timing) != HAL_OK) | |
1414 { | |
1415 /* Initialization Error */ | |
1416 Error_Handler(); | |
1417 } | |
1418 | |
1419 /* Program the SDRAM external device */ | |
1420 SDRAM_Initialization_Sequence(&hsdram, &command); | |
1421 } | |
1422 | |
1423 | |
1424 uint8_t checkResetForFirmwareUpdate(void) | |
1425 { | |
1426 uint32_t backupRegisterContent; | |
1427 | |
1428 RTC_HandleTypeDef RtcHandle; | |
1429 RtcHandle.Instance = RTC; | |
1430 backupRegisterContent = HAL_RTCEx_BKUPRead(&RtcHandle,RTC_BKP_DR0); | |
1431 | |
1432 if(backupRegisterContent == 0x12345678) | |
1433 return 1; | |
1434 else | |
1435 return 0; | |
1436 } | |
1437 | |
1438 void DeleteResetToFirmwareUpdateRegister(void) | |
1439 { | |
1440 RTC_HandleTypeDef RtcHandle; | |
1441 RtcHandle.Instance = RTC; | |
1442 __HAL_RTC_WRITEPROTECTION_DISABLE(&RtcHandle); | |
1443 HAL_RTCEx_BKUPWrite(&RtcHandle,RTC_BKP_DR0,0x00); | |
1444 __HAL_RTC_WRITEPROTECTION_ENABLE(&RtcHandle); | |
1445 } | |
1446 | |
1447 #ifdef USE_FULL_ASSERT | |
1448 | |
1449 /** | |
1450 * @brief Reports the name of the source file and the source line number | |
1451 * where the assert_param error has occurred. | |
1452 * @param file: pointer to the source file name | |
1453 * @param line: assert_param error line source number | |
1454 * @retval None | |
1455 */ | |
1456 void assert_failed(uint8_t* file, uint32_t line) | |
1457 { | |
1458 /* User can add his own implementation to report the file name and line number, | |
1459 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ | |
1460 | |
1461 /* Infinite loop */ | |
1462 while (1) | |
1463 { | |
1464 } | |
1465 } | |
1466 #endif | |
1467 | |
1468 /* | |
1469 static void DualBootToBootloader(void) | |
1470 { | |
1471 // Set BFB2 bit to enable boot from Flash Bank2 | |
1472 // Allow Access to Flash control registers and user Falsh | |
1473 HAL_FLASH_Unlock(); | |
1474 | |
1475 // Allow Access to option bytes sector | |
1476 HAL_FLASH_OB_Unlock(); | |
1477 | |
1478 // Get the Dual boot configuration status | |
1479 AdvOBInit.OptionType = OPTIONBYTE_BOOTCONFIG; | |
1480 HAL_FLASHEx_AdvOBGetConfig(&AdvOBInit); | |
1481 | |
1482 // Enable/Disable dual boot feature | |
1483 if (((AdvOBInit.BootConfig) & (FLASH_OPTCR_BFB2)) == FLASH_OPTCR_BFB2) | |
1484 { | |
1485 AdvOBInit.BootConfig = OB_DUAL_BOOT_DISABLE; | |
1486 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
1487 if (HAL_FLASH_OB_Launch() != HAL_OK) | |
1488 { | |
1489 while (1) | |
1490 { | |
1491 } | |
1492 } | |
1493 } | |
1494 else | |
1495 { | |
1496 | |
1497 AdvOBInit.BootConfig = OB_DUAL_BOOT_ENABLE; | |
1498 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
1499 if (HAL_FLASH_OB_Launch() != HAL_OK) | |
1500 { | |
1501 while (1) | |
1502 { | |
1503 } | |
1504 } | |
1505 } | |
1506 | |
1507 // Prevent Access to option bytes sector | |
1508 HAL_FLASH_OB_Lock(); | |
1509 | |
1510 / Disable the Flash option control register access (recommended to protect | |
1511 // the option Bytes against possible unwanted operations) | |
1512 HAL_FLASH_Lock(); | |
1513 | |
1514 // Initiates a system reset request to reset the MCU | |
1515 reset_to_firmware_using_Watchdog(); | |
1516 } | |
1517 */ | |
1518 | |
1519 void reset_to_update_using_system_reset(void) | |
1520 { | |
1521 __HAL_RCC_CLEAR_RESET_FLAGS(); | |
1522 HAL_NVIC_SystemReset(); | |
1523 } | |
1524 | |
1525 void reset_to_firmware_using_Watchdog(void) | |
1526 { | |
1527 __HAL_RCC_CLEAR_RESET_FLAGS(); | |
1528 __HAL_RCC_WWDG_CLK_ENABLE(); | |
1529 | |
1530 WWDG_HandleTypeDef WwdgHandle; | |
1531 WwdgHandle.Instance = WWDG; | |
1532 | |
1533 WwdgHandle.Init.Prescaler = WWDG_PRESCALER_8; | |
1534 WwdgHandle.Init.Window = 80; | |
1535 WwdgHandle.Init.Counter = 127; | |
1536 | |
1537 HAL_WWDG_Init(&WwdgHandle); | |
869 | 1538 /* HAL_WWDG_Start(&WwdgHandle); has been removed from HAL library starting_V120 */ |
30 | 1539 while(1); |
1540 } | |
1541 | |
1542 | |
1543 void set_returnFromComm(void) | |
1544 { | |
1545 returnFromCommCleanUpRequest = 1; | |
1546 } | |
1547 | |
1548 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |