Mercurial > public > ostc4
annotate BootLoader/Src/base_bootlader.c @ 1003:f1b78bc8de10 BootloaderOstc5
Bootloader improve init sequence:
Initialization of the BT module failed with the previous version. Root cause could be that the commands were send to fast to the module and the error counter expired before the configuration was stored. To avoid this problem a timer has been added which delays the transmission of commands by 100ms.
| author | Ideenmodellierer |
|---|---|
| date | Thu, 01 May 2025 17:52:17 +0200 |
| parents | 39f28cd9dc46 |
| children | 4ef0511c6665 |
| rev | line source |
|---|---|
| 30 | 1 /////////////////////////////////////////////////////////////////////////////// |
| 2 /// -*- coding: UTF-8 -*- | |
| 3 /// | |
| 4 /// \file BootLoader/Src/base_bootlader.c | |
| 5 /// \brief he beginning of it all. main() is part of this. | |
| 36 | 6 /// \author heinrichs weikamp gmbh |
| 30 | 7 /// \date 26-February-2014 |
| 8 /// | |
| 9 /// $Id$ | |
| 10 /////////////////////////////////////////////////////////////////////////////// | |
| 11 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh | |
| 12 /// | |
| 13 /// This program is free software: you can redistribute it and/or modify | |
| 14 /// it under the terms of the GNU General Public License as published by | |
| 15 /// the Free Software Foundation, either version 3 of the License, or | |
| 16 /// (at your option) any later version. | |
| 17 /// | |
| 18 /// This program is distributed in the hope that it will be useful, | |
| 19 /// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 20 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 21 /// GNU General Public License for more details. | |
| 22 /// | |
| 23 /// You should have received a copy of the GNU General Public License | |
| 24 /// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 25 ////////////////////////////////////////////////////////////////////////////// | |
| 26 /** | |
| 27 * @detail The beginning of it all. main() is part of this. | |
| 28 * + Do the inits for hardware | |
| 29 * + check for button press or update process reset trigger | |
| 30 * + Do the inits for sub-systems like menu, dive screen etc. | |
| 31 * + Start IRQs | |
| 32 * + Start MainTasks not in IRQs | |
| 33 * @bug | |
| 34 * @warning | |
| 35 @verbatim | |
| 36 | |
| 37 ============================================================================== | |
| 38 ##### bootloader specific ##### | |
| 39 ============================================================================== | |
| 40 | |
| 36 | 41 151130 hw sleep on button3 |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
42 (MX_tell_reset_logik_alles_ok() + DataEX_call() in endless loop) |
| 30 | 43 |
| 44 ============================================================================== | |
| 45 ##### bootloader specific ##### | |
| 46 ============================================================================== | |
| 47 | |
| 48 Bootloader info is set right here in this file. | |
| 49 The location is 0x0800A000 instead of 0x08050000 (firmware) | |
| 50 | |
| 51 on system reset (Menu Start Bootloader in firmware) the update process | |
| 52 is started automatically if no button is pressed | |
| 53 | |
| 54 if the right button is pressed the bootloader menu is started | |
| 55 | |
| 56 after update process (with update or empty) cleaning of EEPROM is started | |
| 57 afterwards the watchdog reset starts without activating the update process | |
| 58 | |
| 59 bluetooth chip is started in tComm on start of the mini bootloader firmware | |
| 60 | |
| 61 SMALLCPU_CSB_PIN must be re-set to 0 to communicate with small CPU / CPU2 / RTE | |
| 62 | |
| 63 for RealTerm to send file / firmware, Delays has to be increased to 0 | |
| 64 | |
| 65 RTE update / SPI1 with DMA gave IBUSERR, now it is working fine :-) 150828 | |
| 66 ============================================================================== | |
| 67 from standard firmware, parts might be invalid here: | |
| 68 ============================================================================== | |
| 69 ##### IRQs ##### | |
| 70 ============================================================================== | |
| 71 [..] The IRQs are very important and most functions should only run there. | |
| 72 | |
| 73 PreemptPriority are as follows | |
| 74 (#) 2 (low) sprintf _only_ here. Don't use in maintask or anywhere else. | |
| 75 Called by Buttons und Timer3 | |
| 76 Timer3 is 1/10 second | |
| 77 (#) 1 (mid) anything that should work while in IRQ2 like HalDelay(), VSYNC | |
| 78 and DMA2D Transfer Complete for housekeepingFrame(); | |
| 79 (#) 0 (high) _very very short_ interrupts like The HAL hardware part for | |
| 80 spi, uart, i2c. | |
| 81 | |
| 82 SubPriority within PreemptPriority give the order to execute. | |
| 83 Introduced 30.Oct.14 as it used by several HAL examples. | |
| 84 Three levelAmbients are available (2 low,1 mid,0 high) | |
| 85 | |
| 86 The STM32F4 has 4bits for IRQ levelAmbients, divided 2/2 in this code | |
| 87 with the NVIC_PRIORITYGROUP_2 setting. | |
| 88 | |
| 89 ============================================================================== | |
| 90 ##### MainTask ##### | |
| 91 ============================================================================== | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
92 [..] For everything slow without importance to be 'in time'. |
| 30 | 93 Like VPM and Buehlmann. |
| 94 No sprintf and probably no GFX_SetFramesTopBottom() stuff neither. | |
| 95 If sprintf is called while sprintf is executed it blows up everything. | |
| 96 | |
| 97 ============================================================================== | |
| 98 ##### Frames / the external SDRAM ##### | |
| 99 ============================================================================== | |
| 100 [..] The SDRAM is handled by getFrame() and releaseFrame(). | |
| 101 Each frame with 800*480*2 Bytes. | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
102 Be careful to release every frame |
| 30 | 103 otherwise there will be a memory leakage over time. |
| 104 housekeepingFrame() in the MainTask takes care of cleaning the frames. | |
| 105 All frames are filled with 0x00. This will be transparent with color of | |
| 106 CLUT_Font020 (is CLUT 0) if the alpha is set for a 16bit pair. | |
| 107 housekeepingFrame() delays the cleaning of frames still used as screen | |
| 108 buffer to prevent flickering. | |
| 109 | |
| 110 ============================================================================== | |
| 111 ##### Display ##### | |
| 112 ============================================================================== | |
| 113 [..] There is a Top layer, Bottom layer and background color. | |
| 114 All are perfectly alpha-blended by hardware. | |
| 115 | |
| 116 (#) top layer has 800x480 option function calls only | |
| 117 as it is not used for cursors here | |
| 118 (#) bottom layer has free size and start option to be used | |
| 119 for cursors (or sprites in the future ;-) | |
| 120 (#) background only black in the moment. | |
| 121 ToDo: Could be anything else for warnings etc. | |
| 122 if needed | |
| 123 | |
| 124 [..] Frame updates, switching and cursors is done with | |
| 125 | |
| 126 (#) GFX_SetFramesTopBottom() and the subset | |
| 127 GFX_SetFrameTop() + GFX_SetFrameBottom() | |
| 128 Those do not change anything on the display but give commands to.. | |
| 129 (#) GFX_change_LTDC() The only place that changes the pointer. | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
130 This prevents erratic behavior if several changes |
| 30 | 131 are made within one refresh rate of the screen. |
| 132 Is called in IRQ by PD4 and HAL_GPIO_EXTI_IRQHandler | |
| 133 from VSYNC signal. | |
| 134 | |
| 135 [..] Content | |
| 136 | |
| 137 (#) Colors by LookupTable only. This could be modified by | |
| 138 system settings in the future. (gfx_color.h/.c) | |
| 139 | |
| 140 (#) Text by text_multilinguage.h/.c with one char | |
| 141 necessary only starting from '\x80' | |
| 142 with automatic language switch by | |
| 143 selected_language in SSettings | |
| 144 see openEdit_Language() in tMenuEditSystem.c | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
145 Therefore there are different functions |
| 30 | 146 for example: |
| 147 write_label_fix() for single char multilanguage | |
| 148 write_label_var() for strings that could include | |
| 149 multilanguage as well | |
| 150 see GFX_write_string() to get an overview of the controls | |
| 151 as well as the command list in gfx_engine.h | |
| 152 There is no clear before writing, text overlay is always on. | |
| 153 Many options to have LargeFont.SmallFont for numbers etc. | |
| 154 | |
| 155 ============================================================================== | |
| 156 ##### Update, DualBoot and build-in FLASH memory usage ##### | |
| 157 ============================================================================== | |
| 158 [..] Boot0 pin, Boot1/PB2 pin and BFB2 software bit control the behaviour. | |
| 159 PB2 should be tied to GND. | |
| 160 Boot0 == VDD -> bootloader on start, otherwise boot from Bank1 or Bank2 | |
| 161 depending on BFB2. | |
| 162 Bank2 contains the Fonts and should contain a proper test code in future | |
| 163 Bank1 is the main code (Bank1 is 1 MB too, usage as of Oct. 14 is 200 KB) | |
| 164 [..] Bootloader should be either UART or USB (on FS pins _only_) | |
| 165 USB HS to FS like on the Eval board does not work. | |
| 166 [..] Bootloader for the smaller CPU2 is implemented via the SPI used for DMA copy. | |
| 167 | |
| 168 ============================================================================== | |
| 169 ##### Connection to CPU2 (STM32F411 as of Oct.14 ##### | |
| 170 ============================================================================== | |
| 171 [..] Connected via SPI and DMA for every purpose. | |
| 172 two entire arrays are transfered for data security reasons | |
| 173 with respect to master (STM32F429) might interrupt internal | |
| 174 data copy in CPU2 (like hi byte, low byte, etc.). | |
| 175 [..] The entire life data is calculated in CPU2. Like tissues, CNS,... | |
| 176 Therefore the main unit is _not_ necessarily a Real Time system. | |
| 177 Simulation on the main unit can be executed without disrupting life data. | |
| 178 [..] SPI is triggered and timed by calling DataEX_call() in data_exchange_main.c | |
| 179 DataEX_copy_to_LifeData() does the transfer from buffer to variables used. | |
| 180 | |
| 181 ============================================================================== | |
| 182 ##### Menu, MenuEdit, Info ##### | |
| 183 ============================================================================== | |
| 184 [..] tMenu.c, tMenuEdit.c and tInfo.c is the system used. | |
| 185 logbook is part of Info not Menu. | |
| 186 The Info Menu is accessed by button 'Back' | |
| 187 The regular Menu is accessed by button 'Enter' | |
| 188 [..] Menu content is kept in frame memory for fast access. | |
| 189 There is no need to build pages if the 'Enter' button is pressed. | |
| 190 This is in contrast to MenuEdit pages. | |
| 191 [..] Button control for new pages (and pages in general) have to implemented | |
| 192 in tMenu.c, tMenuEdit.c or tInfo.c | |
| 193 | |
| 194 [..] ToDo (Oct. 14) Timeout for menus via Timer3 / IRQ 2 | |
| 195 | |
| 196 ============================================================================== | |
| 197 ##### specials ##### | |
| 198 ============================================================================== | |
| 199 [..] There was code for vector graphics from great demos | |
| 200 (peridiummmm and jupiter) that can be fitted again | |
| 201 | |
| 202 @endverbatim | |
| 203 ****************************************************************************** | |
| 204 */ | |
| 205 | |
| 206 /* Includes ------------------------------------------------------------------*/ | |
| 207 #include "base_bootloader.h" | |
| 208 | |
| 209 // From Bootloader/Inc: | |
| 210 #include "tInfoBootloader.h" | |
| 211 | |
| 212 // ? | |
| 213 #include "externLogbookFlash.h" | |
| 214 #include "firmwareEraseProgram.h" | |
| 215 #include "firmwareJumpToApplication.h" | |
| 216 | |
| 217 // From Common/Inc: | |
| 218 #include "FirmwareData.h" | |
| 219 | |
| 220 // From Common/Drivers: | |
| 221 #include "stm32f4xx_hal.h" | |
| 222 #include "stm32f4xx_hal_rcc.h" | |
| 223 #include "stm32f4xx_hal_flash_ex.h" | |
| 224 #include "stm32f4xx_hal_wwdg.h" | |
| 225 | |
| 869 | 226 #include "Fonts/Font_T48_plus.h" |
| 1003 | 227 #include "font_T24_min.h" |
| 869 | 228 #include "Fonts/image_battery.h" |
| 229 #include "Fonts/image_heinrichs_weikamp.h" | |
| 230 #include "Fonts/image_ostc.h" | |
| 231 | |
| 30 | 232 // From Discovery/Inc (shall be shared...) |
| 233 #include "data_exchange_main.h" | |
| 234 #include "display.h" | |
| 235 #include "gfx_engine.h" | |
| 236 #include "ostc.h" | |
| 237 #include "tComm.h" | |
| 238 #include "tStructure.h" | |
| 239 | |
| 240 // From AC6 support: | |
| 241 #include <stdio.h> | |
| 242 #include <string.h> // for memcopy | |
| 243 | |
| 244 /* Private define ------------------------------------------------------------*/ | |
| 245 #define BUFFER_SIZE ((uint32_t)0x00177000) | |
| 246 #define WRITE_READ_ADDR ((uint32_t)0x0000) | |
| 247 #define REFRESH_COUNT ((uint32_t)0x0569) /* SDRAM refresh counter (90Mhz SD clock) */ | |
| 248 | |
| 249 /* Private macro -------------------------------------------------------------*/ | |
| 250 /* Private variables ---------------------------------------------------------*/ | |
| 251 uint8_t returnFromCommCleanUpRequest = 0; | |
| 252 | |
| 253 const SFirmwareData bootloader_FirmwareData __attribute__(( section(".bootloader_firmware_data") )) = | |
| 254 { | |
| 255 .versionFirst = 1, | |
| 256 .versionSecond = 0, | |
| 257 .versionThird = 1, | |
| 258 .versionBeta = 1, | |
| 259 | |
| 260 /* 4 bytes with trailing 0 */ | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
261 .signature = "mh", |
| 30 | 262 |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
263 .release_year = 25, |
|
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
264 .release_month = 1, |
|
963
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
265 .release_day = 13, |
| 30 | 266 .release_sub = 0, |
| 267 | |
| 268 /* max 48 with trailing 0 */ | |
| 269 .release_info ="tComm with all", | |
| 270 | |
| 271 /* for safety reasons and coming functions*/ | |
| 272 .magic[0] = FIRMWARE_MAGIC_FIRST, | |
| 273 .magic[1] = FIRMWARE_MAGIC_SECOND, | |
| 274 .magic[2] = FIRMWARE_MAGIC_FIRMWARE, /* the magic byte */ | |
| 275 .magic[3] = FIRMWARE_MAGIC_END | |
| 276 }; | |
| 277 | |
| 965 | 278 const SHardwareData HardwareData __attribute__((section(".bootloader_hardware_data"))) = |
|
963
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
279 { |
| 30 | 280 |
| 281 // first 52 bytes | |
| 282 .primarySerial = 0xFFFF, | |
|
963
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
283 .primaryLicence = 0x00, |
|
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
284 .revision8bit = 0x02, |
|
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
285 .production_year = 0x19, |
|
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
286 .production_month = 0x01, |
|
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
287 .production_day = 0x10, |
| 30 | 288 .production_bluetooth_name_set = 0xFF, |
| 289 | |
| 290 .production_info = { | |
|
963
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
291 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x4F,0x53,0x54,0x43, |
|
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
292 0x20,0x35,0x20,0x65,0x6E,0x64,0x2D,0x32,0x30,0x32,0x34, |
|
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
293 0x20,0x68,0x61,0x72,0x64,0x77,0x61,0x72,0x65,0x20,0x20, |
|
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
294 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20}, |
|
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
295 |
|
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
296 /* 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 30 | 297 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 298 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | |
| 299 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | |
|
963
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
300 */ |
| 30 | 301 // other 12 bytes (64 in total) |
| 302 .secondarySerial = 0xFFFF, | |
| 303 .secondaryLicence = 0xFF, | |
| 304 .secondaryReason8bit = 0xFF, | |
| 305 .secondary_year = 0xFF, | |
| 306 .secondary_month = 0xFF, | |
| 307 .secondary_day = 0xFF, | |
| 308 .secondary_bluetooth_name_set = 0xFF, | |
| 309 .secondary_info = {0xFF,0xFF,0xFF,0xFF} | |
| 310 }; | |
|
963
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
311 |
| 30 | 312 |
| 313 RTC_HandleTypeDef RtcHandle; | |
| 314 TIM_HandleTypeDef TimHandle; /* used in stm32f4xx_it.c too */ | |
| 315 TIM_HandleTypeDef TimBacklightHandle; /* used in stm32f4xx_it.c too */ | |
| 316 | |
| 317 uint32_t time_before; | |
| 318 uint32_t time_between; | |
| 319 uint32_t time_after; | |
| 320 | |
| 321 /* SDRAM handler declaration */ | |
| 322 SDRAM_HandleTypeDef hsdram; | |
| 323 FMC_SDRAM_TimingTypeDef SDRAM_Timing; | |
| 324 FMC_SDRAM_CommandTypeDef command; | |
| 325 | |
| 326 FLASH_OBProgramInitTypeDef OBInit; | |
| 327 FLASH_AdvOBProgramInitTypeDef AdvOBInit; | |
| 328 | |
| 329 | |
| 330 /* Private variables with external access ------------------------------------*/ | |
| 331 | |
| 332 uint32_t globalStateID = 0; | |
| 333 uint8_t globalModeID = SURFMODE; | |
| 334 uint32_t time_without_button_pressed_deciseconds = 0; | |
| 335 uint8_t bootToBootloader = 0; | |
| 336 | |
| 337 /* Private function prototypes -----------------------------------------------*/ | |
| 338 | |
| 339 //static void LCD_ToggleFramebuffer(GFX_DrawCfgTypeDef *hconfig); | |
| 340 //static void LCD_Config(GFX_DrawCfgTypeDef *hconfig); | |
| 341 static void SystemClock_Config(void); | |
| 342 static void Error_Handler(void); | |
| 343 | |
| 344 static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command); | |
| 345 static void SDRAM_Config(void); | |
| 346 //static void DualBoot(void); | |
| 347 static void EXTILine_Buttons_Config(void); | |
| 348 //static void RTC_init(void); | |
| 349 static void TIM_init(void); | |
| 350 static void TIM_BACKLIGHT_init(void); | |
| 351 //static void TIM_BACKLIGHT_adjust(void); | |
| 352 static void gotoSleep(void); | |
| 353 uint8_t checkResetForFirmwareUpdate(void); | |
| 354 void DeleteResetToFirmwareUpdateRegister(void); | |
| 355 void reset_to_firmware_using_Watchdog(void); | |
| 356 void reset_to_update_using_system_reset(void); | |
| 357 | |
| 358 //static void DualBootToBootloader(void); | |
| 359 | |
| 360 /* ITM Trace-------- ---------------------------------------------------------*/ | |
| 361 /* | |
| 362 #define ITM_Port8(n) (*((volatile unsigned char *)(0xE0000000+4*n))) | |
| 363 #define ITM_Port16(n) (*((volatile unsigned short*)(0xE0000000+4*n))) | |
| 364 #define ITM_Port32(n) (*((volatile unsigned long *)(0xE0000000+4*n))) | |
| 365 | |
| 366 #define DEMCR (*((volatile unsigned long *)(0xE000EDFC))) | |
| 367 #define TRCENA 0x01000000 | |
| 368 | |
| 369 struct __FILE { int handle; }; | |
| 370 FILE __stdout; | |
| 371 FILE __stdin; | |
| 372 | |
| 373 int fputc(int ch, FILE *f) { | |
| 374 if (DEMCR & TRCENA) { | |
| 375 while (ITM_Port32(0) == 0); | |
| 376 ITM_Port8(0) = ch; | |
| 377 } | |
| 378 return(ch); | |
| 379 } | |
| 380 */ | |
| 381 | |
| 382 /* Private functions ---------------------------------------------------------*/ | |
| 383 | |
| 384 /** | |
| 385 * @brief Main program | |
| 386 * @param None | |
| 387 * @retval None | |
| 388 */ | |
| 389 | |
| 390 void GPIO_test_I2C_lines(void) | |
| 391 { | |
| 392 GPIO_InitTypeDef GPIO_InitStructure; | |
| 393 __GPIOA_CLK_ENABLE(); | |
| 394 __GPIOG_CLK_ENABLE(); | |
| 395 GPIO_InitStructure.Pin = GPIO_PIN_7; | |
| 396 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
| 397 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
| 398 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
| 399 HAL_GPIO_Init(GPIOG, &GPIO_InitStructure); | |
| 400 GPIO_InitStructure.Pin = GPIO_PIN_3; | |
| 401 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); | |
| 402 | |
| 403 while(1) | |
| 404 { | |
| 405 HAL_GPIO_WritePin(GPIOG,GPIO_PIN_7,GPIO_PIN_SET); | |
| 406 HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3,GPIO_PIN_RESET); | |
| 407 HAL_Delay(10); | |
| 408 HAL_GPIO_WritePin(GPIOG,GPIO_PIN_7,GPIO_PIN_RESET); | |
| 409 HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3,GPIO_PIN_SET); | |
| 410 HAL_Delay(10); | |
| 411 } | |
| 412 } | |
| 413 | |
| 991 | 414 int __attribute__((optimize("O0"))) main(void) |
| 30 | 415 { |
| 416 | |
| 417 /* | |
| 418 HAL_Init(); | |
| 419 SystemClock_Config(); | |
| 420 GPIO_test_I2C_lines(); | |
| 421 */ | |
| 422 uint32_t pLayerInvisible; | |
| 423 uint32_t firmware_load_result; | |
| 424 uint8_t magicbyte = 0; | |
| 425 uint8_t callForUpdate; | |
| 426 uint8_t status = 0; | |
| 427 char textVersion[32]; | |
| 428 uint8_t ptr; | |
| 429 uint32_t pOffset; | |
| 430 | |
| 869 | 431 const SHardwareData* HardwareData = hardwareDataGetPointer(); |
| 432 | |
| 30 | 433 set_globalState(StBoot0); |
| 434 | |
| 435 HAL_Init(); | |
| 436 HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_2); | |
| 869 | 437 SystemClock_Config(); |
| 438 | |
| 439 MX_GPIO_Init(); | |
| 30 | 440 |
| 441 /* button press is only 40 to 50 us low */ | |
| 442 MX_GPIO_One_Button_only_Init(); | |
| 443 | |
| 991 | 444 uint32_t i = 4000000; |
| 30 | 445 |
| 446 callForUpdate = __HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST); | |
| 447 | |
| 448 if(callForUpdate) | |
| 449 { | |
| 450 i = 0; | |
| 451 } | |
| 452 else | |
| 453 if( (firmware_MainCodeIsProgammed() == 0) | |
| 869 | 454 || (HardwareData->primarySerial == 0xFFFF) |
| 455 || (HardwareData->production_bluetooth_name_set == 0xFF)) | |
| 30 | 456 { |
| 457 i = 1; | |
| 458 } | |
| 459 else | |
| 460 { | |
| 461 while(MX_GPIO_Read_The_One_Button() && i) | |
| 462 { | |
| 463 i--; | |
| 464 __NOP(); | |
| 465 } | |
| 466 if(i) | |
| 467 { | |
| 991 | 468 i = 4000000; |
| 30 | 469 while(!MX_GPIO_Read_The_One_Button() && i) |
| 470 { | |
| 471 i--; | |
| 472 __NOP(); | |
| 473 } | |
| 474 if(i) | |
| 475 { | |
| 991 | 476 i = 4000000; |
| 30 | 477 while(MX_GPIO_Read_The_One_Button() && i) |
| 478 { | |
| 479 i--; | |
| 480 __NOP(); | |
| 481 } | |
| 482 } | |
| 483 } | |
| 484 } | |
| 485 | |
| 486 if((i == 0) && (callForUpdate == 0)) | |
| 487 firmware_JumpTo_Application(); | |
| 488 | |
| 489 MX_SPI_Init(); | |
| 490 SDRAM_Config(); | |
| 491 HAL_Delay(100); | |
| 492 | |
| 493 GFX_init1_no_DMA(&pLayerInvisible, 2); | |
| 494 | |
| 495 TIM_BACKLIGHT_init(); | |
| 496 | |
| 497 // ----------------------------- | |
| 498 | |
| 499 display_power_on__1_of_2__pre_RGB(); | |
| 500 GFX_LTDC_Init(); | |
| 501 GFX_LTDC_LayerDefaultInit(TOP_LAYER, pLayerInvisible); | |
| 502 GFX_LTDC_LayerDefaultInit(BACKGRD_LAYER, pLayerInvisible); | |
| 503 GFX_SetFramesTopBottom(pLayerInvisible,pLayerInvisible,480); | |
| 504 HAL_Delay(20); | |
| 505 display_power_on__2_of_2__post_RGB(); | |
| 506 | |
| 507 // ----------------------------- | |
| 508 GFX_change_LTDC(); | |
| 509 GFX_hwBackgroundOn(); | |
| 510 GFX_change_LTDC(); | |
| 511 // ----------------------------- | |
| 512 tInfoBootloader_init(); | |
| 513 // ----------------------------- | |
| 514 if(i == 0) | |
| 515 { | |
| 516 tInfo_newpage("load firmware data"); | |
| 517 uint8_t* pBuffer = (uint8_t*)((uint32_t)0xD0000000); /* blocked via GFX_init1_no_DMA */ | |
| 518 firmware_load_result = ext_flash_read_firmware(pBuffer,768000, &magicbyte); | |
| 519 | |
| 520 if((firmware_load_result > 0) && (firmware_load_result < 768000) && (magicbyte == 0xEE)) | |
| 521 { | |
| 522 ptr = ext_flash_read_firmware_version(textVersion); | |
| 523 textVersion[ptr++] = 'f'; | |
| 524 textVersion[ptr++] = 'o'; | |
| 525 textVersion[ptr++] = 'u'; | |
| 526 textVersion[ptr++] = 'n'; | |
| 527 textVersion[ptr++] = 'd'; | |
| 528 textVersion[ptr] = 0; | |
| 529 | |
| 530 tInfo_newpage(textVersion); | |
| 531 tInfo_write("erase flash"); | |
| 532 status = firmware_eraseFlashMemory(); | |
| 533 if(status != HAL_OK) | |
| 534 { | |
| 535 tInfo_newpage("error. try again."); | |
| 536 status = firmware_eraseFlashMemory(); | |
| 537 if(status != HAL_OK) | |
| 538 { | |
| 539 tInfo_newpage("error. skip update."); | |
| 540 HAL_Delay(1000); | |
| 541 } | |
| 542 } | |
| 543 if(status == HAL_OK) | |
| 544 { | |
| 252 | 545 tInfo_write("program flash"); |
| 30 | 546 status = firmware_programFlashMemory(pBuffer,firmware_load_result); |
| 547 if(status != HAL_OK) | |
| 548 { | |
| 549 tInfo_newpage("error. try again."); | |
| 550 status = firmware_programFlashMemory(pBuffer,firmware_load_result); | |
| 551 if(status != HAL_OK) | |
| 552 { | |
| 553 tInfo_newpage("error. skip update."); | |
| 554 HAL_Delay(1000); | |
| 555 } | |
| 556 } | |
| 557 } | |
| 558 } | |
| 559 } | |
| 560 | |
| 561 /* here comes the variable upper firmware loader */ | |
| 562 if((i == 0) && (status == HAL_OK)) | |
| 563 { | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
564 tInfo_newpage("load fontpack data"); |
| 30 | 565 uint8_t* pBuffer = (uint8_t*)((uint32_t)0xD0000000); /* blocked via GFX_init1_no_DMA */ |
| 566 firmware_load_result = ext_flash_read_firmware2(&pOffset, pBuffer,768000*2,0,0); | |
| 567 | |
| 568 if((firmware_load_result > 0) && (firmware_load_result + pOffset <= 1024000)) | |
| 569 { | |
| 570 ptr = 0; | |
| 571 ptr += gfx_number_to_string(7,0,&textVersion[ptr],firmware_load_result); | |
| 572 textVersion[ptr++] = ' '; | |
| 573 textVersion[ptr++] = 'b'; | |
| 574 textVersion[ptr++] = 'y'; | |
| 575 textVersion[ptr++] = 't'; | |
| 576 textVersion[ptr++] = 'e'; | |
| 577 textVersion[ptr++] = 's'; | |
| 578 textVersion[ptr++] = ' '; | |
| 579 textVersion[ptr++] = 'w'; | |
| 580 textVersion[ptr++] = 'i'; | |
| 581 textVersion[ptr++] = 't'; | |
| 582 textVersion[ptr++] = 'h'; | |
| 583 textVersion[ptr++] = ' '; | |
| 584 ptr += gfx_number_to_string(7,0,&textVersion[ptr],pOffset); | |
| 585 textVersion[ptr++] = ' '; | |
| 586 textVersion[ptr++] = 'o'; | |
| 587 textVersion[ptr++] = 'f'; | |
| 588 textVersion[ptr++] = 'f'; | |
| 589 textVersion[ptr++] = 's'; | |
| 590 textVersion[ptr++] = 'e'; | |
| 591 textVersion[ptr++] = 't'; | |
| 592 textVersion[ptr] = 0; | |
| 593 tInfo_newpage(textVersion); | |
| 594 | |
| 595 ptr = 0; | |
| 596 textVersion[ptr++] = 'f'; | |
| 597 textVersion[ptr++] = 'o'; | |
| 598 textVersion[ptr++] = 'u'; | |
| 599 textVersion[ptr++] = 'n'; | |
| 600 textVersion[ptr++] = 'd'; | |
| 601 textVersion[ptr] = 0; | |
| 602 | |
| 603 tInfo_write(textVersion); | |
| 604 tInfo_write("erase flash"); | |
| 605 status = firmware2_variable_upperpart_eraseFlashMemory(firmware_load_result,pOffset); | |
| 606 if(status != HAL_OK) | |
| 607 { | |
| 608 tInfo_newpage("error. try again."); | |
| 609 status = firmware2_variable_upperpart_eraseFlashMemory(firmware_load_result,pOffset); | |
| 610 if(status != HAL_OK) | |
| 611 { | |
| 612 tInfo_newpage("error. skip update."); | |
| 613 HAL_Delay(1000); | |
| 614 } | |
| 615 } | |
| 616 if(status == HAL_OK) | |
| 617 { | |
| 252 | 618 tInfo_write("program flash"); |
| 30 | 619 status = firmware2_variable_upperpart_programFlashMemory(firmware_load_result,pOffset,pBuffer,firmware_load_result,0); |
| 620 if(status != HAL_OK) | |
| 621 { | |
| 622 tInfo_newpage("error. try again."); | |
| 623 status = firmware2_variable_upperpart_programFlashMemory(firmware_load_result,pOffset,pBuffer,firmware_load_result,0); | |
| 624 if(status != HAL_OK) | |
| 625 { | |
| 626 tInfo_newpage("error. skip update."); | |
| 627 HAL_Delay(1000); | |
| 628 } | |
| 629 } | |
| 630 } | |
| 631 } | |
| 632 } | |
| 633 | |
| 634 if((i == 0) && (status == HAL_OK)) | |
| 635 { | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
636 tInfo_newpage("done."); |
|
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
637 tInfo_write("cleaning."); |
| 30 | 638 ext_flash_erase_firmware_if_not_empty(); |
| 639 ext_flash_erase_firmware2_if_not_empty(); | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
640 tInfo_write("reset device."); |
| 30 | 641 reset_to_firmware_using_Watchdog(); |
| 642 } | |
| 643 | |
| 644 ptr = 0; | |
| 880 | 645 textVersion[ptr++] = '\020'; |
| 30 | 646 textVersion[ptr++] = 's'; |
| 647 textVersion[ptr++] = 'e'; | |
| 648 textVersion[ptr++] = 'r'; | |
| 649 textVersion[ptr++] = 'i'; | |
| 650 textVersion[ptr++] = 'a'; | |
| 651 textVersion[ptr++] = 'l'; | |
| 652 textVersion[ptr++] = ' '; | |
| 869 | 653 if(HardwareData->primarySerial == 0xFFFF) |
| 30 | 654 { |
| 655 textVersion[ptr++] = 'n'; | |
| 656 textVersion[ptr++] = 'o'; | |
| 657 textVersion[ptr++] = 't'; | |
| 658 textVersion[ptr++] = ' '; | |
| 659 textVersion[ptr++] = 's'; | |
| 660 textVersion[ptr++] = 'e'; | |
| 661 textVersion[ptr++] = 't'; | |
| 662 } | |
| 869 | 663 else if(HardwareData->secondarySerial == 0xFFFF) |
| 30 | 664 { |
| 665 textVersion[ptr++] = '#'; | |
| 869 | 666 ptr += gfx_number_to_string(5,1,&textVersion[ptr],HardwareData->primarySerial); |
| 30 | 667 } |
| 668 else | |
| 669 { | |
| 670 textVersion[ptr++] = '#'; | |
| 869 | 671 ptr += gfx_number_to_string(5,1,&textVersion[ptr],HardwareData->secondarySerial); |
| 30 | 672 textVersion[ptr++] = ' '; |
| 673 textVersion[ptr++] = '('; | |
| 869 | 674 ptr += gfx_number_to_string(5,1,&textVersion[ptr],HardwareData->primarySerial); |
| 30 | 675 textVersion[ptr++] = ')'; |
| 676 } | |
| 677 textVersion[ptr++] = '\020'; | |
| 678 textVersion[ptr] = 0; | |
| 679 | |
|
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
680 TIM_init(); |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
681 MX_UART_Init(); |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
682 MX_Bluetooth_PowerOn(); |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
683 tComm_init(); |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
684 |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
685 tInfo_button_text("exit","","sleep"); |
|
963
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
686 tInfo_newpage("bootloader 250113"); |
| 30 | 687 tInfo_write("start bluetooth"); |
| 688 tInfo_write(""); | |
| 689 tInfo_write(textVersion); | |
| 992 | 690 #if 0 |
|
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
691 if(tComm_Set_Bluetooth_Name(0) == 0xFF) |
| 992 | 692 #else |
| 693 if(hardwareDataGetPointer()->production_bluetooth_name_set == 0xFF) | |
| 694 #endif | |
|
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
695 { |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
696 tInfo_write("init bluetooth"); |
| 986 | 697 tComm_StartBlueModBaseInit(); |
|
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
698 } |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
699 else |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
700 { |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
701 tInfo_write("bluetooth set"); |
|
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
702 tComm_StartBlueModConfig(); |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
703 } |
| 30 | 704 |
| 705 set_globalState_Base(); | |
| 706 | |
| 707 GFX_start_VSYNC_IRQ(); | |
| 708 | |
| 709 EXTILine_Buttons_Config(); | |
| 710 /* | |
| 711 uint8_t* pBuffer1 = (uint8_t*)getFrame(20); | |
| 712 firmware_load_result = ext_flash_read_firmware(pBuffer1,768000); | |
| 713 | |
| 714 if((firmware_load_result > 0) && (firmware_load_result < 768000)) | |
| 715 { | |
| 716 firmware_eraseFlashMemory(); | |
| 717 firmware_programFlashMemory(pBuffer1,firmware_load_result); | |
| 718 // not for testing | |
| 719 //ext_flash_erase_firmware_if_not_empty(); | |
| 720 reset_to_firmware_using_Watchdog(); | |
| 721 } | |
| 722 */ | |
| 723 while(1) | |
| 724 { | |
| 725 // if(bootToBootloader) | |
| 726 // DualBootToBootloader(); | |
| 727 | |
| 728 if(bootToBootloader) | |
| 729 reset_to_update_using_system_reset(); | |
| 730 | |
| 731 tComm_control(); // will stop while loop if tComm Mode started until exit from UART | |
| 732 }; | |
| 733 } | |
| 734 | |
| 735 | |
| 736 void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) | |
| 737 { | |
| 738 | |
| 739 SStateList status; | |
| 740 | |
| 741 get_globalStateList(&status); | |
| 742 | |
| 743 switch(status.base) | |
| 744 { | |
| 745 default: | |
| 746 // TIM_BACKLIGHT_adjust(); | |
| 747 break; | |
| 748 } | |
| 749 | |
| 750 if(returnFromCommCleanUpRequest) | |
| 751 { | |
| 752 tComm_exit(); | |
| 753 returnFromCommCleanUpRequest = 0; | |
| 754 GFX_hwBackgroundOn(); | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
755 tInfo_button_text("exit","","sleep"); |
| 30 | 756 tInfo_newpage("bluetooth disonnected"); |
| 757 tInfo_write(""); | |
| 758 tInfo_write(""); | |
| 759 tInfo_write(""); | |
| 760 tInfo_write(""); | |
| 761 } | |
| 762 | |
| 763 get_globalStateList(&status); | |
| 764 | |
| 765 switch(status.base) | |
| 766 { | |
| 767 case BaseComm: | |
| 768 if(get_globalState() == StUART_STANDARD) | |
| 769 tComm_refresh(); | |
| 770 break; | |
| 771 default: | |
| 772 break; | |
| 773 } | |
| 774 } | |
| 775 | |
| 776 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) | |
| 777 { | |
| 778 uint8_t action; | |
| 779 SStateList status; | |
| 780 static uint8_t counterToPreventSleep = 0; | |
| 781 if(GPIO_Pin == VSYNC_IRQ_PIN) // rechts, unten | |
| 782 { | |
| 783 GFX_change_LTDC(); | |
| 784 housekeepingFrame(); | |
| 785 if(counterToPreventSleep < 250) | |
| 786 counterToPreventSleep++; | |
| 787 else | |
| 788 if(counterToPreventSleep != 255) | |
| 789 { | |
| 790 counterToPreventSleep = 255; | |
| 791 } | |
| 792 | |
| 793 return; | |
| 794 } | |
| 795 | |
| 796 time_without_button_pressed_deciseconds = 0; | |
| 797 | |
| 798 if(GFX_logoStatus() != 0) | |
| 799 return; | |
| 800 | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
801 if(GPIO_Pin == BUTTON_BACK_PIN) // left |
| 30 | 802 action = ACTION_BUTTON_BACK; |
| 803 else | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
804 if(GPIO_Pin == BUTTON_ENTER_PIN) // center |
| 30 | 805 action = ACTION_BUTTON_ENTER; |
| 806 else | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
807 if(GPIO_Pin == BUTTON_NEXT_PIN) // right |
| 30 | 808 action = ACTION_BUTTON_NEXT; |
| 809 #ifdef BUTTON_CUSTOM_PIN | |
| 810 else | |
| 811 if(GPIO_Pin == BUTTON_CUSTOM_PIN) // extra | |
| 812 action = ACTION_BUTTON_CUSTOM; | |
| 813 #endif | |
| 814 else | |
| 815 action = 0; | |
| 816 get_globalStateList(&status); | |
| 817 | |
| 971 | 818 if(status.base == BaseComm) |
| 30 | 819 { |
| 820 if(action == ACTION_BUTTON_BACK) | |
| 821 { | |
| 822 reset_to_firmware_using_Watchdog(); | |
| 823 } | |
| 971 | 824 } |
| 825 else | |
| 826 { | |
| 827 switch (action) | |
| 828 { | |
| 829 case ACTION_BUTTON_NEXT: if((counterToPreventSleep == 255) && (get_globalState() == StS)) | |
| 830 { | |
| 831 while(1) | |
| 832 { | |
| 833 MX_tell_reset_logik_alles_ok(); | |
| 834 DataEX_call(); | |
| 835 HAL_Delay(100); | |
| 836 } | |
| 837 } | |
| 838 break; | |
| 839 case ACTION_BUTTON_BACK: reset_to_firmware_using_Watchdog(); | |
| 840 break; | |
| 841 case ACTION_BUTTON_CUSTOM: if(get_globalState() == StS) | |
| 842 { | |
| 843 gotoSleep(); | |
| 844 } | |
| 845 break; | |
| 846 case ACTION_BUTTON_ENTER: /* reset_to_update_using_system_reset(); old function */ | |
| 847 tComm_StartBlueModBaseInit(); /* new: factory reset bluetooth */ | |
| 848 break; | |
| 849 default: | |
| 850 break; | |
| 851 } | |
| 30 | 852 } |
| 853 } | |
| 854 | |
| 855 | |
| 856 void gotoSleep(void) | |
| 857 { | |
| 858 ext_flash_erase_firmware_if_not_empty(); | |
| 859 set_globalState(StStop); | |
| 860 } | |
| 861 | |
| 862 // ----------------------------- | |
| 863 | |
| 864 | |
| 865 void MainBootLoaderInit(void) | |
| 866 { | |
| 867 void (*SysMemBootJump)(void); | |
| 868 SysMemBootJump=(void (*)(void)) (*((uint32_t *) 0x1fff0004)); | |
| 869 | |
| 870 // DMA, SPI, UART, TIM, ExtIRQ, graphics DMA, LTDC | |
| 871 | |
| 872 HAL_RCC_DeInit(); | |
| 873 SysTick->CTRL = 0; | |
| 874 SysTick->LOAD = 0; | |
| 875 SysTick->VAL = 0; | |
| 876 | |
| 877 __set_PRIMASK(1); | |
| 878 | |
| 879 __set_MSP(0x20002318); | |
| 880 SysMemBootJump(); | |
| 881 } | |
| 882 | |
| 883 uint32_t get_globalState(void) | |
| 884 { | |
| 885 return globalStateID; | |
| 886 } | |
| 887 | |
| 888 void get_globalStateList(SStateList *output) | |
| 889 { | |
| 890 output->base = (uint8_t)((globalStateID >> 28) & 0x0F); | |
| 891 output->page = (uint8_t)((globalStateID >> 24) & 0x0F); | |
| 892 output->line = (uint8_t)((globalStateID >> 16) & 0xFF); | |
| 893 output->field = (uint8_t)((globalStateID >> 8) & 0xFF); | |
| 894 output->mode = (uint8_t)((globalStateID ) & 0xFF); | |
| 895 } | |
| 896 | |
| 897 void get_idSpecificStateList(uint32_t id, SStateList *output) | |
| 898 { | |
| 899 output->base = (uint8_t)((id >> 28) & 0x0F); | |
| 900 output->page = (uint8_t)((id >> 24) & 0x0F); | |
| 901 output->line = (uint8_t)((id >> 16) & 0xFF); | |
| 902 output->field = (uint8_t)((id >> 8) & 0xFF); | |
| 903 output->mode = (uint8_t)((id ) & 0xFF); | |
| 904 } | |
| 905 | |
| 906 void set_globalState_Base(void) | |
| 907 { | |
| 908 set_globalState(StS); | |
| 909 } | |
| 910 | |
| 911 void set_globalState_Menu_Page(uint8_t page) | |
| 912 { | |
| 913 globalStateID = ((BaseMenu << 28) + (page << 24)); | |
| 914 } | |
| 915 | |
| 916 void set_globalState_Log_Page(uint8_t pageIsLine) | |
| 917 { | |
| 918 globalStateID = StILOGLIST + (pageIsLine << 16); | |
| 919 } | |
| 920 | |
| 921 | |
| 922 void set_globalState_Menu_Line(uint8_t line) | |
| 923 { | |
| 924 globalStateID = ((globalStateID & MaskLineFieldDigit) + (line << 16)); | |
| 925 } | |
| 926 | |
| 927 | |
| 928 void set_globalState(uint32_t newID) | |
| 929 { | |
| 930 globalStateID = newID; | |
| 931 } | |
| 932 | |
| 933 | |
| 934 | |
| 935 void delayMicros(uint32_t micros) | |
| 936 { | |
| 937 micros = micros * (168/4) - 10; | |
| 938 while(micros--); | |
| 939 } | |
| 940 | |
| 941 | |
| 942 void get_RTC_DateTime(RTC_DateTypeDef * sdatestructureget, RTC_TimeTypeDef * stimestructureget) | |
| 943 { | |
| 944 /* Get the RTC current Time */ | |
| 945 if(sdatestructureget) | |
| 946 HAL_RTC_GetTime(&RtcHandle, stimestructureget, FORMAT_BIN); | |
| 947 /* Get the RTC current Date */ | |
| 948 if(stimestructureget) | |
| 949 HAL_RTC_GetDate(&RtcHandle, sdatestructureget, FORMAT_BIN); | |
| 950 } | |
| 951 | |
| 952 | |
| 953 void set_RTC_DateTime(RTC_DateTypeDef * sdatestructure, RTC_TimeTypeDef * stimestructure) | |
| 954 { | |
| 955 if(sdatestructure) | |
| 956 if(HAL_RTC_SetDate(&RtcHandle,sdatestructure,FORMAT_BCD) != HAL_OK) | |
| 957 { | |
| 958 /* Initialization Error */ | |
| 959 Error_Handler(); | |
| 960 } | |
| 961 | |
| 962 if(stimestructure) | |
| 963 if(HAL_RTC_SetTime(&RtcHandle,stimestructure,FORMAT_BCD) != HAL_OK) | |
| 964 { | |
| 965 /* Initialization Error */ | |
| 966 Error_Handler(); | |
| 967 } | |
| 968 } | |
| 969 | |
| 970 static void TIM_init(void) | |
| 971 { | |
| 972 uint16_t uwPrescalerValue = 0; | |
| 973 | |
| 974 uwPrescalerValue = (uint32_t) ((SystemCoreClock /2) / 10000) - 1; | |
| 975 | |
| 976 /* Set TIMx instance */ | |
| 977 TimHandle.Instance = TIMx; | |
| 978 | |
| 979 /* Initialize TIM3 peripheral as follows: | |
| 980 + Period = 10000 - 1 | |
| 981 + Prescaler = ((SystemCoreClock/2)/10000) - 1 | |
| 982 + ClockDivision = 0 | |
| 983 + Counter direction = Up | |
| 984 */ | |
| 985 TimHandle.Init.Period = 1000 - 1; | |
| 986 TimHandle.Init.Prescaler = uwPrescalerValue; | |
| 987 TimHandle.Init.ClockDivision = 0; | |
| 988 TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; | |
| 989 if(HAL_TIM_Base_Init(&TimHandle) != HAL_OK) | |
| 990 { | |
| 991 /* Initialization Error */ | |
| 992 Error_Handler(); | |
| 993 } | |
| 994 | |
| 995 /*##-2- Start the TIM Base generation in interrupt mode ####################*/ | |
| 996 /* Start Channel1 */ | |
| 997 if(HAL_TIM_Base_Start_IT(&TimHandle) != HAL_OK) | |
| 998 { | |
| 999 /* Starting Error */ | |
| 1000 Error_Handler(); | |
| 1001 } | |
| 1002 } | |
| 1003 | |
| 1004 #ifndef TIM_BACKLIGHT | |
| 1005 /* | |
| 1006 static void TIM_BACKLIGHT_adjust(void) | |
| 1007 { | |
| 1008 } | |
| 1009 */ | |
| 1010 static void TIM_BACKLIGHT_init(void) | |
| 1011 { | |
| 1012 } | |
| 1013 #else | |
| 1014 /* | |
| 1015 static void TIM_BACKLIGHT_adjust(void) | |
| 1016 { | |
| 1017 | |
| 1018 TIM_OC_InitTypeDef sConfig; | |
| 1019 sConfig.OCMode = TIM_OCMODE_PWM1; | |
| 1020 sConfig.OCPolarity = TIM_OCPOLARITY_HIGH; | |
| 1021 sConfig.OCFastMode = TIM_OCFAST_DISABLE; | |
| 1022 sConfig.Pulse = 600; | |
| 1023 | |
| 1024 HAL_TIM_PWM_ConfigChannel(&TimBacklightHandle, &sConfig, TIM_BACKLIGHT_CHANNEL); | |
| 1025 HAL_TIM_PWM_Start(&TimBacklightHandle, TIM_BACKLIGHT_CHANNEL); | |
| 1026 } | |
| 1027 */ | |
| 1028 static void TIM_BACKLIGHT_init(void) | |
| 1029 { | |
| 1030 uint32_t uwPrescalerValue = 0; | |
| 1031 TIM_OC_InitTypeDef sConfig; | |
| 1032 | |
| 1033 uwPrescalerValue = (uint32_t) ((SystemCoreClock /2) / 18000000) - 1; | |
| 1034 | |
| 1035 TimBacklightHandle.Instance = TIM_BACKLIGHT; | |
| 1036 | |
| 1037 // Initialize TIM3 peripheral as follows: 30 kHz | |
| 1038 | |
| 1039 TimBacklightHandle.Init.Period = 600 - 1; | |
| 1040 TimBacklightHandle.Init.Prescaler = uwPrescalerValue; | |
| 1041 TimBacklightHandle.Init.ClockDivision = 0; | |
| 1042 TimBacklightHandle.Init.CounterMode = TIM_COUNTERMODE_UP; | |
| 1043 HAL_TIM_PWM_Init(&TimBacklightHandle); | |
| 1044 | |
| 1045 sConfig.OCMode = TIM_OCMODE_PWM1; | |
| 1046 sConfig.OCPolarity = TIM_OCPOLARITY_HIGH; | |
| 1047 sConfig.OCFastMode = TIM_OCFAST_DISABLE; | |
| 1048 sConfig.Pulse = 50 * 6; | |
| 1049 | |
| 1050 HAL_TIM_PWM_ConfigChannel(&TimBacklightHandle, &sConfig, TIM_BACKLIGHT_CHANNEL); | |
| 1051 HAL_TIM_PWM_Start(&TimBacklightHandle, TIM_BACKLIGHT_CHANNEL); | |
| 1052 } | |
| 1053 #endif | |
| 1054 | |
| 1055 /* Configure RTC prescaler and RTC data registers */ | |
| 1056 /* RTC configured as follow: | |
| 1057 - Hour Format = Format 24 | |
| 1058 - Asynch Prediv = Value according to source clock | |
| 1059 - Synch Prediv = Value according to source clock | |
| 1060 - OutPut = Output Disable | |
| 1061 - OutPutPolarity = High Polarity | |
| 1062 - OutPutType = Open Drain */ | |
| 1063 /*#define RTC_ASYNCH_PREDIV 0x7F LSE as RTC clock */ | |
| 1064 /*LSE: #define RTC_SYNCH_PREDIV 0x00FF LSE as RTC clock */ | |
| 1065 /*LSI: #define RTC_SYNCH_PREDIV 0x0130 LSI as RTC clock */ | |
| 1066 /* | |
| 1067 static void RTC_init(void) | |
| 1068 { | |
| 1069 RtcHandle.Instance = RTC; | |
| 1070 | |
| 1071 | |
| 1072 RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24; | |
| 1073 RtcHandle.Init.AsynchPrediv = 0x7F; | |
| 1074 RtcHandle.Init.SynchPrediv = 0x0130; | |
| 1075 RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE; | |
| 1076 RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; | |
| 1077 RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; | |
| 1078 | |
| 1079 if(HAL_RTC_Init(&RtcHandle) != HAL_OK) | |
| 1080 { | |
| 1081 Error_Handler(); | |
| 1082 } | |
| 1083 } | |
| 1084 */ | |
| 1085 | |
| 1086 static void EXTILine_Buttons_Config(void) | |
| 1087 { | |
| 1088 GPIO_InitTypeDef GPIO_InitStructure; | |
| 1089 | |
| 1090 BUTTON_ENTER_GPIO_ENABLE(); | |
| 1091 BUTTON_NEXT_GPIO_ENABLE(); | |
| 1092 BUTTON_BACK_GPIO_ENABLE(); | |
| 1093 | |
| 1094 /* Configure pin as weak PULLUP input */ | |
| 1095 /* buttons */ | |
| 1096 GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING; | |
| 1097 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
| 1098 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
| 1099 | |
| 1100 GPIO_InitStructure.Pin = BUTTON_ENTER_PIN; | |
| 1101 HAL_GPIO_Init(BUTTON_ENTER_GPIO_PORT, &GPIO_InitStructure); | |
| 1102 | |
| 1103 GPIO_InitStructure.Pin = BUTTON_NEXT_PIN; | |
| 1104 HAL_GPIO_Init(BUTTON_NEXT_GPIO_PORT, &GPIO_InitStructure); | |
| 1105 | |
| 1106 GPIO_InitStructure.Pin = BUTTON_BACK_PIN; | |
| 1107 HAL_GPIO_Init(BUTTON_BACK_GPIO_PORT, &GPIO_InitStructure); | |
| 1108 | |
| 1109 /* Enable and set EXTI Line0 Interrupt to the lowest priority */ | |
| 1110 HAL_NVIC_SetPriority(BUTTON_ENTER_EXTI_IRQn, 2, 0); | |
| 1111 HAL_NVIC_SetPriority(BUTTON_NEXT_EXTI_IRQn, 2, 0); | |
| 1112 HAL_NVIC_SetPriority(BUTTON_BACK_EXTI_IRQn, 2, 0); | |
| 1113 HAL_NVIC_EnableIRQ(BUTTON_ENTER_EXTI_IRQn); | |
| 1114 HAL_NVIC_EnableIRQ(BUTTON_NEXT_EXTI_IRQn); | |
| 1115 HAL_NVIC_EnableIRQ(BUTTON_BACK_EXTI_IRQn); | |
| 1116 | |
| 1117 #ifdef BUTTON_CUSTOM_PIN | |
| 1118 BUTTON_CUSTOM_GPIO_ENABLE(); | |
| 1119 GPIO_InitStructure.Pin = BUTTON_CUSTOM_PIN; | |
| 1120 HAL_GPIO_Init(BUTTON_CUSTOM_GPIO_PORT, &GPIO_InitStructure); | |
| 1121 HAL_NVIC_SetPriority(BUTTON_CUSTOM_EXTI_IRQn, 2, 0); | |
| 1122 HAL_NVIC_EnableIRQ(BUTTON_CUSTOM_EXTI_IRQn); | |
| 1123 #endif | |
| 1124 } | |
| 1125 | |
| 1126 | |
| 1127 /** | |
| 1128 * @brief System Clock Configuration | |
| 1129 * The system Clock is configured as follow : | |
| 1130 * System Clock source = PLL (HSE) | |
| 1131 * SYSCLK(Hz) = 180000000 | |
| 1132 * HCLK(Hz) = 180000000 | |
| 1133 * AHB Prescaler = 1 | |
| 1134 * APB1 Prescaler = 4 | |
| 1135 * APB2 Prescaler = 2 | |
| 1136 * HSE Frequency(Hz) = 8000000 | |
| 1137 * PLL_M = 8 | |
| 1138 * PLL_N = 360 | |
| 1139 * PLL_P = 2 | |
| 1140 * PLL_Q = 7 | |
| 1141 * VDD(V) = 3.3 | |
| 1142 * Main regulator output voltage = Scale1 mode | |
| 1143 * Flash Latency(WS) = 5 | |
| 1144 * The LTDC Clock is configured as follow : | |
| 1145 * PLLSAIN = 192 | |
| 1146 * PLLSAIR = 4 | |
| 1147 * PLLSAIDivR = 8 | |
| 1148 * @param None | |
| 1149 * @retval None | |
| 1150 */ | |
| 1151 static void SystemClock_Config(void) | |
| 1152 { | |
| 869 | 1153 /* Enable Power Control clock */ |
| 1154 __PWR_CLK_ENABLE(); | |
| 30 | 1155 |
| 869 | 1156 /* The voltage scaling allows optimizing the power consumption when the device is |
| 1157 clocked below the maximum system frequency, to update the voltage scaling value | |
| 1158 regarding system frequency refer to product datasheet. */ | |
| 1159 __HAL_PWR_VOLTAGESCALING_CONFIG( PWR_REGULATOR_VOLTAGE_SCALE1 ); | |
| 30 | 1160 |
| 869 | 1161 /*##-1- System Clock Configuration #########################################*/ |
| 1162 /* Enable HighSpeed Oscillator and activate PLL with HSE/HSI as source */ | |
| 1163 RCC_OscInitTypeDef RCC_OscInitStruct = { 0 }; | |
| 1164 #ifdef DISC1_BOARD | |
| 1165 // Use High Speed Internal (HSI) oscillator, running at 16MHz. | |
| 1166 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; | |
| 1167 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |
| 1168 RCC_OscInitStruct.HSICalibrationValue = 0x10; | |
| 1169 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; | |
| 1170 RCC_OscInitStruct.PLL.PLLM = 16; // HSI/16 is 1Mhz. | |
| 1171 #else | |
| 1172 // Use High Speed External oscillator, running at 8MHz | |
| 1173 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; | |
| 1174 RCC_OscInitStruct.HSEState = RCC_HSE_ON; | |
| 1175 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; | |
| 1176 RCC_OscInitStruct.PLL.PLLM = 8; // HSE/8 is 1Mhz. | |
| 1177 #endif | |
| 1178 // System clock = PLL (1MHz) * N/p = 180 MHz. | |
| 1179 RCC_OscInitStruct.PLL.PLLN = 360; | |
| 1180 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; | |
| 1181 RCC_OscInitStruct.PLL.PLLQ = 7; | |
| 1182 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
| 1183 HAL_RCC_OscConfig( &RCC_OscInitStruct ); | |
| 30 | 1184 |
| 1185 // HAL_PWREx_ActivateOverDrive(); | |
| 869 | 1186 HAL_PWREx_DeactivateOverDrive(); |
| 1187 | |
| 1188 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ | |
| 1189 RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 }; | |
| 1190 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | |
| 1191 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; | |
| 1192 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
| 1193 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
| 1194 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; | |
| 1195 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; | |
| 1196 HAL_RCC_ClockConfig( &RCC_ClkInitStruct, FLASH_LATENCY_8 ); //FLASH_LATENCY_5); | |
| 30 | 1197 |
| 869 | 1198 /*##-2- LTDC Clock Configuration ###########################################*/ |
| 1199 /* LCD clock configuration */ | |
| 1200 /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */ | |
| 1201 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */ | |
| 1202 /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 Mhz */ | |
| 1203 /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDIVR_8 = 48/8 = 6 Mhz */ | |
| 30 | 1204 |
| 869 | 1205 /* neu: 8MHz/8*300/5/8 = 7,5 MHz = 19,5 Hz bei 800 x 480 */ |
| 1206 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; | |
| 1207 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC; | |
| 1208 PeriphClkInitStruct.PLLSAI.PLLSAIN = 300; //192; | |
| 1209 PeriphClkInitStruct.PLLSAI.PLLSAIR = 5; //4; | |
| 1210 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;//RCC_PLLSAIDIVR_4;// RCC_PLLSAIDIVR_2; // RCC_PLLSAIDIVR_8 | |
| 1211 HAL_RCCEx_PeriphCLKConfig( &PeriphClkInitStruct ); | |
| 30 | 1212 } |
| 1213 | |
| 1214 | |
| 1215 /** | |
| 1216 * @brief This function is executed in case of error occurrence. | |
| 1217 * @param None | |
| 1218 * @retval None | |
| 1219 */ | |
| 1220 static void Error_Handler(void) | |
| 1221 { | |
| 1222 /* Turn LED3 on */ | |
| 1223 // BSP_LED_On(LED3); | |
| 1224 while(1) | |
| 1225 { | |
| 1226 } | |
| 1227 } | |
| 1228 | |
| 1229 /** | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
1230 * @brief Perform the SDRAM external memory initialization sequence |
| 30 | 1231 * @param hsdram: SDRAM handle |
| 1232 * @param Command: Pointer to SDRAM command structure | |
| 1233 * @retval None | |
| 1234 */ | |
| 1235 static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command) | |
| 1236 { | |
| 1237 __IO uint32_t tmpmrd =0; | |
| 1238 /* Step 3: Configure a clock configuration enable command */ | |
| 1239 Command->CommandMode = FMC_SDRAM_CMD_CLK_ENABLE; | |
| 1240 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
| 1241 Command->AutoRefreshNumber = 1; | |
| 1242 Command->ModeRegisterDefinition = 0; | |
| 1243 | |
| 1244 /* Send the command */ | |
| 1245 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
| 1246 | |
| 1247 /* Step 4: Insert 100 ms delay */ | |
| 1248 HAL_Delay(100); | |
| 1249 | |
| 1250 /* Step 5: Configure a PALL (precharge all) command */ | |
| 1251 Command->CommandMode = FMC_SDRAM_CMD_PALL; | |
| 1252 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
| 1253 Command->AutoRefreshNumber = 1; | |
| 1254 Command->ModeRegisterDefinition = 0; | |
| 1255 | |
| 1256 /* Send the command */ | |
| 1257 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
| 1258 | |
| 1259 /* Step 6 : Configure a Auto-Refresh command */ | |
| 1260 Command->CommandMode = FMC_SDRAM_CMD_AUTOREFRESH_MODE; | |
| 1261 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
| 1262 Command->AutoRefreshNumber = 4; | |
| 1263 Command->ModeRegisterDefinition = 0; | |
| 1264 | |
| 1265 /* Send the command */ | |
| 1266 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
| 1267 | |
| 1268 /* Step 7: Program the external memory mode register */ | |
| 1269 tmpmrd = (uint32_t)SDRAM_MODEREG_BURST_LENGTH_2 | | |
| 1270 SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL | | |
| 1271 SDRAM_MODEREG_CAS_LATENCY_3 | | |
| 1272 SDRAM_MODEREG_OPERATING_MODE_STANDARD | | |
| 1273 SDRAM_MODEREG_WRITEBURST_MODE_SINGLE; | |
| 1274 | |
| 1275 Command->CommandMode = FMC_SDRAM_CMD_LOAD_MODE; | |
| 1276 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
| 1277 Command->AutoRefreshNumber = 1; | |
| 1278 Command->ModeRegisterDefinition = tmpmrd; | |
| 1279 | |
| 1280 /* Send the command */ | |
| 1281 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
| 1282 | |
| 1283 /* Step 8: Set the refresh rate counter */ | |
| 1284 /* (15.62 us x Freq) - 20 */ | |
| 1285 /* neu: (8 us x Freq) - 20 */ | |
| 1286 /* Set the device refresh counter */ | |
| 1287 HAL_SDRAM_ProgramRefreshRate(hsdram, REFRESH_COUNT); | |
| 1288 } | |
| 1289 | |
| 1290 /* | |
| 1291 static void DualBoot(void) | |
| 1292 { | |
| 1293 // Set BFB2 bit to enable boot from Flash Bank2 | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
1294 // Allow Access to Flash control registers and user Flash |
| 30 | 1295 HAL_FLASH_Unlock(); |
| 1296 | |
| 1297 // Allow Access to option bytes sector | |
| 1298 HAL_FLASH_OB_Unlock(); | |
| 1299 | |
| 1300 // Get the Dual boot configuration status | |
| 1301 AdvOBInit.OptionType = OBEX_BOOTCONFIG; | |
| 1302 HAL_FLASHEx_AdvOBGetConfig(&AdvOBInit); | |
| 1303 | |
| 1304 // Enable/Disable dual boot feature | |
| 1305 if (((AdvOBInit.BootConfig) & (FLASH_OPTCR_BFB2)) == FLASH_OPTCR_BFB2) | |
| 1306 { | |
| 1307 AdvOBInit.BootConfig = OB_DUAL_BOOT_DISABLE; | |
| 1308 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
| 1309 } | |
| 1310 else | |
| 1311 { | |
| 1312 AdvOBInit.BootConfig = OB_DUAL_BOOT_ENABLE; | |
| 1313 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
| 1314 } | |
| 1315 | |
| 1316 // Start the Option Bytes programming process | |
| 1317 if (HAL_FLASH_OB_Launch() != HAL_OK) | |
| 1318 { | |
| 1319 // User can add here some code to deal with this error | |
| 1320 while (1) | |
| 1321 { | |
| 1322 } | |
| 1323 } | |
| 1324 // Prevent Access to option bytes sector | |
| 1325 HAL_FLASH_OB_Lock(); | |
| 1326 | |
| 1327 // Disable the Flash option control register access (recommended to protect | |
| 1328 // the option Bytes against possible unwanted operations) | |
| 1329 HAL_FLASH_Lock(); | |
| 1330 | |
| 1331 // Initiates a system reset request to reset the MCU | |
| 1332 reset_to_firmware_using_Watchdog(); | |
| 1333 } | |
| 1334 */ | |
| 1335 /** | |
| 1336 ****************************************************************************** | |
| 1337 ****************************************************************************** | |
| 1338 ****************************************************************************** | |
| 1339 */ | |
| 1340 | |
| 1341 | |
| 1342 /** | |
| 1343 * @brief DMA2D configuration. | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
1344 * @note This function Configure the DMA2D peripheral : |
| 30 | 1345 * 1) Configure the transfer mode : memory to memory W/ pixel format conversion |
| 1346 * 2) Configure the output color mode as ARGB4444 | |
| 1347 * 3) Configure the output memory address at SRAM memory | |
| 1348 * 4) Configure the data size : 320x120 (pixels) | |
| 1349 * 5) Configure the input color mode as ARGB8888 | |
| 1350 * 6) Configure the input memory address at FLASH memory | |
| 1351 * @retval | |
| 1352 * None | |
| 1353 */ | |
| 1354 | |
| 1355 static void SDRAM_Config(void) | |
| 1356 { | |
| 1357 /*##-1- Configure the SDRAM device #########################################*/ | |
| 1358 /* SDRAM device configuration */ | |
| 1359 hsdram.Instance = FMC_SDRAM_DEVICE; | |
| 1360 | |
| 1361 /* Timing configuration for 90 Mhz of SD clock frequency (180Mhz/2) */ | |
| 1362 /* TMRD: 2 Clock cycles */ | |
| 1363 SDRAM_Timing.LoadToActiveDelay = 2; | |
| 1364 /* TXSR: min=70ns (6x11.90ns) */ | |
| 1365 SDRAM_Timing.ExitSelfRefreshDelay = 7; | |
| 1366 /* TRAS: min=42ns (4x11.90ns) max=120k (ns) */ | |
| 1367 SDRAM_Timing.SelfRefreshTime = 4; | |
| 1368 /* TRC: min=63 (6x11.90ns) */ | |
| 1369 SDRAM_Timing.RowCycleDelay = 7; | |
| 1370 /* TWR: 2 Clock cycles */ | |
| 1371 SDRAM_Timing.WriteRecoveryTime = 2; | |
| 1372 /* TRP: 15ns => 2x11.90ns */ | |
| 1373 SDRAM_Timing.RPDelay = 2; | |
| 1374 /* TRCD: 15ns => 2x11.90ns */ | |
| 1375 SDRAM_Timing.RCDDelay = 2; | |
| 1376 | |
| 1377 hsdram.Init.SDBank = FMC_SDRAM_BANK2; | |
| 1378 hsdram.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_9; | |
| 1379 hsdram.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_13; | |
| 1380 hsdram.Init.MemoryDataWidth = SDRAM_MEMORY_WIDTH; | |
| 1381 hsdram.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4; | |
| 1382 hsdram.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3; | |
| 1383 hsdram.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE; | |
| 1384 hsdram.Init.SDClockPeriod = SDCLOCK_PERIOD; | |
| 1385 hsdram.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE; | |
| 1386 hsdram.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_1; | |
| 1387 | |
| 1388 /* Initialize the SDRAM controller */ | |
| 1389 if(HAL_SDRAM_Init(&hsdram, &SDRAM_Timing) != HAL_OK) | |
| 1390 { | |
| 1391 /* Initialization Error */ | |
| 1392 Error_Handler(); | |
| 1393 } | |
| 1394 | |
| 1395 /* Program the SDRAM external device */ | |
| 1396 SDRAM_Initialization_Sequence(&hsdram, &command); | |
| 1397 } | |
| 1398 | |
| 1399 | |
| 1400 uint8_t checkResetForFirmwareUpdate(void) | |
| 1401 { | |
| 1402 uint32_t backupRegisterContent; | |
| 1403 | |
| 1404 RTC_HandleTypeDef RtcHandle; | |
| 1405 RtcHandle.Instance = RTC; | |
| 1406 backupRegisterContent = HAL_RTCEx_BKUPRead(&RtcHandle,RTC_BKP_DR0); | |
| 1407 | |
| 1408 if(backupRegisterContent == 0x12345678) | |
| 1409 return 1; | |
| 1410 else | |
| 1411 return 0; | |
| 1412 } | |
| 1413 | |
| 1414 void DeleteResetToFirmwareUpdateRegister(void) | |
| 1415 { | |
| 1416 RTC_HandleTypeDef RtcHandle; | |
| 1417 RtcHandle.Instance = RTC; | |
| 1418 __HAL_RTC_WRITEPROTECTION_DISABLE(&RtcHandle); | |
| 1419 HAL_RTCEx_BKUPWrite(&RtcHandle,RTC_BKP_DR0,0x00); | |
| 1420 __HAL_RTC_WRITEPROTECTION_ENABLE(&RtcHandle); | |
| 1421 } | |
| 1422 | |
| 1423 #ifdef USE_FULL_ASSERT | |
| 1424 | |
| 1425 /** | |
| 1426 * @brief Reports the name of the source file and the source line number | |
| 1427 * where the assert_param error has occurred. | |
| 1428 * @param file: pointer to the source file name | |
| 1429 * @param line: assert_param error line source number | |
| 1430 * @retval None | |
| 1431 */ | |
| 1432 void assert_failed(uint8_t* file, uint32_t line) | |
| 1433 { | |
| 1434 /* User can add his own implementation to report the file name and line number, | |
| 1435 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ | |
| 1436 | |
| 1437 /* Infinite loop */ | |
| 1438 while (1) | |
| 1439 { | |
| 1440 } | |
| 1441 } | |
| 1442 #endif | |
| 1443 | |
| 1444 /* | |
| 1445 static void DualBootToBootloader(void) | |
| 1446 { | |
| 1447 // Set BFB2 bit to enable boot from Flash Bank2 | |
| 1448 // Allow Access to Flash control registers and user Falsh | |
| 1449 HAL_FLASH_Unlock(); | |
| 1450 | |
| 1451 // Allow Access to option bytes sector | |
| 1452 HAL_FLASH_OB_Unlock(); | |
| 1453 | |
| 1454 // Get the Dual boot configuration status | |
| 1455 AdvOBInit.OptionType = OPTIONBYTE_BOOTCONFIG; | |
| 1456 HAL_FLASHEx_AdvOBGetConfig(&AdvOBInit); | |
| 1457 | |
| 1458 // Enable/Disable dual boot feature | |
| 1459 if (((AdvOBInit.BootConfig) & (FLASH_OPTCR_BFB2)) == FLASH_OPTCR_BFB2) | |
| 1460 { | |
| 1461 AdvOBInit.BootConfig = OB_DUAL_BOOT_DISABLE; | |
| 1462 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
| 1463 if (HAL_FLASH_OB_Launch() != HAL_OK) | |
| 1464 { | |
| 1465 while (1) | |
| 1466 { | |
| 1467 } | |
| 1468 } | |
| 1469 } | |
| 1470 else | |
| 1471 { | |
| 1472 | |
| 1473 AdvOBInit.BootConfig = OB_DUAL_BOOT_ENABLE; | |
| 1474 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
| 1475 if (HAL_FLASH_OB_Launch() != HAL_OK) | |
| 1476 { | |
| 1477 while (1) | |
| 1478 { | |
| 1479 } | |
| 1480 } | |
| 1481 } | |
| 1482 | |
| 1483 // Prevent Access to option bytes sector | |
| 1484 HAL_FLASH_OB_Lock(); | |
| 1485 | |
| 1486 / Disable the Flash option control register access (recommended to protect | |
| 1487 // the option Bytes against possible unwanted operations) | |
| 1488 HAL_FLASH_Lock(); | |
| 1489 | |
| 1490 // Initiates a system reset request to reset the MCU | |
| 1491 reset_to_firmware_using_Watchdog(); | |
| 1492 } | |
| 1493 */ | |
| 1494 | |
| 1495 void reset_to_update_using_system_reset(void) | |
| 1496 { | |
| 1497 __HAL_RCC_CLEAR_RESET_FLAGS(); | |
| 1498 HAL_NVIC_SystemReset(); | |
| 1499 } | |
| 1500 | |
| 1501 void reset_to_firmware_using_Watchdog(void) | |
| 1502 { | |
| 1503 __HAL_RCC_CLEAR_RESET_FLAGS(); | |
| 1504 __HAL_RCC_WWDG_CLK_ENABLE(); | |
| 1505 | |
| 1506 WWDG_HandleTypeDef WwdgHandle; | |
| 1507 WwdgHandle.Instance = WWDG; | |
| 1508 | |
| 1509 WwdgHandle.Init.Prescaler = WWDG_PRESCALER_8; | |
| 1510 WwdgHandle.Init.Window = 80; | |
| 1511 WwdgHandle.Init.Counter = 127; | |
| 1512 | |
| 1513 HAL_WWDG_Init(&WwdgHandle); | |
| 869 | 1514 /* HAL_WWDG_Start(&WwdgHandle); has been removed from HAL library starting_V120 */ |
| 30 | 1515 while(1); |
| 1516 } | |
| 1517 | |
| 1518 | |
| 1519 void set_returnFromComm(void) | |
| 1520 { | |
| 1521 returnFromCommCleanUpRequest = 1; | |
| 1522 } | |
| 1523 | |
| 1524 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |
