
开发板到了,先点个灯吧,使用STM32CUBEMX,对HAL库还不是很熟悉,才开始还走了一点弯路,不知道HAL_GPIO_WritePin()函数如何设置,后来发现原来在这里,
![]() : }3 ~- i# \* \3 z& x6 T 以下是main()函数,总体感觉HAL库还是很好用的,要是有更详细的文档说明就更好了。# W0 M# t' z3 q) C0 w /** ******************************************************************************+ x4 u; r+ I* e: u) [$ \ * File Name : main.c& r( n( S; X, ]- i * Date : 25/12/2014 16:24:54 * Description : Main program body ******************************************************************************# y( q0 j6 d+ E0 ^ Q2 ? *% w& M% |; x' {( } * COPYRIGHT(c) 2014 STMicroelectronics8 a- }' O! l0 U *+ V+ o7 q* ~8 x, L l' v * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice,, C3 \' N5 l$ I, K! M- W9 a * this list of conditions and the following disclaimer in the documentation W5 {" \, h2 p+ F, u * and/or other materials provided with the distribution. * 3. Neither the name of STMicroelectronics nor the names of its contributors * may be used to endorse or promote products derived from this software, V/ B5 l, V/ Q, i" m * without specific prior written permission. *$ G+ |! d1 z& H- p+ \/ [/ q * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS", t$ }8 U5 h1 O7 h; G, { * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE/ O- {. T2 H* d t. F( t2 i( ^ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL2 V ]1 T- T$ M6 z * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR8 Y7 c3 X% U, _. ^2 H& M; h0 U * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, T% b% x! Z6 B5 [% f+ S * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.5 u; p( k* E+ K$ Y& F5 ~* J% ] *7 c- w% S+ n3 I1 }! G ******************************************************************************3 u" l* D8 M! w- j- ?& R */ /* Includes ------------------------------------------------------------------*// D7 {, D. m0 k; l/ s) ~$ O #include "stm32f0xx_hal.h" 7 g' N v4 i! h9 e /* USER CODE BEGIN Includes */3 r/ K0 E$ j8 D, f# k! L- c$ Z % v( o* E3 K9 L0 ^8 j$ A/ z1 } /* USER CODE END Includes */ , V' M& Y3 ]3 \ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ & R) t9 `" c2 E4 D$ [4 V8 ? /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); ) q$ ?, t5 b. E /* USER CODE BEGIN PFP */, [' J8 V/ t. Y: D$ n7 ~" u /* USER CODE END PFP */ /* USER CODE BEGIN 0 */; z* I( g7 i. E9 V /* USER CODE END 0 */: e" p, d- ^! ~/ E int main(void) { /* USER CODE BEGIN 1 */ " ~" t9 _* ]4 `: [; Y. j /* USER CODE END 1 */2 b# ]( ~5 } P* N y, d /* MCU Configuration----------------------------------------------------------*/# m6 B- k5 S, u f2 v( a7 C& `( Y6 X ; c( P$ P3 s J' r0 _ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); 4 | f7 V* m: [ /* Configure the system clock */ SystemClock_Config();. U4 D; @* [2 \* w /* Initialize all configured peripherals */& Z1 ?! \+ S; d6 L2 X MX_GPIO_Init(); , }9 X# ?. w9 I( m/ V /* USER CODE BEGIN 2 */ /* USER CODE END 2 */; i5 T0 z k% g4 ` /* USER CODE BEGIN 3 */: h# O( w2 n& g! \5 e+ i6 ^ /* Infinite loop */ while (1)8 x# i, _8 e6 V' f( ~8 ^; W {' ~+ v0 D, G( w5 y" q HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_SET); HAL_Delay(500);7 O, v% o: P7 c$ j) L HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_RESET); HAL_Delay(500);( V0 n0 T v4 s) y6 e( c } /* USER CODE END 3 */ ! d4 Y1 \$ a u1 \- g2 K( t3 b }! n! X4 e) @( i7 O4 ` /** System Clock Configuration7 O. H; N1 I0 o% x* E" R T6 e */ void SystemClock_Config(void)- C. X& d% o a% ` { / t( J! H' U6 @! o( k) k2 C# K; f RCC_OscInitTypeDef RCC_OscInitStruct;5 \2 j( o; x! Z& ] RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = 16;1 H& g+ n# ?2 ?1 o/ e7 p RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;8 [, ^- I, a# V+ ~6 j$ C HAL_RCC_OscConfig(&RCC_OscInitStruct);7 l( b5 I4 b4 m9 S / W5 Z' h/ x7 U; v9 l, R RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;7 [$ @5 r: j( [+ t RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;& h3 i7 c5 q3 E# G2 H7 [6 ?1 e RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;7 n) E. W8 R& v: l RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;3 \: M! O; Y1 ~: N6 b% O HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0); 7 i/ c4 r& i. F9 p! E1 V& Y7 N __SYSCFG_CLK_ENABLE(); 6 z9 `; s- X$ J- |' K } /** Configure pins as * Analog * Input X; ]! C" B1 j. Z* } * Output * EVENT_OUT: u! Q# R! A8 ~. S9 { * EXTI; ~2 ?7 p! U3 J, ^5 G */ void MX_GPIO_Init(void) {5 V$ n( E& T8 x, q8 f GPIO_InitTypeDef GPIO_InitStruct;# l& Z- Q: Y; `! v5 _6 p /* GPIO Ports Clock Enable */ __GPIOA_CLK_ENABLE(); 2 r( @( s) z# x /*Configure GPIO pin : PA5 */ GPIO_InitStruct.Pin = GPIO_PIN_5;& q1 h5 U! e% d1 {5 V7 ^ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;- z1 q! T" ^" k" F/ a GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_LOW;- C3 H' ?- J; S- c HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);) `5 I( ?$ [. Q" @, t3 D4 S% ~ ; E$ c2 E( s% B0 v4 L } J% F6 ^1 ^2 W7 b) A5 g /* USER CODE BEGIN 4 */ & }6 F( G2 m4 G+ [& T /* USER CODE END 4 */ ; j7 s# R5 s) C3 {4 r #ifdef USE_FULL_ASSERT /**% [# A! A! E% \5 E' }1 k * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred.3 K; U' f- Y3 l * @param file: pointer to the source file name4 H+ b% R+ l+ G& _: R6 y* D# \ * @param line: assert_param error line source number5 P+ d6 R6 i. I * @retval None' ^. [/ ?# b, w/ l */ void assert_failed(uint8_t* file, uint32_t line)( n* J- A4 N4 E! U1 y" q1 ` { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */* W( W# c5 Y% C' l; M/ ~0 F- }0 ? /* USER CODE END 6 */) Y" Y& c3 Q5 y, ]8 C " ~* _/ K" K) z7 t/ w4 Q } , k# H( y2 l7 [! M #endif /** * @}" E; B. Z/ E* l- S+ S+ i% \ */ ' y5 c* T0 `3 W8 {; K0 H /**1 B. J2 v( f1 P8 j2 ^0 }7 n * @}; a3 H8 c) }' e8 x( a [- K */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/* m& u. ?' O) \ 2 F" F T) ^/ g# h. W8 d3 j% ]2 f 2 B1 d9 J4 [1 E: x2 p |
谢谢~通常来说,下一步就是按键了![]() ![]() |
是啊 按套路来![]() |