已阅读5页,还剩21页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
ARM笔记目录名词解释2基于MDK的STM32处理器开发应用李宁 笔记3程序示例3主函数3RCC:系统时钟、PLL、GPIO时钟设置6NVIC:中断向量位置(flash、ram)、中断的配置8GPIO11SysTick函数和Delay函数13EXTI:外部中断/事件控制器16中断服务函数17USART18碰到的问题20知识点22关于stm3222关于启动文件 .s24关于库函数STM32F10xR.LIB25THE END26名词解释NVIC:异常处理基于MDK的STM32处理器开发应用李宁 笔记程序示例主函数/* File Name : main.c* Author : Wuhan R&D Center, Embest* Date First Issued : 08/08/2008* Description : Main program body*/* Includes -*/#include stm32f10x_lib.h/* Private typedef -*/* Private define -*/* Private macro -*/* Private variables -*/#define ADC1_DR_Address (u32)0x4001244C)unsigned short int ADC_ConvertedValue;GPIO_InitTypeDef GPIO_InitStructure;ADC_InitTypeDef ADC_InitStructure;DMA_InitTypeDef DMA_InitStructure;EXTI_InitTypeDef EXTI_InitStructure;ErrorStatus HSEStartUpStatus;extern vu32 TimingDelay;/* Private function prototypes -*/void RCC_Configuration(void);void NVIC_Configuration(void);void GPIO_Configuration(void);void Delay(vu32 nTime);void SysTick_Configuration(void);void SetupLED (void) ;extern void SetupADC (void);/* Private functions -*/* Function Name : main* Description : Main program.* Input : None* Output : None* Return : None*/int main(void)#ifdef DEBUG debug();#endif /* Configure the system clocks */ RCC_Configuration(); SysTick_Configuration(); /* NVIC Configuration */ NVIC_Configuration(); /* Configure the GPIO ports */ GPIO_Configuration(); /* Connect EXTI Line9 to PB.9 */ GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9); /* Configure EXTI Line9 to generate an interrupt on falling edge */ EXTI_InitStructure.EXTI_Line = EXTI_Line9; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); for(;) GPIOC-ODR = 0xfffffc4f;Delay(800);GPIOC-ODR = 0xfffffc8f;Delay(800);GPIOC-ODR = 0xfffffd0f;Delay(800);GPIOC-ODR = 0xfffffe0f;Delay(800); RCC:系统时钟、PLL、GPIO时钟设置/* Function Name : RCC_Configuration* Description : Configures the different system clocks.* Input : None* Output : None* Return : None*/void RCC_Configuration(void) /* RCC system reset(for debug purpose) */ RCC_DeInit(); /* Enable HSE */ RCC_HSEConfig(RCC_HSE_ON); /* Wait till HSE is ready */ HSEStartUpStatus = RCC_WaitForHSEStartUp(); if(HSEStartUpStatus = SUCCESS) /* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK/2 */ RCC_PCLK1Config(RCC_HCLK_Div2); /* Flash 2 wait state */ FLASH_SetLatency(FLASH_Latency_2); /* Enable Prefetch Buffer */ FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); /* PLLCLK = 8MHz * 9 = 72 MHz */ RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); /* Enable PLL */ RCC_PLLCmd(ENABLE); /* Wait till PLL is ready */ while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) = RESET) /* Select PLL as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); /* Wait till PLL is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x08) /* Enable GPIOB, GPIOC and AFIO clocks */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE);NVIC:中断向量位置(flash、ram)、中断的配置/* Function Name : NVIC_Configuration* Description : Configures Vector Table base location.* Input : None* Output : None* Return : None*/void NVIC_Configuration(void) NVIC_InitTypeDef NVIC_InitStructure; #ifdef VECT_TAB_RAM /* Set the Vector Table base location at 0x20000000 */ NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); #else /* VECT_TAB_FLASH */ /* Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif /* Configure one bit for preemption priority */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); /* Enable the EXTI9_5 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);STM32F10xxx中断IRQ命名按照CMSIS的规范,修改了STM32F10xxx中断号码定义命名。所有中断号码的#define在它们的名称中都添加了后缀_IRQn。表8展示了名称的变化表8 新的异常名称STM32F10xxx固件库V2.0.3 STM32F10xxx标准外设库V3.0.0 描述SystemHandler_NMI NonMaskableInt_IRQn NMI处理程序SystemHandler_HardFault - SystemHandler_MemoryManage MemoryManagement_IRQn 存储器管理处理程序SystemHandler_BusFault BusFault_IRQn 总线错误处理程序SystemHandler_UsageFault UsageFault_IRQn 使用错误处理程序SystemHandler_SVCall SVCall_IRQn SVC处理程序SystemHandler_DebugMonitor DebugMonitor_IRQn 调试监控器处理程序SystemHandler_PSV PendSV_IRQn Pend SV处理程序SystemHandler_Systick SysTick_IRQn SysTick处理程序WWDG_IRQChannel WWDG_IRQn WWDG IRQ处理程序 同样,在标准外设库V3.0.0中,外设CAN的名称改为CAN1。这样,如表9所示,在文件startup_stm32f10x_xx.s / startup_stm32f10x_xx.c和stm32f10x.h中,CAN中断IRQ通道名称也相应改变。表9 CAN1 IRQ通道名称更新固件库V2.0.3 标准外设库V3.0.0 USB_HP_CAN_TX_IRQChannel USB_HP_CAN1_TX_IRQn USB_HP_CAN_RX0_ IRQChannel USB_HP_CAN1_RX0_ IRQn CAN_RX1_ IRQChannel CAN1_RX1_ IRQn CAN_SCE_ IRQChannel CAN1_SCE_ IRQn NVIC驱动从STM32F10xxx标准外设库中移除了NVIC驱动,因此应用程序应当调用CMSIS的NVIC函数。表10展示了CMSIS的函数。表10 STM32F10xxx固件库NVIC函数与CMSIS NVIC函数对比STM32F10xxx固件库NVIC函数CMSIS NVIC函数描述 NVIC_PriorityGroupConfig NVIC_SetPriorityGrouping 在NVIC中断控制器中设置组优先级NVIC_Init NVIC_EnableIRQ 在NVIC中断控制器中使能中断NVIC_DisableIRQ 失能指定的外部中断线路NVIC_SetPriority为某中断设置优先级NVIC_GetIRQChannelPendingBitStatusNVIC_GetPendingIRQ 读取指定的微控制器中断的待处理标志位NVIC_SetIRQChannelPendingBit NVIC_SetPendingIRQ 为某外部中断设置待处理标志位NVIC_ClearIRQChannelPendingBit NVIC_ClearPendingIRQ 为某外部中断清除待处理标志位NVIC_GetIRQChannelActiveBitStatus NVIC_GetActive 读取某中断的活动标志位- NVIC_GetPriority 读取某中断的优先级NVIC_GenerateSystemReset NVIC_SystemReset 初始化系统复位请求STM32F10xxx标准外设库不覆盖其他的STM32F10xxx固件库NVIC函数。为了简化NVIC和STM32中断设置,在文件”misc.h/.c”中保留了原有NVIC驱动的一些函数。它们是: void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup); void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct); void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset); void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState); void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource); 在应用程序开发中进行中断设置时,用户可以选用CMSIS的NVIC函数,或者选用在文件”misc.h/.c”中原有固件库函数。这些函数的优点是提供了相对简单的中断配置方法,使得用户无需深入研究NVIC规范。下面是一段利用固件库V2.0.3原有函数进行NVIC中断设置的例程: /* 1 bits for pre-emption priority 3 bits for subpriority*/ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); /* Configure and enable DMA channel6 IRQ Channel */ NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel6_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 6; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); 在标准外设库3.0.0中,用户只需要把DMA IRQ通道的名称从DMA1_Channel6_IRQchannel改为DMA1_Channel6_IRQn。GPIO/* Function Name : GPIO_Configuration* Description : Configures the different GPIO ports.* Input : None* Output : None* Return : None*/void GPIO_Configuration(void) GPIO_InitTypeDef GPIO_InitStructure; /* Configure PC. as Output push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOC, &GPIO_InitStructure); /* Configure PB9 as input floating (EXTI Line9) */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOB, &GPIO_InitStructure);void EXTI9_5_IRQHandler(void) int i; if(EXTI_GetITStatus(EXTI_Line9) != RESET) for(i=0;iODR = 0xfffffC3f; for(i=0;iODR = 0xffffffff; for(i=0;i=1000000;i+) /* Clear the EXTI line 9 pending bit */ EXTI_ClearITPendingBit(EXTI_Line9); SysTick函数和Delay函数void SysTick_Configuration(void) /* Select AHB clock(HCLK) as SysTick clock source */ SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK); /* Set SysTick Priority to 3 */ NVIC_SystemHandlerPriorityConfig(SystemHandler_SysTick, 3, 0); /* SysTick interrupt each 1ms with HCLK equal to 72MHz */ SysTick_SetReload(72000);/72MHz 1ms /* Enable the SysTick Interrupt */ SysTick_ITConfig(ENABLE);#include stm32f10x_it.hvu32 TimingDelay = 0;extern void Delay(vu32 nTime);/* Function Name : Delay* Description : Inserts a delay time.* Input : nTime: specifies the delay time length, in milliseconds. 即ms* Output : None* Return : None*/void Delay(u32 nTime) /* Enable the SysTick Counter */ SysTick_CounterCmd(SysTick_Counter_Enable); TimingDelay = nTime; while(TimingDelay != 0); /* Disable the SysTick Counter */ SysTick_CounterCmd(SysTick_Counter_Disable); /* Clear the SysTick Counter */ SysTick_CounterCmd(SysTick_Counter_Clear);void SysTickHandler(void) TimingDelay-;另外附一个简单的Delay:void Delay(vu32 nCount) for(; nCount != 0; nCount-);CMSIS只提供了一个SysTick设置的函数,替代了STM32原有SysTick驱动的全部函数。SysTick_Config(uint32_t ticks); 该函数设置了自动重载入计数器(LOAD)的值,SysTick IRQ的优先级,复位了计数器(VAL)的值,开始计数并打开SysTick IRQ中断。SysTick时钟默认使用系统时钟。下面的例程为使用固件库V2.0.3进行SysTick设置: /* Select the HCLK Clock as SysTick clock source (72MHz) */ SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK); /* SysTick end of count event each 1ms with input clock equal to 72MHz (HCLK) */ SysTick_SetReload(72000); /* Enable SysTick interrupt */ SysTick_ITConfig(ENABLE); 下面的例程为使用标准外设库V3.0.0进行SysTick设置: /* Setup SysTick Timer for 1 msec interrupts */ if (SysTick_Config(SystemFrequency / 1000) /* SystemFrequency is defined in “system_stm32f10x.h” and equal to HCLK frequency */ /* Capture error */ while (1); EXTI:外部中断/事件控制器void EXTI_Configuration(void) /* Connect EXTI Line0 to PA.00 */ GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0); /* Configure EXTI Line0 to generate an interrupt on falling edge */ EXTI_InitStructure.EXTI_Line = EXTI_Line0; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Connect EXTI Line9 to PB.09 */ GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9); /* Configure EXTI Line9 to generate an interrupt on falling edge */ EXTI_InitStructure.EXTI_Line = EXTI_Line9; EXTI_Init(&EXTI_InitStructure);中断服务函数void SysTickHandler(void) /* If the EXTI0 IRQ Handler was preempted by SysTick Handler */ if(NVIC_GetIRQChannelActiveBitStatus(EXTI0_IRQChannel) != RESET)/低电位 PreemptionOccured = TRUE; /just an example. 不需要清除中断。void EXTI0_IRQHandler(void) / Add your code here /* Clear EXTI Line0 pending bit */ EXTI_ClearITPendingBit(EXTI_Line0);USARTvoid USART_Configuration(void) USART_InitTypeDef USART_InitStructure; USART_ClockInitTypeDef USART_ClockInitStructure;/* USART1 configuration -*/ /* USART1 configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled - USART Clock disabled - USART CPOL: Clock is active low - USART CPHA: Data is captured on the middle - USART LastBit: The clock pulse of the last data bit is not output to the SCLK pin */USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;/* Configure the USART1 synchronous paramters */USART_ClockInit(USART1, &USART_ClockInitStructure);USART_InitStructure.USART_BaudRate = 9600;USART_InitStructure.USART_WordLength = USART_WordLength_8b;USART_InitStructure.USART_StopBits = USART_StopBits_1;USART_InitStructure.USART_Parity = USART_Parity_No ;USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;/* Configure USART1 basic and asynchronous paramters */USART_Init(USART1, &USART_InitStructure); /* Enable USART1 */ USART_Cmd(USART1, ENABLE);碰到的问题1、 停留在stm32f10x.s中,进不了主函数主函数前面加上这样一段即可,可能是因为将C库中的printf函数重新定向到USART中,重写了fputc(int ch,FILE *f)函数:/* Includes -*/#include stm32f10x_lib.h#include #pragma import(_use_no_semihosting) /* *? */ struct _FILE int handle; /* Whatever you require here. If the only file you are using is */ /* standard output using printf() for debugging, no file handling */ /* is required. */ ; /* FILE is typedef d in stdio.h. */ FILE _stdout; / / ?_sys_exit()? / / / _sys_exit(int x) x = x; 简单说就是添加下面一段:#include stm32f10x_lib.h#include #pragma import(_use_no_semihosting) /这句话去掉也行struct _FILE int handle; ; /* FILE is typedef d in stdio.h. */ FILE _stdout; _sys_exit(int x) x = x; 真正的原因是由于:/share/detail/54393578在keil (我用的是realview mdk3.11)建立ARM的工程时其中有一项是选 use MicroLIBmicrolib 是缺省 C 库的备选库。 它旨在与需要装入到极少量内存中的深层嵌入式应用程序配合使用。 这些应用程序不在操作系统中运行。测试:这样加上这个microlib之后就是好的了,呵呵。2、 四谛法知识点关于stm32AHB主要负责外部存储器时钟。PB2负责AD,I/O,高级TIM,串口1。APB1负责DA,USB,SPI,I2C,CAN,串口2345,普通TIM。/* PWR clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);/使能PWR时钟 /* APB1Periph_ALL clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_ALL, ENABLE);/使能APB1Periph_ALL时钟 /* Enable APB2 peripheral clocks -APB2外设时钟使能-*/ /* Enable GPIOA,B,C,D,E clocks */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);/使能GPIOA时钟/ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);/使能GPIOB时钟 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);/使能GPIOC时钟 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);/使能GPIOD时钟/ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);/使能GPIOE时钟 /* AFIO clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Pe
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026浙江杭州市富阳区部分事业单位招聘40人笔试模拟试题及答案详解
- 2026辽宁沈阳化工大学招聘高层次人才50人(第一批)笔试模拟试题及答案详解
- 夹江县2026年面向县外公开选调事业单位工作人员(19人)笔试参考题库及答案详解
- 2026四川绵阳东辰高级中学招聘教师83人笔试模拟试题及答案详解
- 2026四川凉山州西昌学院招聘科研助理94人笔试备考试题及答案详解
- 2026湖南株洲市第十三中学招聘教师8人笔试模拟试题及答案详解
- 2026山东金衢设计咨询集团有限公司招聘7人笔试参考题库及答案详解
- 招聘1人!2026年度海南州第五民族高级中学校园引才笔试模拟试题及答案详解
- 2025年广发银行(葫芦岛分行)校园招聘笔试考试试题及答案详解
- 2026年中信银行(宁波分行)校园招聘考试备考题库及答案详解
- 曼昆-宏观经济学
- JCT 906-2023 混凝土地面用水泥基耐磨材料 (正式版)
- 《决策树算法》课件
- 第四章-空气和废气监测
- 海康威视全系产品交流-课件
- 人工智能导论知到章节答案智慧树2023年哈尔滨工程大学
- 2022年全国高考新高考I卷读后续写课件- 高三英语二轮复习
- 【超星尔雅学习通】航空与航天网课章节答案
- 考向1 化学与STSE(附答案解析)-备战高考化学一轮复习(全国通用)
- 2023年报告模版单位政治生态分析研判报告
- GA 891-2010公安单警装备警用急救包
评论
0/150
提交评论