app_loader.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. ******************************************************************************
  3. * File Name : main.c
  4. * Description : Main program body
  5. ******************************************************************************
  6. *
  7. * COPYRIGHT(c) 2015 STMicroelectronics
  8. *
  9. * Redistribution and use in source and binary forms, with or without modification,
  10. * are permitted provided that the following conditions are met:
  11. * 1. Redistributions of source code must retain the above copyright notice,
  12. * this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright notice,
  14. * this list of conditions and the following disclaimer in the documentation
  15. * and/or other materials provided with the distribution.
  16. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  17. * may be used to endorse or promote products derived from this software
  18. * without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  24. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  26. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  27. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. ******************************************************************************
  32. */
  33. #ifndef __APP_LOADER_H__
  34. #define __APP_LOADER_H__
  35. /* Includes ------------------------------------------------------------------*/
  36. #define STM32F103 1
  37. #define STM32F072 0
  38. #if STM32F103
  39. #include "stm32f1xx_hal.h"
  40. #define NEW_VECTOR_OFFSET (uint32_t)0x00003000
  41. #elif STM32F072
  42. #include "stm32f0xx_hal.h"
  43. #define APPLICATION_ADDRESS (uint32_t)0x08003000
  44. #define NEW_VECTOR_ADDRESS (uint32_t)0x20000000
  45. #endif
  46. /* USER CODE BEGIN Includes */
  47. /* USER CODE END Includes */
  48. /* Private variables ---------------------------------------------------------*/
  49. /* USER CODE BEGIN PV */
  50. /* Private variables ---------------------------------------------------------*/
  51. /* USER CODE END PV */
  52. /* Private function prototypes -----------------------------------------------*/
  53. /* USER CODE BEGIN PFP */
  54. /* Private function prototypes -----------------------------------------------*/
  55. extern void IAP_Init(void)
  56. {
  57. #if (STM32F103 == 1)
  58. #ifdef VECT_TAB_SRAM
  59. SCB->VTOR = SRAM_BASE | NEW_VECTOR_OFFSET; /* Vector Table Relocation in Internal SRAM. */
  60. #else
  61. SCB->VTOR = FLASH_BASE | NEW_VECTOR_OFFSET; /* Vector Table Relocation in Internal FLASH. */
  62. #endif
  63. #elif (STM32F072 == 1)
  64. /* Relocate by software the vector table to the internal SRAM at 0x20000000 ***/
  65. uint32_t i = 0;
  66. /* Copy the vector table from the Flash (mapped at the base of the application
  67. load address 0x08003000) to the base address of the SRAM at 0x20000000. */
  68. for(i = 0; i < 48; i++)
  69. {
  70. *((uint32_t*)(NEW_VECTOR_ADDRESS + (i << 2)))=*(__IO uint32_t*)(APPLICATION_ADDRESS + (i<<2));
  71. }
  72. /* Enable the SYSCFG peripheral clock*/
  73. __HAL_RCC_SYSCFG_CLK_ENABLE();
  74. /* Remap SRAM at 0x00000000 */
  75. __HAL_SYSCFG_REMAPMEMORY_SRAM();
  76. #endif
  77. }
  78. #endif /*___APP_LOADER_H__ */
  79. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/