
开发板到了,先点个灯吧,使用STM32CUBEMX,对HAL库还不是很熟悉,才开始还走了一点弯路,不知道HAL_GPIO_WritePin()函数如何设置,后来发现原来在这里,
![]() / O4 K3 x8 e% J \0 _ 以下是main()函数,总体感觉HAL库还是很好用的,要是有更详细的文档说明就更好了。( T" h: g, z1 c! y+ L8 R) H /** ****************************************************************************** * File Name : main.c4 g) o" e- Q9 `+ f$ D! q8 x% `3 B * Date : 25/12/2014 16:24:543 J2 R4 I) t. e' v" p0 V% d& O * Description : Main program body ******************************************************************************1 a* d3 H& s |6 L * * COPYRIGHT(c) 2014 STMicroelectronics * j8 N' I. q0 z. y0 e/ ^ * Redistribution and use in source and binary forms, with or without modification,& F0 Y6 G0 t7 `. x+ w$ K2 Y$ v * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice,8 }. n+ Z/ O2 e$ G2 V1 ?$ ^3 J * this list of conditions and the following disclaimer.+ Q8 a$ l) ]% C+ [% _2 U * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation! {/ U3 r* J0 g! d0 \ * 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! R, N6 g N& o7 N( q2 g4 s5 s * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE- J8 |6 Y6 H. d6 \ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL3 U# M* Y! u: x' j- h& G! E$ w * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER) P8 r8 E+ M5 A* N * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,6 ~9 w. f& X2 t% Y2 l9 |6 i * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE% P# W5 D/ @& t3 _+ i3 H * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.9 k& @/ O2 f+ Y6 F% S * ****************************************************************************** */! |7 W! h5 }/ {; e( p ( R+ f) p& |- j" Y7 Q8 h, O /* Includes ------------------------------------------------------------------*/ #include "stm32f0xx_hal.h" " d3 ~& `. U, ^; I b- I) b /* USER CODE BEGIN Includes */% h, s" Y/ ?8 O4 O /* USER CODE END Includes */ /* Private variables ---------------------------------------------------------*/ : @; K$ H& H' Y4 t( w+ t/ | /* USER CODE BEGIN PV */9 M" F, O/ @( L) L- ^3 D6 } . I' a" z' i: t: |, U; e /* USER CODE END PV */9 ?7 v5 m+ |3 B& I /* Private function prototypes -----------------------------------------------*/8 E: `8 k5 O: h# _ void SystemClock_Config(void);/ j7 N! V+ w& h4 t* L) W0 ~ static void MX_GPIO_Init(void);9 h; O! q/ m/ [8 o6 V3 x6 j, e7 G & P: ]# q) N3 M8 W; P1 |3 P& l /* USER CODE BEGIN PFP */ / W0 A- e: {: W8 s* [! w /* USER CODE END PFP */ ' W$ l% m+ {1 s% A) O( e' L j /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ ' p& l( E( @6 W2 c9 D6 x, X int main(void): P R* z5 g2 d' V% i; ] {, t( V$ u8 o2 o$ H% R; B /* USER CODE BEGIN 1 */ - C# E& E0 o/ l, Y /* USER CODE END 1 */$ e Z/ v9 w U. r. R /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */$ s- p' w8 z* I9 N% j5 Z5 L HAL_Init(); 8 F: Z9 }( H4 D6 J* a# u: z' T /* Configure the system clock */ SystemClock_Config();; d0 B! G% m3 y, U D8 l8 ~ /* Initialize all configured peripherals */ MX_GPIO_Init(); 4 K) K. \3 j. m0 ^ /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ 5 x% A) e6 c* n4 G, W /* USER CODE BEGIN 3 */( \, s. u8 E3 c+ v+ O /* Infinite loop */ while (1) {$ m' O1 v5 J, F" n* z7 ]0 o9 q8 u4 v HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_SET);& J' Q! Z! o# d M& J HAL_Delay(500); HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_RESET); HAL_Delay(500); } /* USER CODE END 3 */" p6 _( x( O# T) ?$ t3 n . s3 h4 T i9 L! M! f4 _1 A3 l, y }. G. T7 S: Q' n z , a+ A9 E0 q& |6 h /** System Clock Configuration8 [# k0 ~1 v4 k- e) Z */* g# A; z; c/ P; K; E1 u/ n* s7 @ void SystemClock_Config(void)! I! v! i5 S( p/ a/ Y- j: i {, J2 G* C4 Z$ l) F5 t4 [ : Z: P* [' N4 j7 D4 i, N RCC_OscInitTypeDef RCC_OscInitStruct; RCC_ClkInitTypeDef RCC_ClkInitStruct;! l+ x, }% {( r# U3 q- R' B5 _) e. L! a ' D& ?) |( n; i2 |% Q0 m/ ? RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = 16;: z, _- N8 `: F0 d4 H RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;( I# E* h; T8 d. u& O1 F. C HAL_RCC_OscConfig(&RCC_OscInitStruct); RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;- j% U% n9 l% c+ E RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0); ( |/ s* `; f/ z __SYSCFG_CLK_ENABLE(); } / p- _0 M4 v9 A+ |$ B& N /** Configure pins as * Analog 5 e% t9 Q% A4 I' P- _* j& M * Input 9 I2 h& e1 _5 Z1 J( c/ O * Output+ o# P6 B( |2 K$ X * EVENT_OUT * EXTI */ void MX_GPIO_Init(void) {; J! U1 n9 w. S. i* a' J1 s ( W# b7 d7 a9 ?1 I1 ]( U GPIO_InitTypeDef GPIO_InitStruct; @4 Z8 w8 K$ Z0 C4 T2 D ) ~/ i. a4 f4 h /* GPIO Ports Clock Enable */ __GPIOA_CLK_ENABLE();! c& }/ v% \. n1 L E# Z 4 H4 o' n% d& t/ s) d /*Configure GPIO pin : PA5 */" Y' `- R T$ S4 l5 r GPIO_InitStruct.Pin = GPIO_PIN_5; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL;. L5 l3 s9 X2 t h5 @/ Z GPIO_InitStruct.Speed = GPIO_SPEED_LOW;% N, W' Q% {+ G* O$ `( q HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); } ! j) Y4 m! q3 K /* USER CODE BEGIN 4 */$ K) d6 X) X# N* {0 V /* USER CODE END 4 */9 S) S" P% w) A1 l4 F3 _$ | " l' H9 x7 N# A: h5 O #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number# F8 T8 ^0 [1 o% I * where the assert_param error has occurred. * @param file: pointer to the source file name5 ]( l2 W3 w/ w: p+ Z' @+ x- _ * @param line: assert_param error line source number' P5 g- s/ }8 g; T * @retval None */ void assert_failed(uint8_t* file, uint32_t line) { /* USER CODE BEGIN 6 */% j) F( I8 F3 @- H /* User can add his own implementation to report the file name and line number,8 Y6 o4 a+ @ C0 _" S# K ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */2 N4 v! y+ O- A$ g! X4 C: m5 U } #endif 3 f+ d) M& B, Y! v /** * @} */ /** P3 [1 `$ \- @4 k% B* i * @} */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ ' ^0 o5 r! ~) W) [( m5 W |
谢谢~通常来说,下一步就是按键了![]() ![]() |
是啊 按套路来![]() |