38
|
1 /**
|
|
2 ******************************************************************************
|
|
3 * @file firmwareJumpToApplication.c
|
|
4 * @author heinrichs weikamp gmbh
|
|
5 * @version V0.0.1
|
|
6 * @date 05-May-2015
|
|
7 * @version V0.0.1
|
|
8 * @since 05-May-2015
|
|
9 * @brief jump to application in higher flash region
|
|
10 *
|
|
11 @verbatim
|
|
12 ==============================================================================
|
|
13 ##### How to use #####
|
|
14 ==============================================================================
|
|
15
|
|
16 ==============================================================================
|
|
17 ##### From AN2557 #####
|
|
18 STM32F10xxx In-Application programming CD00161640.pdf 2010
|
|
19 ==============================================================================
|
|
20 User program conditions
|
|
21 The user application to be loaded into the Flash memory using IAP should be built with
|
|
22 these configuration settings:
|
|
23 1. Set the program load address at 0x08003000, using your toolchain linker file
|
|
24 2. Relocate the vector table at address 0x08003000, using the
|
|
25 "NVIC_SetVectorTable"function or the VECT_TAB_OFFSET definition inside the
|
|
26 "system_stm32f10x.c"
|
|
27
|
|
28 can be found here system_stm32f4xx.c
|
|
29
|
|
30
|
|
31 @endverbatim
|
|
32 ******************************************************************************
|
|
33 * @attention
|
|
34 *
|
|
35 * <h2><center>© COPYRIGHT(c) 2015 heinrichs weikamp</center></h2>
|
|
36 *
|
|
37 ******************************************************************************
|
|
38 */
|
|
39
|
|
40 /* Includes ------------------------------------------------------------------*/
|
|
41 #include "stm32f4xx_hal.h"
|
|
42 #include "stdio.h"
|
|
43 #include "firmwareJumpToApplication.h"
|
|
44
|
|
45 /* Exported variables --------------------------------------------------------*/
|
|
46
|
|
47 /* Private types -------------------------------------------------------------*/
|
|
48 typedef void (*pFunction)(void);
|
|
49 #define ApplicationAddress 0x08040000
|
|
50
|
|
51 /* Private variables ---------------------------------------------------------*/
|
|
52 pFunction Jump_To_Application;
|
|
53 uint32_t JumpAddress;
|
|
54
|
|
55 /* Private function prototypes -----------------------------------------------*/
|
|
56
|
|
57 /* Exported functions --------------------------------------------------------*/
|
|
58 uint8_t firmware_MainCodeIsProgammed(void)
|
|
59 {
|
|
60 uint32_t content_start;
|
|
61 content_start = *(__IO uint32_t*)ApplicationAddress;
|
|
62
|
|
63 if ((content_start & 0x2FFE0000 ) == 0x20000000)
|
|
64 return 1;
|
|
65 else
|
|
66 return 0;
|
|
67 }
|
|
68
|
|
69 void firmware_JumpTo_Application(void)
|
|
70 {
|
|
71 /* Test if user code is programmed starting from address "ApplicationAddress" */
|
|
72 if (((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000)
|
|
73 {
|
|
74 /* Jump to user application */
|
|
75 JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);
|
|
76 Jump_To_Application = (pFunction) JumpAddress;
|
|
77 /* Initialize user application's Stack Pointer */
|
|
78 __set_MSP(*(__IO uint32_t*) ApplicationAddress);
|
|
79 Jump_To_Application();
|
|
80 }
|
|
81 while (1)
|
|
82 {}
|
|
83 }
|
|
84
|
|
85 /* Private functions ---------------------------------------------------------*/
|