boot.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-01-19 19813 the first version
  9. */
  10. ///
  11. ///
  12. ///
  13. ///
  14. ///
  15. /// 使用跳转功能前需要设置的几项
  16. ///
  17. /// 1. 设置boot loader工程的rom 起始地址不变 大小缩减为给bl预留的大小
  18. /// 设置位置在linkscripts stm32xxxx - > link.lds
  19. ///
  20. /// 2. 设置bl工程中的烧录方式由auto改为块擦除 选择烧录bin文件 起始位置不变
  21. ///
  22. /// 3. 设置app工程中 rom的起始位置为0x08000000 + bl预留空间的大小 设置rom大小为flash大小-bl大小
  23. ///
  24. /// 4. 设置app工程中的烧录方式由auto改为块擦除 选择烧录bin文件 起始位置改为0x08000000 + bl预留空间的大小
  25. ///
  26. /// 5. 在app工程中libraries\CMSIS\Device\ST\STM32G0xx\Source\Templates\System_stm32xxxx.h中
  27. /// 修改中断向量表的宏定义 VECT_TAB_OFFSET 的值 由默认值0x0U 改为app Rom起始地址
  28. /// 如预留32K给bootloader 则 VECT_TAB_OFFSET 的值设置为0x8000U 即可
  29. ///
  30. /// 6. 再BL工程中 #define app_start_addr 修改为 0x08000000 + VECT_TAB_OFFSET ( boot.c ) 同时修改iap.c中的定义
  31. ///
  32. /// 7. App工程中 iap.c 和 at_client.c 中 #define 的 App_size 的大小改为app区 的空间大小
  33. ///
  34. ///
  35. ///
  36. ///
  37. ///
  38. ///
  39. #include "boot.h"
  40. #include "main.h"
  41. #define app_start_addr 0x08008000
  42. void Start_app(void)
  43. {
  44. rt_kprintf("Go To App --->");
  45. HAL_RCC_DeInit();
  46. SysTick->CTRL = 0;
  47. SysTick->LOAD = 0;
  48. SysTick->VAL = 0;
  49. HAL_DeInit();
  50. __set_PRIMASK(1); /* 关闭总中断 */
  51. pFunction Jump_To_Application;
  52. __IO uint32_t JumpAddress;
  53. /* Test if user code is programmed starting from address "APPLICATION_ADDRESS" */
  54. if (((*(__IO uint32_t *)app_start_addr) & 0x2FFE0000) == 0x20000000)
  55. {
  56. /* Jump to user application */
  57. JumpAddress = *(__IO uint32_t *)(app_start_addr + 4);
  58. Jump_To_Application = (pFunction)JumpAddress;
  59. /* Initialize user application's Stack Pointer */
  60. __set_MSP(*(__IO uint32_t *)app_start_addr);
  61. Jump_To_Application();
  62. }
  63. // else
  64. // {
  65. // rt_kprintf("Address Err\n");
  66. // }
  67. }