开发板到了,先点个灯吧,使用STM32CUBEMX,对HAL库还不是很熟悉,才开始还走了一点弯路,不知道HAL_GPIO_WritePin()函数如何设置,后来发现原来在这里,
以下是main()函数,总体感觉HAL库还是很好用的,要是有更详细的文档说明就更好了。 /**7 s1 E" y) a5 R9 i/ c ******************************************************************************- P+ }; ~+ [8 E) C" B * File Name : main.c3 z; G% i1 V8 x * Date : 25/12/2014 16:24:54; P2 F9 f$ D6 D* f9 D/ ~( S# j * Description : Main program body ******************************************************************************6 ] _+ U+ z1 q: A1 r *+ W. U3 d6 O2 m4 c) M9 o! Q * COPYRIGHT(c) 2014 STMicroelectronics3 l; g# O% ~" d/ s) M * * 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,; D' b1 A3 e! }# } * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice,. X- _* C5 {6 n! `- v* p% F * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution." I# ?! l, Z- v, W1 D, o * 3. Neither the name of STMicroelectronics nor the names of its contributors) _* Y1 a) A$ B9 z% u * may be used to endorse or promote products derived from this software * 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 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE4 @8 a2 B: s! x* A, B A; s: f+ ?! n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * 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,7 n& C8 i# E5 o6 | * 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. Z& b* v# K$ `! ~9 i' U+ ] * ******************************************************************************, } ^- h( _ ~5 D* k- e */) w) K* k, ]( N# f s( n0 ~ * X+ f) M. i# N/ o /* Includes ------------------------------------------------------------------*/4 F+ u6 c# l+ Q3 S& t' \4 I2 B9 \ #include "stm32f0xx_hal.h"/ U9 U6 _4 m" B% }$ n* S# h /* USER CODE BEGIN Includes */. N3 s8 I) K0 q /* USER CODE END Includes */ /* Private variables ---------------------------------------------------------*/: L! X, K% ?9 s% b /* USER CODE BEGIN PV */0 H! s6 r! L6 {; f + b1 C: t5 \, l& v+ y /* USER CODE END PV */+ g' n ~& p h p /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* USER CODE BEGIN 0 */ x$ O* x: @9 H6 O# W9 h6 { /* USER CODE END 0 */ ) t0 W* X A9 r. N' Y) c int main(void) { + U4 O) p; Z4 r% q; z7 R$ ]4 |4 _5 [0 F /* USER CODE BEGIN 1 */ + l* y7 Y$ b* G; ^ /* USER CODE END 1 */ $ s( A8 g: m, Y2 S. Z/ a /* MCU Configuration----------------------------------------------------------*/ . D" R1 M$ u* _/ g5 x& Y, X /* Reset of all peripherals, Initializes the Flash interface and the Systick. */+ i) i; T5 H6 I HAL_Init(); /* Configure the system clock */) f: Q* d/ h/ l; D$ V; R6 X% a SystemClock_Config(); /* Initialize all configured peripherals */; S. p. r: h* e; P- q% ]( ^ MX_GPIO_Init(); 7 N) Y1 ^) `- }& }+ J- w7 _8 L /* USER CODE BEGIN 2 */9 {' R" t/ e; K2 t0 a G 9 r9 Y8 m5 N. e$ {( c /* USER CODE END 2 *// I" |* E j8 F$ b0 k) d9 Q2 ` 8 F# I r) U4 t% I0 O$ K /* USER CODE BEGIN 3 */ /* Infinite loop */ while (1) { HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_SET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_RESET);& h1 N; n0 d5 w P. ?, E, w8 c) _ HAL_Delay(500);6 c3 l/ Z% e* g) N+ W0 v& Z } /* USER CODE END 3 */ , g4 I% n5 \4 ?! R2 `; x) v/ W } /** System Clock Configuration8 T9 }8 R& W# a3 h1 b$ V */! ^" M' R8 Q( I2 Q+ n void SystemClock_Config(void) {6 Z1 c+ h* ]/ i: W1 g8 c 3 x, J' B' m+ w3 X RCC_OscInitTypeDef RCC_OscInitStruct; RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;; }+ x4 T# b) Q2 V7 I RCC_OscInitStruct.HSIState = RCC_HSI_ON;5 J' Q3 a% \- t! s4 E# ~+ g# A RCC_OscInitStruct.HSICalibrationValue = 16;$ `) e0 H5 d% T RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;* q2 g0 Z- X5 M$ m3 X' H/ V7 [# h1 { HAL_RCC_OscConfig(&RCC_OscInitStruct); D- J1 V- z" f$ E. j, A8 H+ ? j RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; n! F Z- o: n% K) k RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;# s( _2 e3 k1 X- z$ U! ^ RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0); 9 k) F3 n9 B# l/ d __SYSCFG_CLK_ENABLE(); } /** Configure pins as % C% E2 s" V, w6 f* J+ z) v * Analog * Input 7 Z! X* O8 ]7 g. U * Output * EVENT_OUT6 u. S: z3 `$ D * EXTI0 s) e8 J; v! B1 U6 U5 t' F */$ H% ^7 ?& Q9 H& k$ g void MX_GPIO_Init(void)! N; |. L, v% ]$ G; c {( {; U4 V6 e @# v 5 Q" I( d: p C- R6 c6 l- u! e GPIO_InitTypeDef GPIO_InitStruct; 0 P8 O5 S6 Q6 y$ Z /* GPIO Ports Clock Enable */ __GPIOA_CLK_ENABLE(); & ^! @4 u# N' Y( i* [$ k% ^) A /*Configure GPIO pin : PA5 */8 u5 g, h8 Z) ~$ u. ] GPIO_InitStruct.Pin = GPIO_PIN_5;0 Z7 f5 C t: t/ _' f* L$ w GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL;8 J1 x$ K: [5 T5 Z+ U GPIO_InitStruct.Speed = GPIO_SPEED_LOW;' C7 I& W5 ]& m HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);' @/ `+ t8 p) z* s }0 x( x; L0 s; \ /* USER CODE BEGIN 4 */ /* USER CODE END 4 */ 9 \+ B9 ^9 M( O4 g- E #ifdef USE_FULL_ASSERT /**' Q4 ?9 Q, U, {# C, m9 g * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred.1 ` l& K4 d/ N * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */7 Y* _" D- k: L1 V void assert_failed(uint8_t* file, uint32_t line) { /* 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 */ 9 L: Y; L/ F: x7 |, W0 F }: _, Q% D2 |6 v% u 0 r2 Q: t0 h! ^! j3 E# Y4 g) T #endif /**- R4 A/ ?6 H3 O( |& q( Q * @}! W% I! m/ L. j/ _0 o5 y' i$ M */ + O$ ^) D! s/ {. u+ q: g ~ + K0 ` o/ C' X! W! A /** * @}; t B: N# }, U0 h- @; K* C0 c */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/# r$ }. i: V' }7 P + F( W; T- U4 d7 G |
谢谢~通常来说,下一步就是按键了![]() |
是啊 按套路来 |
DMA 原理从 0 到 1:为什么它能解放 CPU?一文讲透 DMA 的工作流程
小白也能明白的STM32的低功耗与唤醒机制
STM32系统中2种数据掉电保护的方法
分享STM32F051中文参考手册(重制书签版)
AI工具训练营-用ChatGPT解决HID Keyboard实现的问题
STM32固件库分享,超全系列整理
STM32小白入门指南:从基础到OTA实现方案
STM32超详细学习笔记
新手必看!STM32单片机应该怎么学?
如果你解决了这些问题,就可以直接学STM32
微信公众号
手机版