Mercurial > public > ostc4
comparison BootLoader/Src/base_bootlader.c @ 869:4e10a3e087a1 Evo_2_23
Reactivate Bootloader:
The bootloader has not been compiled for a long time. Changes were necessary to catch up with the actual code
author | Ideenmodellierer |
---|---|
date | Mon, 12 Aug 2024 22:23:03 +0200 |
parents | 1b9be6040d82 |
children | 5e027b0f7475 |
comparison
equal
deleted
inserted
replaced
868:db92692c014f | 869:4e10a3e087a1 |
---|---|
221 #include "stm32f4xx_hal.h" | 221 #include "stm32f4xx_hal.h" |
222 #include "stm32f4xx_hal_rcc.h" | 222 #include "stm32f4xx_hal_rcc.h" |
223 #include "stm32f4xx_hal_flash_ex.h" | 223 #include "stm32f4xx_hal_flash_ex.h" |
224 #include "stm32f4xx_hal_wwdg.h" | 224 #include "stm32f4xx_hal_wwdg.h" |
225 | 225 |
226 #ifdef BOOTLOADER_STANDALONE | |
227 #include "Fonts/Font_T144_plus.h" | |
228 #include "Fonts/Font_T84.h" | |
229 #include "Fonts/Font_T105.h" | |
230 #include "Fonts/Font_T54.h" | |
231 #include "Fonts/Font_T48_plus.h" | |
232 #include "Fonts/Font_T24.h" | |
233 #include "Fonts/Font_T42.h" | |
234 #include "Fonts/image_battery.h" | |
235 #include "Fonts/image_heinrichs_weikamp.h" | |
236 #include "Fonts/image_ostc.h" | |
237 #endif | |
238 | |
226 // From Discovery/Inc (shall be shared...) | 239 // From Discovery/Inc (shall be shared...) |
227 #include "data_exchange_main.h" | 240 #include "data_exchange_main.h" |
228 #include "display.h" | 241 #include "display.h" |
229 #include "gfx_engine.h" | 242 #include "gfx_engine.h" |
230 #include "ostc.h" | 243 #include "ostc.h" |
267 .magic[1] = FIRMWARE_MAGIC_SECOND, | 280 .magic[1] = FIRMWARE_MAGIC_SECOND, |
268 .magic[2] = FIRMWARE_MAGIC_FIRMWARE, /* the magic byte */ | 281 .magic[2] = FIRMWARE_MAGIC_FIRMWARE, /* the magic byte */ |
269 .magic[3] = FIRMWARE_MAGIC_END | 282 .magic[3] = FIRMWARE_MAGIC_END |
270 }; | 283 }; |
271 | 284 |
272 | 285 #if 0 |
273 const SHardwareData HardwareData __attribute__((at(HARDWAREDATA_ADDRESS))) = { | 286 const SHardwareData HardwareData __attribute__((at(HARDWAREDATA_ADDRESS))) = { |
274 | 287 |
275 // first 52 bytes | 288 // first 52 bytes |
276 .primarySerial = 0xFFFF, | 289 .primarySerial = 0xFFFF, |
277 .primaryLicence = 0xFF, | 290 .primaryLicence = 0xFF, |
295 .secondary_month = 0xFF, | 308 .secondary_month = 0xFF, |
296 .secondary_day = 0xFF, | 309 .secondary_day = 0xFF, |
297 .secondary_bluetooth_name_set = 0xFF, | 310 .secondary_bluetooth_name_set = 0xFF, |
298 .secondary_info = {0xFF,0xFF,0xFF,0xFF} | 311 .secondary_info = {0xFF,0xFF,0xFF,0xFF} |
299 }; | 312 }; |
300 | 313 #endif |
301 | 314 |
302 RTC_HandleTypeDef RtcHandle; | 315 RTC_HandleTypeDef RtcHandle; |
303 TIM_HandleTypeDef TimHandle; /* used in stm32f4xx_it.c too */ | 316 TIM_HandleTypeDef TimHandle; /* used in stm32f4xx_it.c too */ |
304 TIM_HandleTypeDef TimBacklightHandle; /* used in stm32f4xx_it.c too */ | 317 TIM_HandleTypeDef TimBacklightHandle; /* used in stm32f4xx_it.c too */ |
305 | 318 |
416 uint8_t status = 0; | 429 uint8_t status = 0; |
417 char textVersion[32]; | 430 char textVersion[32]; |
418 uint8_t ptr; | 431 uint8_t ptr; |
419 uint32_t pOffset; | 432 uint32_t pOffset; |
420 | 433 |
434 const SHardwareData* HardwareData = hardwareDataGetPointer(); | |
435 | |
421 set_globalState(StBoot0); | 436 set_globalState(StBoot0); |
422 | 437 |
423 HAL_Init(); | 438 HAL_Init(); |
424 HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_2); | 439 HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_2); |
440 SystemClock_Config(); | |
441 | |
442 MX_GPIO_Init(); | |
425 | 443 |
426 /* feedback for the user | 444 /* feedback for the user |
427 * aber sehr unsch�n beim Warmstart | 445 * aber sehr unsch�n beim Warmstart |
428 * da das letzte Bild noch lange nachleuchtet */ | 446 * da das letzte Bild noch lange nachleuchtet */ |
429 // MX_GPIO_Backlight_max_static_only_Init(); | 447 // MX_GPIO_Backlight_max_static_only_Init(); |
440 { | 458 { |
441 i = 0; | 459 i = 0; |
442 } | 460 } |
443 else | 461 else |
444 if( (firmware_MainCodeIsProgammed() == 0) | 462 if( (firmware_MainCodeIsProgammed() == 0) |
445 || (hardwareDataGetPointer()->primarySerial == 0xFFFF) | 463 || (HardwareData->primarySerial == 0xFFFF) |
446 || (hardwareDataGetPointer()->production_bluetooth_name_set == 0xFF)) | 464 || (HardwareData->production_bluetooth_name_set == 0xFF)) |
447 { | 465 { |
448 i = 1; | 466 i = 1; |
449 } | 467 } |
450 else | 468 else |
451 { | 469 { |
493 } | 511 } |
494 | 512 |
495 if((i == 0) && (callForUpdate == 0)) | 513 if((i == 0) && (callForUpdate == 0)) |
496 firmware_JumpTo_Application(); | 514 firmware_JumpTo_Application(); |
497 | 515 |
498 SystemClock_Config(); | 516 |
499 | 517 |
500 MX_GPIO_Init(); | |
501 MX_Bluetooth_PowerOn(); | 518 MX_Bluetooth_PowerOn(); |
502 MX_SPI_Init(); | 519 MX_SPI_Init(); |
503 SDRAM_Config(); | 520 SDRAM_Config(); |
504 HAL_Delay(100); | 521 HAL_Delay(100); |
505 | 522 |
661 textVersion[ptr++] = 'r'; | 678 textVersion[ptr++] = 'r'; |
662 textVersion[ptr++] = 'i'; | 679 textVersion[ptr++] = 'i'; |
663 textVersion[ptr++] = 'a'; | 680 textVersion[ptr++] = 'a'; |
664 textVersion[ptr++] = 'l'; | 681 textVersion[ptr++] = 'l'; |
665 textVersion[ptr++] = ' '; | 682 textVersion[ptr++] = ' '; |
666 if(HardwareData.primarySerial == 0xFFFF) | 683 if(HardwareData->primarySerial == 0xFFFF) |
667 { | 684 { |
668 textVersion[ptr++] = 'n'; | 685 textVersion[ptr++] = 'n'; |
669 textVersion[ptr++] = 'o'; | 686 textVersion[ptr++] = 'o'; |
670 textVersion[ptr++] = 't'; | 687 textVersion[ptr++] = 't'; |
671 textVersion[ptr++] = ' '; | 688 textVersion[ptr++] = ' '; |
672 textVersion[ptr++] = 's'; | 689 textVersion[ptr++] = 's'; |
673 textVersion[ptr++] = 'e'; | 690 textVersion[ptr++] = 'e'; |
674 textVersion[ptr++] = 't'; | 691 textVersion[ptr++] = 't'; |
675 } | 692 } |
676 else if(HardwareData.secondarySerial == 0xFFFF) | 693 else if(HardwareData->secondarySerial == 0xFFFF) |
677 { | 694 { |
678 textVersion[ptr++] = '#'; | 695 textVersion[ptr++] = '#'; |
679 ptr += gfx_number_to_string(5,1,&textVersion[ptr],HardwareData.primarySerial); | 696 ptr += gfx_number_to_string(5,1,&textVersion[ptr],HardwareData->primarySerial); |
680 } | 697 } |
681 else | 698 else |
682 { | 699 { |
683 textVersion[ptr++] = '#'; | 700 textVersion[ptr++] = '#'; |
684 ptr += gfx_number_to_string(5,1,&textVersion[ptr],HardwareData.secondarySerial); | 701 ptr += gfx_number_to_string(5,1,&textVersion[ptr],HardwareData->secondarySerial); |
685 textVersion[ptr++] = ' '; | 702 textVersion[ptr++] = ' '; |
686 textVersion[ptr++] = '('; | 703 textVersion[ptr++] = '('; |
687 ptr += gfx_number_to_string(5,1,&textVersion[ptr],HardwareData.primarySerial); | 704 ptr += gfx_number_to_string(5,1,&textVersion[ptr],HardwareData->primarySerial); |
688 textVersion[ptr++] = ')'; | 705 textVersion[ptr++] = ')'; |
689 } | 706 } |
690 textVersion[ptr++] = '\020'; | 707 textVersion[ptr++] = '\020'; |
691 textVersion[ptr] = 0; | 708 textVersion[ptr] = 0; |
692 | 709 |
693 tInfo_button_text("Exit","","Sleep"); | 710 tInfo_button_text("Exit","","Sleep"); |
694 tInfo_newpage("Bootloader 160602"); | 711 tInfo_newpage("Bootloader 240812"); |
695 tInfo_write("start bluetooth"); | 712 tInfo_write("start bluetooth"); |
696 tInfo_write(""); | 713 tInfo_write(""); |
697 tInfo_write(textVersion); | 714 tInfo_write(textVersion); |
698 tInfo_write(""); | 715 tInfo_write(""); |
699 | 716 |
700 TIM_init(); | 717 TIM_init(); |
701 MX_UART_Init(); | 718 MX_UART_Init(); |
702 MX_Bluetooth_PowerOn(); | 719 MX_Bluetooth_PowerOn(); |
703 tComm_Set_Bluetooth_Name(0); | 720 tComm_Set_Bluetooth_Name(0); |
704 | |
705 tComm_init(); | 721 tComm_init(); |
722 tComm_StartBlueModConfig(); | |
723 | |
706 set_globalState_Base(); | 724 set_globalState_Base(); |
707 | 725 |
708 GFX_start_VSYNC_IRQ(); | 726 GFX_start_VSYNC_IRQ(); |
709 | 727 |
710 EXTILine_Buttons_Config(); | 728 EXTILine_Buttons_Config(); |
1151 * @param None | 1169 * @param None |
1152 * @retval None | 1170 * @retval None |
1153 */ | 1171 */ |
1154 static void SystemClock_Config(void) | 1172 static void SystemClock_Config(void) |
1155 { | 1173 { |
1156 RCC_ClkInitTypeDef RCC_ClkInitStruct; | 1174 /* Enable Power Control clock */ |
1157 RCC_OscInitTypeDef RCC_OscInitStruct; | 1175 __PWR_CLK_ENABLE(); |
1158 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; | 1176 |
1159 | 1177 /* The voltage scaling allows optimizing the power consumption when the device is |
1160 /* Enable Power Control clock */ | 1178 clocked below the maximum system frequency, to update the voltage scaling value |
1161 __PWR_CLK_ENABLE(); | 1179 regarding system frequency refer to product datasheet. */ |
1162 | 1180 __HAL_PWR_VOLTAGESCALING_CONFIG( PWR_REGULATOR_VOLTAGE_SCALE1 ); |
1163 /* The voltage scaling allows optimizing the power consumption when the device is | 1181 |
1164 clocked below the maximum system frequency, to update the voltage scaling value | 1182 /*##-1- System Clock Configuration #########################################*/ |
1165 regarding system frequency refer to product datasheet. */ | 1183 /* Enable HighSpeed Oscillator and activate PLL with HSE/HSI as source */ |
1166 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); | 1184 RCC_OscInitTypeDef RCC_OscInitStruct = { 0 }; |
1167 | 1185 #ifdef DISC1_BOARD |
1168 /*##-1- System Clock Configuration #########################################*/ | 1186 // Use High Speed Internal (HSI) oscillator, running at 16MHz. |
1169 /* Enable HSE Oscillator and activate PLL with HSE as source */ | 1187 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; |
1170 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; | 1188 RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
1171 RCC_OscInitStruct.HSEState = RCC_HSE_ON; | 1189 RCC_OscInitStruct.HSICalibrationValue = 0x10; |
1172 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | 1190 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; |
1173 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; | 1191 RCC_OscInitStruct.PLL.PLLM = 16; // HSI/16 is 1Mhz. |
1174 RCC_OscInitStruct.PLL.PLLM = 8; | 1192 #else |
1175 RCC_OscInitStruct.PLL.PLLN = 336;//360; | 1193 // Use High Speed External oscillator, running at 8MHz |
1176 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; | 1194 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
1177 RCC_OscInitStruct.PLL.PLLQ = 7; | 1195 RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
1178 HAL_RCC_OscConfig(&RCC_OscInitStruct); | 1196 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
1197 RCC_OscInitStruct.PLL.PLLM = 8; // HSE/8 is 1Mhz. | |
1198 #endif | |
1199 // System clock = PLL (1MHz) * N/p = 180 MHz. | |
1200 RCC_OscInitStruct.PLL.PLLN = 360; | |
1201 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; | |
1202 RCC_OscInitStruct.PLL.PLLQ = 7; | |
1203 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
1204 HAL_RCC_OscConfig( &RCC_OscInitStruct ); | |
1179 | 1205 |
1180 // HAL_PWREx_ActivateOverDrive(); | 1206 // HAL_PWREx_ActivateOverDrive(); |
1181 HAL_PWREx_DeactivateOverDrive(); | 1207 HAL_PWREx_DeactivateOverDrive(); |
1182 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 | 1208 |
1183 clocks dividers */ | 1209 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ |
1184 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); | 1210 RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 }; |
1185 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | 1211 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK |
1186 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | 1212 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; |
1187 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; | 1213 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
1188 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; | 1214 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
1189 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_8);//FLASH_LATENCY_5); | 1215 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; |
1190 | 1216 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; |
1191 /*##-2- LTDC Clock Configuration ###########################################*/ | 1217 HAL_RCC_ClockConfig( &RCC_ClkInitStruct, FLASH_LATENCY_8 ); //FLASH_LATENCY_5); |
1192 /* LCD clock configuration */ | 1218 |
1193 /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */ | 1219 /*##-2- LTDC Clock Configuration ###########################################*/ |
1194 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */ | 1220 /* LCD clock configuration */ |
1195 /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 Mhz */ | 1221 /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */ |
1196 /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDIVR_8 = 48/8 = 6 Mhz */ | 1222 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */ |
1197 | 1223 /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 Mhz */ |
1198 /* neu: 8MHz/8*300/5/8 = 7,5 MHz = 19,5 Hz bei 800 x 480 */ | 1224 /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDIVR_8 = 48/8 = 6 Mhz */ |
1199 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC; | 1225 |
1200 PeriphClkInitStruct.PLLSAI.PLLSAIN = 300;//192; | 1226 /* neu: 8MHz/8*300/5/8 = 7,5 MHz = 19,5 Hz bei 800 x 480 */ |
1201 PeriphClkInitStruct.PLLSAI.PLLSAIR = 5;//4; | 1227 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; |
1202 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;//RCC_PLLSAIDIVR_4;// RCC_PLLSAIDIVR_2; // RCC_PLLSAIDIVR_8 | 1228 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC; |
1203 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); | 1229 PeriphClkInitStruct.PLLSAI.PLLSAIN = 300; //192; |
1230 PeriphClkInitStruct.PLLSAI.PLLSAIR = 5; //4; | |
1231 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;//RCC_PLLSAIDIVR_4;// RCC_PLLSAIDIVR_2; // RCC_PLLSAIDIVR_8 | |
1232 HAL_RCCEx_PeriphCLKConfig( &PeriphClkInitStruct ); | |
1204 } | 1233 } |
1205 | 1234 |
1206 | 1235 |
1207 /** | 1236 /** |
1208 * @brief This function is executed in case of error occurrence. | 1237 * @brief This function is executed in case of error occurrence. |
1501 WwdgHandle.Init.Prescaler = WWDG_PRESCALER_8; | 1530 WwdgHandle.Init.Prescaler = WWDG_PRESCALER_8; |
1502 WwdgHandle.Init.Window = 80; | 1531 WwdgHandle.Init.Window = 80; |
1503 WwdgHandle.Init.Counter = 127; | 1532 WwdgHandle.Init.Counter = 127; |
1504 | 1533 |
1505 HAL_WWDG_Init(&WwdgHandle); | 1534 HAL_WWDG_Init(&WwdgHandle); |
1506 HAL_WWDG_Start(&WwdgHandle); | 1535 /* HAL_WWDG_Start(&WwdgHandle); has been removed from HAL library starting_V120 */ |
1507 while(1); | 1536 while(1); |
1508 } | 1537 } |
1509 | 1538 |
1510 | 1539 |
1511 void set_returnFromComm(void) | 1540 void set_returnFromComm(void) |