
开发板到了,先点个灯吧,使用STM32CUBEMX,对HAL库还不是很熟悉,才开始还走了一点弯路,不知道HAL_GPIO_WritePin()函数如何设置,后来发现原来在这里,
![]() " Q$ Z+ g/ I h: b4 t: [ 以下是main()函数,总体感觉HAL库还是很好用的,要是有更详细的文档说明就更好了。 /** ****************************************************************************** a* i- d/ N' G0 r, \0 P3 T0 C * File Name : main.c * Date : 25/12/2014 16:24:54+ w3 T0 w) ~7 O9 ~5 ?/ I" m * Description : Main program body. U7 J# o R3 }& j( h, E8 l+ b7 J ****************************************************************************** * * COPYRIGHT(c) 2014 STMicroelectronics * * Redistribution and use in source and binary forms, with or without modification,6 o+ E& Z% x3 [& }6 e * are permitted provided that the following conditions are met:& p2 s% p# K. v8 r3 ^8 i3 ~ * 1. Redistributions of source code must retain the above copyright notice,& S' E) `4 i) A * this list of conditions and the following disclaimer.7 X; t; y" W4 l8 B( ] * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution.( O8 T0 g' q! a * 3. Neither the name of STMicroelectronics nor the names of its contributors! |1 [! ~% V' k0 G3 a3 I, ?. R$ \7 x * may be used to endorse or promote products derived from this software' k$ k: X0 W$ ^" z* w$ A. L, b * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS") d/ V+ E9 o% f * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE9 n( b8 {/ n8 T; `. ~ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL$ D0 M! ?- T7 Q, {8 d * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * 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 [! f0 L- n) P* F P *# B1 X9 \( i7 z0 {) Z7 V% W0 [ ******************************************************************************% r6 m0 Q- D; T7 V. m */+ K) d t, ~4 [0 s* B/ P /* Includes ------------------------------------------------------------------*/0 r l9 S$ [5 y+ {9 O8 [/ [7 d #include "stm32f0xx_hal.h"1 J! V3 a; K2 n /* USER CODE BEGIN Includes */! ]% |3 ?6 I% v5 l- [$ ^ f6 Z ! \) ~! ]9 ?5 J9 ~ /* USER CODE END Includes */3 p+ l. ?* f" ~2 N' i7 ^9 @ /* Private variables ---------------------------------------------------------*/ ; P3 m% G$ {' z a; q2 L( e /* USER CODE BEGIN PV */, ^1 D9 j# Q: V5 Y$ V- I /* USER CODE END PV */4 |% M0 `3 M' b$ E, m0 M# E ' B2 H' P& N: \. D6 Z, K4 y, [ /* Private function prototypes -----------------------------------------------*/7 Q6 m# l5 P2 e3 J4 v' t void SystemClock_Config(void); static void MX_GPIO_Init(void);0 z j+ H/ Y9 X1 f& e6 x6 D- } /* USER CODE BEGIN PFP */ * x+ _7 N" J! ?2 c8 h3 V% f) O /* USER CODE END PFP */! y5 n* s/ G0 z- Q /* USER CODE BEGIN 0 */, j# Y& ]% e9 }1 M" l, b + p3 M. K& g' C) e9 e& S' e0 q /* USER CODE END 0 */ int main(void)# i2 \; D& i6 V5 I' x( h! i {+ k* o% F, s- c T + C5 I( X! s8 z& E /* USER CODE BEGIN 1 */1 G' C+ l7 z; S6 C2 m /* USER CODE END 1 */8 y+ U& f8 y$ f /* MCU Configuration----------------------------------------------------------*/& D) {* W9 ?9 N : L; r" x! m, i. v3 v3 y- z /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init();; f6 ?& {# w2 W* W2 W * R8 [% m3 q6 K" H4 T# l# Z /* Configure the system clock */ SystemClock_Config(); a: E; {# a) v2 [3 [* W /* Initialize all configured peripherals */0 S# Q' b' e3 t6 R MX_GPIO_Init();# i1 n( U0 b$ C0 Q /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* USER CODE BEGIN 3 */ /* Infinite loop */ while (1)( c; W1 W5 i' z6 |" x {# y0 c+ u' u) {: b" N% U5 V HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_SET);5 ?8 d, o9 x: L9 w HAL_Delay(500);1 |; W. E6 G" n/ L; D& v HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_RESET);* s; e; ~, d3 f! q$ e" { HAL_Delay(500);/ r8 C: _& b8 w" q7 ] } /* USER CODE END 3 */ }7 C9 C* R6 {( V4 Y /** System Clock Configuration7 n$ P+ S! R @( N */6 ~" |# @$ f) j, O r void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct; RCC_ClkInitTypeDef RCC_ClkInitStruct;( ~, I" d8 y7 F: ?- p3 @0 m $ T" `2 C" T5 v) w8 T RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;: C2 p* s/ z: x! |: h1 q RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = 16;, ]9 B( y) {# h6 ~ RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;; h, o4 p8 H3 Z1 c5 U. w7 e4 N HAL_RCC_OscConfig(&RCC_OscInitStruct); }) M4 M' ?5 W6 U, {$ p6 C RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;( ^5 Z. g# v4 m) }/ Y8 E7 z RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;. ~9 Q* i- ~# E HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0); __SYSCFG_CLK_ENABLE(); 5 }* u# u3 u1 v- o' u0 \0 T }, }# X3 ?1 ]- g" z4 L X$ X5 e+ K: Z0 W* d /** Configure pins as * Analog * Input * Output. Q$ [, G9 b: d ~" U * EVENT_OUT! q1 _0 A7 @8 I) Z+ c$ s# p * EXTI1 a4 U9 b V) w5 B% X1 c& C5 I2 U% r */9 ?! E. s, Q% W) n& P2 I! v void MX_GPIO_Init(void)$ [7 U8 E: {% d9 a- f* ~$ I { 3 N" Z5 G2 D# f- {& t+ } L GPIO_InitTypeDef GPIO_InitStruct; /* GPIO Ports Clock Enable */ __GPIOA_CLK_ENABLE();1 A" Y3 O4 y' c% F4 M% r% H 2 ~9 o: g) N7 d- O7 u9 l /*Configure GPIO pin : PA5 */5 y3 n+ H' m$ U: y GPIO_InitStruct.Pin = GPIO_PIN_5; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;+ ? ~. r) ]0 v GPIO_InitStruct.Pull = GPIO_NOPULL;/ q/ X* X- h% j# B5 I: }: ]7 C( D GPIO_InitStruct.Speed = GPIO_SPEED_LOW;) Z" U$ [( f. C$ y, f: K8 M- _ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);8 Y: m9 r- M% J b7 j% X$ M3 w } 6 o! g! ]: x. ?* n8 l4 C4 D k) n /* USER CODE BEGIN 4 */% z3 r0 }! Z* I3 {' x% H ) p; Q3 h. B% w /* USER CODE END 4 */$ k& x. W9 J$ J/ O+ k& m, b #ifdef USE_FULL_ASSERT /**3 ^: G# M% `2 O. z: E) m0 y * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred.0 O+ X, u* O6 i! N * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */# W6 S+ ^$ C) n0 b5 _/ g k void assert_failed(uint8_t* file, uint32_t line) {( ]( V( b$ j, i. V5 t /* 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) */ /* USER CODE END 6 */ } " e& ?; |2 n8 {1 w1 ^ #endif3 V0 ^9 Q# U7 c 9 k3 f8 ~, I4 Q+ Q /** * @} g: ~: Y/ A8 f3 ~- o9 u' P2 C */ /**( I/ E& h1 H9 B6 ^ * @} */ ( S2 q( c; a. F6 J /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ $ }8 J& U0 q2 o# B/ s5 j9 ~ - K$ Q' U1 p2 P) l- F 7 k7 K% k" |: L+ C+ c- [; ?3 _1 \! z |
谢谢~通常来说,下一步就是按键了![]() ![]() |
是啊 按套路来![]() |