开发板到了,先点个灯吧,使用STM32CUBEMX,对HAL库还不是很熟悉,才开始还走了一点弯路,不知道HAL_GPIO_WritePin()函数如何设置,后来发现原来在这里,
以下是main()函数,总体感觉HAL库还是很好用的,要是有更详细的文档说明就更好了。 /** ****************************************************************************** * File Name : main.c( C D5 ^9 ]2 W. }* g5 I* N. y * Date : 25/12/2014 16:24:54 * Description : Main program body ******************************************************************************3 [2 |6 \) T( a4 s/ l: L) C, k * * COPYRIGHT(c) 2014 STMicroelectronics *+ a. O" R5 |8 [- [ * 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,7 ]; w1 j a1 M+ D( |" f- i9 m * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice,& V) N, L7 o$ `! C- k- ~ * this list of conditions and the following disclaimer in the documentation& F+ H; r9 f4 j * and/or other materials provided with the distribution.% z& e0 _5 L Z% V$ v7 { * 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. * v3 U2 x$ J6 D# m% {' m& ~# z * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE& X: v# F$ Z$ i' a {! X% d+ }. k * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE% {8 g3 t+ Z6 b" c8 g- t$ y% R * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL3 A) ~; `9 {* U% B+ x * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER G: b- C! v7 `! `5 b * 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.6 a* G" Q3 J& C1 x6 J *5 x- n% x- [- U ******************************************************************************3 ?9 A4 b, R F# Z7 ?, ` */" N& I! V7 D( ?$ ^- x, U+ l! G& t /* Includes ------------------------------------------------------------------*/ #include "stm32f0xx_hal.h"& B' I3 [' `( j: G ; l5 q% K1 w5 S1 M J' d) Z/ t z /* USER CODE BEGIN Includes */; e7 M% J3 K2 ]2 F , ^ A6 K u. p% U" U; g5 d( `/ Y" C /* USER CODE END Includes */ /* Private variables ---------------------------------------------------------*/9 q& \2 G' V7 H* p. ^% p$ c, Y$ l - [1 i9 L4 f% W9 s, H- b9 a' F /* USER CODE BEGIN PV */ /* USER CODE END PV */ 4 a) H ~5 ]; O* r, |) @ /* Private function prototypes -----------------------------------------------*/9 G& F; Y! ^$ P3 T6 Z! o; n* w void SystemClock_Config(void); static void MX_GPIO_Init(void);# k* R# w" [5 K1 ~% f M , S3 H% N) |: n/ V3 d, C$ B /* USER CODE BEGIN PFP */8 l3 W5 c- Z. H6 u" } /* USER CODE END PFP */ /* USER CODE BEGIN 0 */ 1 y8 ^$ D r+ b3 K K1 ` /* USER CODE END 0 */! K5 K: A* f! {: {9 T" T6 h, l# n int main(void)1 W) P: k) T, l7 v5 d# c1 P; v9 { { /* USER CODE BEGIN 1 */' Q+ F, P9 x) v& u) t+ u /* USER CODE END 1 */9 z! ]1 X" m7 h, S; v /* MCU Configuration----------------------------------------------------------*/6 }7 `2 _5 n" e3 C8 k1 c& ?$ g ; q. R# h# n& q& t. y( |$ l /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); . q m+ [: d8 G1 |. k /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init();9 K, N4 x2 Q! e9 l & W3 {$ S6 P( v9 O* l& F3 h5 e9 l /* USER CODE BEGIN 2 */ ! K: M; Y5 C$ b. K- q- W/ T- {! h; {, g /* USER CODE END 2 */7 j1 u- a0 I- S1 D$ M! C! y 2 }( F4 l* l9 V" ^. v /* USER CODE BEGIN 3 */ /* Infinite loop */ while (1) {: |( t6 E; A8 o: h; Z" [7 y: G8 v HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_SET);2 y: ~3 x" {( A HAL_Delay(500);' X8 a4 M8 q! B$ `9 J# y7 r# O" G HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_RESET);/ _% g* R, d& d) c& G. D5 o HAL_Delay(500);2 n$ v3 M, W% O } /* USER CODE END 3 */% q; r0 c* w% @# T }1 \9 M9 U! |( p( D /** System Clock Configuration */ void SystemClock_Config(void) { % L# e4 E7 f9 h. Z RCC_OscInitTypeDef RCC_OscInitStruct; RCC_ClkInitTypeDef RCC_ClkInitStruct;- h$ s! K0 `$ A: B 1 i, u8 G8 \0 i, B RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;: k5 T3 Q+ L r7 G- f+ H- I) ` RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = 16;8 O# E( U# m9 f, O3 V# n RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; HAL_RCC_OscConfig(&RCC_OscInitStruct); + F# m/ N; Q* c& l+ `/ V7 Y' j RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;' r3 J h' R4 ]( A5 J RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;" R9 t3 ^" N2 Z9 N" V3 F RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;' B# G: y- ]4 Q+ H$ o9 } RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;7 w# N0 C, C& X HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0); 8 a9 d# g5 V) @# i& f# X1 b |0 X __SYSCFG_CLK_ENABLE();( P! P$ s I- C4 a5 d1 \& D ! Z6 o6 Z6 A' V! r } /** Configure pins as - J" S1 [/ x5 e( ?2 G( I) c3 m * Analog * Input * Output * EVENT_OUT! e" Y! U; Y9 e * EXTI */" B2 w$ x6 o6 D& R8 D- I1 @5 ~ void MX_GPIO_Init(void) {' \ O4 t3 j0 i R$ r$ q& m ! o% \$ g, }; x2 B' s E! u GPIO_InitTypeDef GPIO_InitStruct;5 A' t4 b: _) b* o1 b / R# K3 {, z6 g) F3 O0 B /* GPIO Ports Clock Enable */) O \4 _8 W7 Z, \' P, V __GPIOA_CLK_ENABLE(); 4 _8 X+ {' E" ?, w: Y, W, |- X /*Configure GPIO pin : PA5 */% x7 Q/ D# k! ]" A( i2 ` GPIO_InitStruct.Pin = GPIO_PIN_5; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;% V% d; D9 R. H& m, H* n GPIO_InitStruct.Pull = GPIO_NOPULL;1 W* |% q" X$ P/ a- X g GPIO_InitStruct.Speed = GPIO_SPEED_LOW; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);, o! r- H: L. u/ q2 w + t) c. n; \7 ? } / `( e) \( O, V d /* USER CODE BEGIN 4 */ /* USER CODE END 4 */ 7 f& z2 S7 `, M: |! ^3 `$ b$ z7 F #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred.% A. H; t0 F$ U * @param file: pointer to the source file name * @param line: assert_param error line source number2 i) a$ d" r* b8 W a * @retval None3 J, ?2 u% l2 h! h/ R3 V* F */' F9 A1 m3 ^7 I. x2 w) S void assert_failed(uint8_t* file, uint32_t line) {, m# R$ M5 P# o* j% a5 g2 Y+ n /* USER CODE BEGIN 6 */0 Q+ T# i( W' ~# B0 m2 T /* 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 */( `0 F; P( o/ T/ c. X% M }2 \. `- I5 w+ R+ s- U: b" u $ z2 a6 i; @/ } #endif* f% D8 }9 H" [' P9 ~- \7 B /** * @}. d8 O- R& j9 Y+ I W3 @& Y& \ */ /**5 f8 M, g0 z6 `/ e# |7 D4 L * @}+ c7 _ @3 [1 F3 u */ 7 f2 F6 I- m5 H* F* x# o /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 4 M7 ?) f. E8 Q* C + u4 x: V/ m3 w% `6 h |
谢谢~通常来说,下一步就是按键了![]() |
是啊 按套路来 |
DMA 原理从 0 到 1:为什么它能解放 CPU?一文讲透 DMA 的工作流程
小白也能明白的STM32的低功耗与唤醒机制
STM32系统中2种数据掉电保护的方法
分享STM32F051中文参考手册(重制书签版)
AI工具训练营-用ChatGPT解决HID Keyboard实现的问题
STM32固件库分享,超全系列整理
STM32小白入门指南:从基础到OTA实现方案
STM32超详细学习笔记
新手必看!STM32单片机应该怎么学?
如果你解决了这些问题,就可以直接学STM32
微信公众号
手机版