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