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