提交 | 用户 | age
|
483170
|
1 |
|
Q |
2 |
/** |
|
3 |
****************************************************************************** |
|
4 |
* @file : main.c |
|
5 |
* @brief : Main program body |
|
6 |
****************************************************************************** |
|
7 |
** This notice applies to any and all portions of this file |
|
8 |
* that are not between comment pairs USER CODE BEGIN and |
|
9 |
* USER CODE END. Other portions of this file, whether |
|
10 |
* inserted by the user or by software development tools |
|
11 |
* are owned by their respective copyright owners. |
|
12 |
* |
|
13 |
* COPYRIGHT(c) 2018 STMicroelectronics |
|
14 |
* |
|
15 |
* Redistribution and use in source and binary forms, with or without modification, |
|
16 |
* are permitted provided that the following conditions are met: |
|
17 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
18 |
* this list of conditions and the following disclaimer. |
|
19 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
20 |
* this list of conditions and the following disclaimer in the documentation |
|
21 |
* and/or other materials provided with the distribution. |
|
22 |
* 3. Neither the name of STMicroelectronics nor the names of its contributors |
|
23 |
* may be used to endorse or promote products derived from this software |
|
24 |
* without specific prior written permission. |
|
25 |
* |
|
26 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
27 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
28 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
29 |
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
|
30 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
31 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|
32 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
33 |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
|
34 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
35 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
36 |
* |
|
37 |
****************************************************************************** |
|
38 |
*/ |
|
39 |
/* Includes ------------------------------------------------------------------*/ |
|
40 |
#include "main.h" |
|
41 |
#include "stm32f0xx_hal.h" |
|
42 |
|
|
43 |
/* USER CODE BEGIN Includes */ |
|
44 |
#include "Globaldef.h" |
|
45 |
#include "debug.h" |
|
46 |
#include "Functions.h" |
|
47 |
#include "string.h" |
|
48 |
#include "BSP.h" |
|
49 |
|
|
50 |
/* USER CODE END Includes */ |
|
51 |
|
|
52 |
/* Private variables ---------------------------------------------------------*/ |
|
53 |
|
|
54 |
/* USER CODE BEGIN PV */ |
|
55 |
/* Private variables ---------------------------------------------------------*/ |
|
56 |
|
|
57 |
unsigned char SlowFlicker=0; |
|
58 |
unsigned char FastFlicker=0; |
|
59 |
|
|
60 |
|
|
61 |
uint32_t us1,us2,us3,us4,us5,us6; |
|
62 |
|
|
63 |
/* USER CODE END PV */ |
|
64 |
|
|
65 |
/* Private function prototypes -----------------------------------------------*/ |
|
66 |
|
|
67 |
|
|
68 |
/* USER CODE BEGIN PFP */ |
|
69 |
/* Private function prototypes -----------------------------------------------*/ |
|
70 |
|
|
71 |
/* USER CODE END PFP */ |
|
72 |
|
|
73 |
/* USER CODE BEGIN 0 */ |
|
74 |
|
|
75 |
void HAL_SYSTICK_Callback(void) |
|
76 |
{ |
|
77 |
static int Count=0; |
|
78 |
Count++; |
|
79 |
if (Count>=10000) |
|
80 |
{ |
|
81 |
Count=0; |
|
82 |
} |
|
83 |
|
|
84 |
return; |
|
85 |
} |
|
86 |
|
|
87 |
#define ApplicationAddress 0x08001000 //应用程序首地址定义 |
|
88 |
|
|
89 |
typedef void (*pFunction)(void); //定义跳转函数指针类型 |
|
90 |
|
|
91 |
|
|
92 |
/*跳转到应用程序处理函数*/ |
|
93 |
static void JumpToApplication(void) |
|
94 |
{ |
|
95 |
uint32_t StackAddr; //应用程序栈地址 |
|
96 |
uint32_t ResetVector; //应用程序中断向量表的地址 |
|
97 |
|
|
98 |
pFunction JumpToApp; //定义跳转函数指针 |
|
99 |
|
|
100 |
__set_PRIMASK(1); //关闭全局中断 |
|
101 |
|
8b51c7
|
102 |
StackAddr = *(__IO uint32_t*)ApplicationAddress; //0x08001000; |
Q |
103 |
ResetVector = *(__IO uint32_t*)(ApplicationAddress + 4); //0x08001004; |
483170
|
104 |
|
Q |
105 |
if((StackAddr&0x2FFC0000)==0x20000000) //检查栈顶地址是否合法. |
|
106 |
{ |
|
107 |
__disable_irq(); |
|
108 |
memcpy((void *)0x20000000,(void *)ApplicationAddress,0xc0); |
|
109 |
|
|
110 |
__set_MSP(StackAddr); //初始化应用程序栈指针 |
|
111 |
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_SYSCFG); |
|
112 |
LL_SYSCFG_SetRemapMemory(LL_SYSCFG_REMAP_SRAM); |
|
113 |
// SYSCFG |
|
114 |
JumpToApp = (pFunction)ResetVector; |
|
115 |
JumpToApp(); |
|
116 |
} |
|
117 |
} |
|
118 |
|
|
119 |
/* USER CODE END 0 */ |
|
120 |
|
|
121 |
/** |
|
122 |
* @brief The application entry point. |
|
123 |
* |
|
124 |
* @retval None |
|
125 |
*/ |
|
126 |
int main(void) |
|
127 |
{ |
|
128 |
/* USER CODE BEGIN 1 */ |
|
129 |
|
|
130 |
// InitUartstat(&Uart1Stat,Uart1RxBuf,sizeof(Uart1RxBuf),Uart1TxBuf,sizeof(Uart1TxBuf)); |
|
131 |
// InitUartstat(&Uart2Stat,Uart2RxBuf,sizeof(Uart2RxBuf),Uart2TxBuf,sizeof(Uart2TxBuf)); |
|
132 |
/* USER CODE END 1 */ |
|
133 |
|
|
134 |
/* MCU Configuration----------------------------------------------------------*/ |
|
135 |
|
|
136 |
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
|
137 |
// HAL_Init(); |
|
138 |
|
|
139 |
/* USER CODE BEGIN Init */ |
|
140 |
|
|
141 |
/* USER CODE END Init */ |
|
142 |
|
|
143 |
/* Configure the system clock */ |
|
144 |
|
|
145 |
/* USER CODE BEGIN SysInit */ |
|
146 |
// HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/TickFreq); //重新定义SysTick的频率 |
|
147 |
LL_Init1msTick(8000000); |
|
148 |
MX_GPIO_Init(); |
|
149 |
|
|
150 |
/* USER CODE END SysInit */ |
|
151 |
|
|
152 |
|
|
153 |
/* USER CODE BEGIN 2 */ |
|
154 |
|
|
155 |
//LL_USART_EnableIT_TXE(USART1); |
|
156 |
/* USER CODE END 2 */ |
|
157 |
|
|
158 |
/* Infinite loop */ |
|
159 |
/* USER CODE BEGIN WHILE */ |
|
160 |
|
|
161 |
SetRunLed(1); //Turn On Run Led |
|
162 |
SetErrLed(0); //Turn Off Err Led |
8b51c7
|
163 |
// |
483170
|
164 |
int nCount=0; |
Q |
165 |
while (1) |
|
166 |
{ |
|
167 |
|
|
168 |
SlowFlicker=0; |
|
169 |
FastFlicker=1; |
|
170 |
us1=GetuS(); |
8b51c7
|
171 |
LL_mDelay(100); |
483170
|
172 |
|
8b51c7
|
173 |
// ToggleRunLed(); |
Q |
174 |
// ToggleErrLed(); |
483170
|
175 |
ToggleErr2Led(); |
Q |
176 |
|
|
177 |
// LL_IWDG_ReloadCounter(IWDG); |
|
178 |
nCount++; |
8b51c7
|
179 |
if (nCount>2) {JumpToApplication(); LL_mDelay(1000);} |
483170
|
180 |
|
Q |
181 |
} //while (1) ; |
|
182 |
/* USER CODE END WHILE */ |
|
183 |
|
|
184 |
/* USER CODE BEGIN 3 */ |
|
185 |
|
|
186 |
/* USER CODE END 3 */ |
|
187 |
} |
|
188 |
/* USER CODE BEGIN 4 */ |
|
189 |
|
|
190 |
/* USER CODE END 4 */ |
|
191 |
|
|
192 |
/** |
|
193 |
* @brief This function is executed in case of error occurrence. |
|
194 |
* @param file: The file name as string. |
|
195 |
* @param line: The line in file as a number. |
|
196 |
* @retval None |
|
197 |
*/ |
|
198 |
void _Error_Handler(char *file, int line) |
|
199 |
{ |
|
200 |
/* USER CODE BEGIN Error_Handler_Debug */ |
|
201 |
/* User can add his own implementation to report the HAL error return state */ |
|
202 |
while(1) |
|
203 |
{ |
|
204 |
} |
|
205 |
/* USER CODE END Error_Handler_Debug */ |
|
206 |
} |
|
207 |
|
|
208 |
#ifdef USE_FULL_ASSERT |
|
209 |
/** |
|
210 |
* @brief Reports the name of the source file and the source line number |
|
211 |
* where the assert_param error has occurred. |
|
212 |
* @param file: pointer to the source file name |
|
213 |
* @param line: assert_param error line source number |
|
214 |
* @retval None |
|
215 |
*/ |
|
216 |
void assert_failed(uint8_t* file, uint32_t line) |
|
217 |
{ |
|
218 |
/* USER CODE BEGIN 6 */ |
|
219 |
/* User can add his own implementation to report the file name and line number, |
|
220 |
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
|
221 |
/* USER CODE END 6 */ |
|
222 |
} |
|
223 |
#endif /* USE_FULL_ASSERT */ |
|
224 |
|
|
225 |
/** |
|
226 |
* @} |
|
227 |
*/ |
|
228 |
|
|
229 |
/** |
|
230 |
* @} |
|
231 |
*/ |
|
232 |
|
|
233 |
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |