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