Skip to content

Commit 2a6d8fa

Browse files
authored
use test app added
1 parent f7b03c4 commit 2a6d8fa

File tree

4 files changed

+1278
-0
lines changed

4 files changed

+1278
-0
lines changed
Lines changed: 280 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,280 @@
1+
/**
2+
******************************************************************************
3+
* File Name : main.c
4+
* Description : Main program body
5+
******************************************************************************
6+
** This notice applies to any and all portions of this file
7+
* that are not between comment pairs USER CODE BEGIN and
8+
* USER CODE END. Other portions of this file, whether
9+
* inserted by the user or by software development tools
10+
* are owned by their respective copyright owners.
11+
*
12+
* COPYRIGHT(c) 2017 STMicroelectronics
13+
*
14+
* Redistribution and use in source and binary forms, with or without modification,
15+
* are permitted provided that the following conditions are met:
16+
* 1. Redistributions of source code must retain the above copyright notice,
17+
* this list of conditions and the following disclaimer.
18+
* 2. Redistributions in binary form must reproduce the above copyright notice,
19+
* this list of conditions and the following disclaimer in the documentation
20+
* and/or other materials provided with the distribution.
21+
* 3. Neither the name of STMicroelectronics nor the names of its contributors
22+
* may be used to endorse or promote products derived from this software
23+
* without specific prior written permission.
24+
*
25+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35+
*
36+
******************************************************************************
37+
*/
38+
/* Includes ------------------------------------------------------------------*/
39+
#include "main.h"
40+
#include "stm32f4xx_hal.h"
41+
42+
/* USER CODE BEGIN Includes */
43+
44+
/* USER CODE END Includes */
45+
46+
/* Private variables ---------------------------------------------------------*/
47+
UART_HandleTypeDef huart2;
48+
49+
/* USER CODE BEGIN PV */
50+
/* Private variables ---------------------------------------------------------*/
51+
52+
/* USER CODE END PV */
53+
54+
/* Private function prototypes -----------------------------------------------*/
55+
void SystemClock_Config(void);
56+
static void MX_GPIO_Init(void);
57+
static void MX_USART2_UART_Init(void);
58+
59+
/* USER CODE BEGIN PFP */
60+
/* Private function prototypes -----------------------------------------------*/
61+
62+
/* USER CODE END PFP */
63+
64+
/* USER CODE BEGIN 0 */
65+
66+
char userdata[] = "Hello From user Application \r\n";
67+
68+
/* USER CODE END 0 */
69+
70+
int main(void)
71+
{
72+
73+
/* USER CODE BEGIN 1 */
74+
75+
/* USER CODE END 1 */
76+
77+
/* MCU Configuration----------------------------------------------------------*/
78+
79+
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
80+
HAL_Init();
81+
82+
/* USER CODE BEGIN Init */
83+
84+
/* USER CODE END Init */
85+
86+
/* Configure the system clock */
87+
SystemClock_Config();
88+
89+
/* USER CODE BEGIN SysInit */
90+
91+
/* USER CODE END SysInit */
92+
93+
/* Initialize all configured peripherals */
94+
MX_GPIO_Init();
95+
MX_USART2_UART_Init();
96+
97+
/* USER CODE BEGIN 2 */
98+
99+
/* USER CODE END 2 */
100+
101+
/* Infinite loop */
102+
/* USER CODE BEGIN WHILE */
103+
while (1)
104+
{
105+
/* USER CODE END WHILE */
106+
HAL_UART_Transmit(&huart2,(uint8_t*)userdata,sizeof(userdata),HAL_MAX_DELAY);
107+
uint32_t current_tick = HAL_GetTick();
108+
while(HAL_GetTick() <= current_tick +1000);
109+
110+
/* USER CODE BEGIN 3 */
111+
112+
}
113+
/* USER CODE END 3 */
114+
115+
}
116+
117+
/** System Clock Configuration
118+
*/
119+
void SystemClock_Config(void)
120+
{
121+
122+
RCC_OscInitTypeDef RCC_OscInitStruct;
123+
RCC_ClkInitTypeDef RCC_ClkInitStruct;
124+
125+
/**Configure the main internal regulator output voltage
126+
*/
127+
__HAL_RCC_PWR_CLK_ENABLE();
128+
129+
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
130+
131+
/**Initializes the CPU, AHB and APB busses clocks
132+
*/
133+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
134+
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
135+
RCC_OscInitStruct.HSICalibrationValue = 16;
136+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
137+
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
138+
RCC_OscInitStruct.PLL.PLLM = 16;
139+
RCC_OscInitStruct.PLL.PLLN = 336;
140+
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
141+
RCC_OscInitStruct.PLL.PLLQ = 2;
142+
RCC_OscInitStruct.PLL.PLLR = 2;
143+
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
144+
{
145+
_Error_Handler(__FILE__, __LINE__);
146+
}
147+
148+
/**Initializes the CPU, AHB and APB busses clocks
149+
*/
150+
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
151+
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
152+
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
153+
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
154+
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
155+
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
156+
157+
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
158+
{
159+
_Error_Handler(__FILE__, __LINE__);
160+
}
161+
162+
/**Configure the Systick interrupt time
163+
*/
164+
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
165+
166+
/**Configure the Systick
167+
*/
168+
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
169+
170+
/* SysTick_IRQn interrupt configuration */
171+
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
172+
}
173+
174+
/* USART2 init function */
175+
static void MX_USART2_UART_Init(void)
176+
{
177+
178+
huart2.Instance = USART2;
179+
huart2.Init.BaudRate = 115200;
180+
huart2.Init.WordLength = UART_WORDLENGTH_8B;
181+
huart2.Init.StopBits = UART_STOPBITS_1;
182+
huart2.Init.Parity = UART_PARITY_NONE;
183+
huart2.Init.Mode = UART_MODE_TX_RX;
184+
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
185+
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
186+
if (HAL_UART_Init(&huart2) != HAL_OK)
187+
{
188+
_Error_Handler(__FILE__, __LINE__);
189+
}
190+
191+
}
192+
193+
/** Configure pins as
194+
* Analog
195+
* Input
196+
* Output
197+
* EVENT_OUT
198+
* EXTI
199+
*/
200+
static void MX_GPIO_Init(void)
201+
{
202+
203+
GPIO_InitTypeDef GPIO_InitStruct;
204+
205+
/* GPIO Ports Clock Enable */
206+
__HAL_RCC_GPIOC_CLK_ENABLE();
207+
__HAL_RCC_GPIOH_CLK_ENABLE();
208+
__HAL_RCC_GPIOA_CLK_ENABLE();
209+
__HAL_RCC_GPIOB_CLK_ENABLE();
210+
211+
/*Configure GPIO pin Output Level */
212+
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
213+
214+
/*Configure GPIO pin : B1_Pin */
215+
GPIO_InitStruct.Pin = B1_Pin;
216+
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
217+
GPIO_InitStruct.Pull = GPIO_NOPULL;
218+
HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
219+
220+
/*Configure GPIO pin : LD2_Pin */
221+
GPIO_InitStruct.Pin = LD2_Pin;
222+
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
223+
GPIO_InitStruct.Pull = GPIO_NOPULL;
224+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
225+
HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct);
226+
227+
/* EXTI interrupt init*/
228+
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
229+
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
230+
231+
}
232+
233+
/* USER CODE BEGIN 4 */
234+
235+
/* USER CODE END 4 */
236+
237+
/**
238+
* @brief This function is executed in case of error occurrence.
239+
* @param None
240+
* @retval None
241+
*/
242+
void _Error_Handler(char * file, int line)
243+
{
244+
/* USER CODE BEGIN Error_Handler_Debug */
245+
/* User can add his own implementation to report the HAL error return state */
246+
while(1)
247+
{
248+
}
249+
/* USER CODE END Error_Handler_Debug */
250+
}
251+
252+
#ifdef USE_FULL_ASSERT
253+
254+
/**
255+
* @brief Reports the name of the source file and the source line number
256+
* where the assert_param error has occurred.
257+
* @param file: pointer to the source file name
258+
* @param line: assert_param error line source number
259+
* @retval None
260+
*/
261+
void assert_failed(uint8_t* file, uint32_t line)
262+
{
263+
/* USER CODE BEGIN 6 */
264+
/* User can add his own implementation to report the file name and line number,
265+
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
266+
/* USER CODE END 6 */
267+
268+
}
269+
270+
#endif
271+
272+
/**
273+
* @}
274+
*/
275+
276+
/**
277+
* @}
278+
*/
279+
280+
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

0 commit comments

Comments
 (0)