STM32开发板学习笔记【2】STM32F407IGTx实验--跑马灯.pdf

上传人:小*** 文档编号:83415429 上传时间:2023-03-30 格式:PDF 页数:9 大小:1.78MB
返回 下载 相关 举报
STM32开发板学习笔记【2】STM32F407IGTx实验--跑马灯.pdf_第1页
第1页 / 共9页
STM32开发板学习笔记【2】STM32F407IGTx实验--跑马灯.pdf_第2页
第2页 / 共9页
点击查看更多>>
资源描述

《STM32开发板学习笔记【2】STM32F407IGTx实验--跑马灯.pdf》由会员分享,可在线阅读,更多相关《STM32开发板学习笔记【2】STM32F407IGTx实验--跑马灯.pdf(9页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、STM32开发板学习笔记【2】STM32F407IGTx实验-跑马灯1.跑马灯实验只要是对硬件操作,就要先查看原理图。查看外设是给模块的 MCU 的哪个引脚相连。FS-STM32F407开发平台上的 LED 的亮灭状态,与芯上的引脚 I/O 输出电平有关。1.配置STM32cube将4个LED管脚设置为输出模式 点击 CLOCK CONFIGURATION 对时钟进设置 点击成程按钮 打开uv项件 往开发板下载程序单击具栏中 Build Target图标可编译链接程件。如果源程序中存在语法错误,Vision 则会在Output Window-Build 窗中显出错误和警告信息。双击提信息所在,

2、就会在Vision编辑窗打开并显相应的出错源件,光标会定位在该件的出错上,以便户快速定位出错位置。编译和链接显没有错误:下载程序拨码开关接法:boot0 和 boot1 接法决定了芯启动式和从那部分存储介质启动。BOOT1=x,BOOT0=0 从户闪存启动,这是正常的作模式。BOOT1=0,BOOT0=1 从系统存储器启动,这种模式启动的程序功能由家设置。BOOT1=1,BOOT0=1 从内置 SRAM 启动,这种模式可以于调试。这下载前先将 boot0,boot1 拨到 0 状态:如下图 打开程配置,选择 Debug,勾选 Use,选择仿真具为 ST-Link Debugger,点击 Set

3、ting Vision IDE 调试器提供了软件仿真和 GDI 驱动两种调试模式,采 ST-Link 仿真器调试时,先将集成环境与 ST-Link 仿真器连接,按照前的程基本配置法对要调试的程进配置后,点击 Flash-Download 菜单项(或者点击按钮)可将标件下载到标系统的指定存储区中,件下载后(按 复位键可以看到 LED 灯亮起)即可进在线仿真调试。下载完毕后发现很神奇!说好的跑马灯为什么跑不起来,灯直亮着,这是因为编译链接之前没有修改main.C中的代码,详细代码如下:/*File Name :main.c *Description :Main program body *COPY

4、RIGHT(c)2020 STMicroelectronics *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,*this list of conditions and the following disclaimer

5、.*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.*3.Neither the name of STMicroelectronics nor the names of its contributors *may be used to e

6、ndorse 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

7、 PARTICULAR PURPOSE ARE *DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE *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 INTER

8、RUPTION)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.*/*Includes-*/#include main.h#include stm32f4xx_hal.h#include g

9、pio.h/*USER CODE BEGIN Includes*/*USER CODE END Includes*/*Private variables-*/*USER CODE BEGIN PV*/*Private variables-*/*USER CODE END PV*/*Private function prototypes-*/void SystemClock_Config(void);void Error_Handler(void);/*USER CODE BEGIN PFP*/*Private function prototypes-*/void Turn_On_LED(uin

10、t8_t LED_NUM);/*USER CODE END PFP*/*USER CODE BEGIN 0*/*USER CODE END 0*/int main(void)/*USER CODE BEGIN 1*/uint8_t count=0;/*USER CODE END 1*/*MCU Configuration-*/*Reset of all peripherals,Initializes the Flash interface and the Systick.*/HAL_Init();/*Configure the system clock*/SystemClock_Config(

11、);/*Initialize all configured peripherals*/MX_GPIO_Init();/*USER CODE BEGIN 2*/*USER CODE END 2*/*Infinite loop*/*USER CODE BEGIN WHILE*/while(1)/*USER CODE END WHILE*/*USER CODE BEGIN 3*/HAL_GPIO_WritePin(GPIOF,GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10,GPIO_PIN_SET);Turn_On_LED(count%4);count+;H

12、AL_Delay(500);/*USER CODE END 3*/*System Clock Configuration*/void SystemClock_Config(void)RCC_OscInitTypeDef RCC_OscInitStruct;RCC_ClkInitTypeDef RCC_ClkInitStruct;/*Configure the main internal regulator output voltage */_HAL_RCC_PWR_CLK_ENABLE();_HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE

13、_SCALE1);/*Initializes the CPU,AHB and APB busses clocks */RCC_OscInitStruct.OscillatorType=RCC_OSCILLATORTYPE_HSE;RCC_OscInitStruct.HSEState=RCC_HSE_ON;RCC_OscInitStruct.PLL.PLLState=RCC_PLL_ON;RCC_OscInitStruct.PLL.PLLSource=RCC_PLLSOURCE_HSE;RCC_OscInitStruct.PLL.PLLM=25;RCC_OscInitStruct.PLL.PLL

14、N=336;RCC_OscInitStruct.PLL.PLLP=RCC_PLLP_DIV2;RCC_OscInitStruct.PLL.PLLQ=4;if(HAL_RCC_OscConfig(&RCC_OscInitStruct)!=HAL_OK)Error_Handler();/*Initializes the CPU,AHB and APB busses clocks */RCC_ClkInitStruct.ClockType=RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;R

15、CC_ClkInitStruct.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK;RCC_ClkInitStruct.AHBCLKDivider=RCC_SYSCLK_DIV1;RCC_ClkInitStruct.APB1CLKDivider=RCC_HCLK_DIV4;RCC_ClkInitStruct.APB2CLKDivider=RCC_HCLK_DIV4;if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct,FLASH_LATENCY_5)!=HAL_OK)Error_Handler();/*Configure the Systi

16、ck interrupt time */HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);/*Configure the Systick */HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);/*SysTick_IRQn interrupt configuration*/HAL_NVIC_SetPriority(SysTick_IRQn,0,0);/*USER CODE BEGIN 4*/void Turn_On_LED(uint8_t LED_NUM)switch(LED_NUM)case 0:

17、HAL_GPIO_WritePin(GPIOF,GPIO_PIN_7,GPIO_PIN_RESET);break;case 1:HAL_GPIO_WritePin(GPIOF,GPIO_PIN_8,GPIO_PIN_RESET);break;case 2:case 2:HAL_GPIO_WritePin(GPIOF,GPIO_PIN_9,GPIO_PIN_RESET);break;case 3:HAL_GPIO_WritePin(GPIOF,GPIO_PIN_10,GPIO_PIN_RESET);break;default:break;/*USER CODE END 4*/*brief Thi

18、s function is executed in case of error occurrence.*param None *retval None */void Error_Handler(void)/*USER CODE BEGIN Error_Handler*/*User can add his own implementation to report the HAL error return state*/while(1)/*USER CODE END Error_Handler*/#ifdef USE_FULL_ASSERT/*brief Reports the name of t

19、he source file and the source line number *where the assert_param error has occurred.*param file:pointer to the source file name *param line:assert_param error line source number *retval None */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%drn,file,line)*/*USER CODE END 6*/#endif/*/*/*(C)COPYRIGHT STMicroelectronics*END OF FILE*/

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 技术资料 > 技术方案

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁