
开发板到了,先点个灯吧,使用STM32CUBEMX,对HAL库还不是很熟悉,才开始还走了一点弯路,不知道HAL_GPIO_WritePin()函数如何设置,后来发现原来在这里,
![]() 以下是main()函数,总体感觉HAL库还是很好用的,要是有更详细的文档说明就更好了。 /** ****************************************************************************** * File Name : main.c4 [ I) Q6 k" F9 c * Date : 25/12/2014 16:24:54 * Description : Main program body ****************************************************************************** *$ W- E- I6 g4 Z7 M2 {3 y4 _ * COPYRIGHT(c) 2014 STMicroelectronics5 C; k9 v |6 M9 r * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met:" a' B+ F5 f/ q5 O& K* c* ^* A * 1. Redistributions of source code must retain the above copyright notice,9 l1 v. ~% M* F# U1 Z) ^5 A) Y% C * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation4 M- K- @. d2 q5 H5 h. w' e8 \ * and/or other materials provided with the distribution.3 o. w) U# k, w" N# ] * 3. Neither the name of STMicroelectronics nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission.3 U4 |; z. L% i$ B *( \) H$ |, H; m5 d' @ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"& O6 f0 H+ n! Z8 r" n * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE* J3 N4 Z) O4 U * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL9 g3 e, K1 }, r3 q9 _' Z4 [ * 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,/ Q5 }1 L7 a# V8 W0 t" n * 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.) B5 z7 D D* T5 Z3 D+ ?* K$ J# u# C# l * ****************************************************************************** */! e" y* _6 I3 O 5 J9 I5 [+ Y+ r8 m8 Y /* Includes ------------------------------------------------------------------*/9 ^3 j5 g# b3 ]& c: y #include "stm32f0xx_hal.h"6 w7 f; L7 P' _$ Q' v4 ? ) Y: N* J6 N3 I3 L9 B$ {! d+ z2 i /* USER CODE BEGIN Includes */! c% V" _! @2 O; ?; H" T+ I) p ' s% x: c1 p: X K9 l /* USER CODE END Includes */ /* Private variables ---------------------------------------------------------*/ , T9 R0 {9 ~2 c5 ]% s) ?4 D /* USER CODE BEGIN PV */ 2 m4 d. R; A* J: J! V: W$ y /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/( u: K0 y3 N! X void SystemClock_Config(void); static void MX_GPIO_Init(void);+ t2 F! }( F! `: a8 L/ n4 [/ g" o /* USER CODE BEGIN PFP */ ! Q2 y8 t$ I2 ^2 B, L) d /* USER CODE END PFP */ /* USER CODE BEGIN 0 */ m4 n9 s0 l8 g/ M$ o% R B( h R$ J; V1 D /* USER CODE END 0 */ ' \1 `% R) T: r1 t; R6 R; O int main(void)) y( i+ T M8 O W; x# V5 c9 m { l' g" v0 W+ T8 T$ t* i6 c& ] & {2 \5 R. Y1 G7 J, u /* USER CODE BEGIN 1 */6 {2 H9 P5 `8 Q! }* W 3 ~$ G5 X. w" X6 ^$ {. ~) i /* USER CODE END 1 */ - G& V+ l. r* B: _' C /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init();4 E% j( ~: {3 V& k! I8 T ( x+ Q' n' p: C1 m5 {# d2 ~% W' t$ p /* Configure the system clock */ SystemClock_Config(); y; J/ `# b, q' _ /* Initialize all configured peripherals */# t0 T: \9 \+ d( v MX_GPIO_Init(); /* USER CODE BEGIN 2 */ . ~- |4 H' k/ f ~$ h [7 x$ }4 {$ q/ W /* USER CODE END 2 */% `; x+ Y( Z# G3 @! |; y2 ~& B3 ? /* USER CODE BEGIN 3 */ /* Infinite loop */, {7 H7 i0 m+ T" y* j6 \ while (1)7 \$ h+ E/ D5 [2 v4 M; r {+ T+ U5 ?0 l& E/ m- f W) D HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_SET);# q2 o( y X8 p9 G HAL_Delay(500); HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_RESET); HAL_Delay(500);( L" h+ r! G! Z0 N }1 m! ?* V% Q5 B6 x9 c /* USER CODE END 3 */ }* u& u b+ l( ^0 w% W& T /** System Clock Configuration# q# a9 c; T! _ */ {2 ]+ N$ V2 Y- Z) s2 C void SystemClock_Config(void) { - g1 t! ~1 T6 o5 U$ a RCC_OscInitTypeDef RCC_OscInitStruct; RCC_ClkInitTypeDef RCC_ClkInitStruct;4 J+ ~2 w3 \- J6 ?( ~ $ \9 t0 J+ T# X: ~3 U n. H( e& N RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;+ g% \6 l" r9 X1 O% x8 l6 ]) x- M RCC_OscInitStruct.HSIState = RCC_HSI_ON;' w# O5 i3 `( @% w5 R7 V4 n$ I RCC_OscInitStruct.HSICalibrationValue = 16; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;2 D* ~0 t |/ J) x+ f3 r HAL_RCC_OscConfig(&RCC_OscInitStruct); , ^4 d k* z/ H6 t' a RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;& P4 p4 [% j8 W RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);( n6 w- D/ t% U" a2 o 0 o7 P0 o$ {6 E __SYSCFG_CLK_ENABLE(); ' t0 T; P2 u* E7 A4 W" L }7 }' N% |7 C+ G" p /** Configure pins as * Analog * Input ' l9 T& T: v! X1 f * Output# Q w# ? U. w/ L7 H9 u; a * EVENT_OUT6 t& x! A) ^( D% M, R9 ?7 J9 l# ~ * EXTI3 [. \3 [+ D$ s. ~0 A, }; ] */ void MX_GPIO_Init(void)+ P5 x; H9 }) N" K8 \ L: Q/ M+ e) I { ! j" K% \/ u2 U/ N* h GPIO_InitTypeDef GPIO_InitStruct;+ }0 @6 U8 k" w0 {5 s8 O /* GPIO Ports Clock Enable */2 I/ @9 _4 r) s" B0 h# N __GPIOA_CLK_ENABLE(); /*Configure GPIO pin : PA5 */) K; A) ]" ^& \/ Z; h GPIO_InitStruct.Pin = GPIO_PIN_5; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; L& \) p3 g/ c GPIO_InitStruct.Pull = GPIO_NOPULL;# [" H9 K2 j0 W! U. d6 q GPIO_InitStruct.Speed = GPIO_SPEED_LOW;5 p& a+ `9 ~( G# L7 u8 f HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); } 6 Z i# _! o/ t /* USER CODE BEGIN 4 */% K1 m# E2 c! E- m1 k /* USER CODE END 4 */ ) j/ M* a8 I8 t) X x) `% B/ V #ifdef USE_FULL_ASSERT /**, V; j7 C6 y; O3 K T * @brief Reports the name of the source file and the source line number" v/ ^! G( z, b( s1 j * where the assert_param error has occurred.1 ~) B2 n9 T$ z * @param file: pointer to the source file name( Y e5 y4 f. ^1 e. e * @param line: assert_param error line source number * @retval None */; t/ E% v$ M) t; L9 @+ `$ o* p void assert_failed(uint8_t* file, uint32_t line)# n* A/ }6 ?. B5 D { /* 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) */( p- e- F* b J! r. ? /* USER CODE END 6 */ } % J" S: F8 R( w& l1 X" j7 c% q& ~ #endif$ `# i+ n" _' W+ k /** * @}( x3 H* E; }8 c8 k2 g& ~ */ ! I) x& k/ x7 j9 s /** * @} */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ % u8 [ S- l5 G1 `! F9 h |
谢谢~通常来说,下一步就是按键了![]() ![]() |
是啊 按套路来![]() |