RCC_AHB2Periph_AFIO
时间: 2024-03-24 16:34:26 浏览: 64
RCC_AHB2Periph_AFIO是STM32系列微控制器的一个寄存控制器,用于配置IO端口功能和映射。它是通过RCC(Reset and Clock Control)模块的AHB2总线来控的。
RCC_AHB2Periph_AFIO的主要功能包括:
1. 配置IO端口的复用功能可以将IO端口为多种不同的功能,如GPIO、USART、SPI等。
2. 配置IO端口的映射:可以将IO端口映射到不同的引脚,以满足特定应用的需求。
3. 配置外部中断线:可以将外部中断线连接到特定的IO端口上,以实现外部中断功能。
RCC_AHB2Periph_AFIO的使用方法一般包括以下几个步骤:
1. 使能AFIO时钟:通过RCC模块使能AFIO时钟,以便使用AFIO功能。
2. 配置IO端口的复用功能:通过设置AFIO寄存器,将IO端口配置为所需的功能。
3. 配置IO端口的映射:通过设置AFIO寄存器,将IO端口映射到所需的引脚。
4. 配置外部中断线:通过设置AFIO寄存器,将外部中断线连接到所需的IO端口上。
相关问题
在保持原来的代码逻辑的条件下,根据STM32F407的特性,把下面STM32F1的代码移植到STM32F407。void ExtiGpioInit(void) { GPIO_InitTypeDef GPIO_InitStruct; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO, ENABLE); GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_5 ; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStruct); } void ExtiNvicInit(void) { NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn ; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } void ExtiModeInit(void) { EXTI_InitTypeDef EXTI_InitStructure; GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource4); EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_Line = EXTI_Line4; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource5); EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_Line = EXTI_Line5; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); }
void ExtiGpioInit(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_5 ;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOC, &GPIO_InitStruct);
}
void ExtiNvicInit(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void ExtiModeInit(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource4);
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_Line = EXTI_Line4;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource5);
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_Line = EXTI_Line5;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
stm32f411如何打开AFIO的时钟
STM32F411系列微控制器想要开启AFIO(Advanced Front-End Interface)模块的时钟,首先需要确保系统时钟已经配置好并且AFIO模块位于可用的时钟树中。以下是基本步骤:
1. **配置系统时钟**:确保HSE(High-Speed External Oscillator)或HSI(Internal High-Speed oscillator)已启动,并通过`RCC_OscInitTypeDef`结构配置到所需的系统时钟源(如SYSCLK、AHB/APBx clock)。
```c
RCC_OscInitTypeDef RCC_OscInitStruct;
// ... (设置oscillator频率)
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; // 或者 RCC_OSCILLATORTYPE_HSI
RCC_OscInitStruct.HSEState = RCC_HSE_ON; // 开启HSE
// ... (其他时钟配置选项)
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; // 如果需要PLL
HAL_RCC_OscConfig(&RCC_OscInitStruct);
```
2. **选择AFIO时钟源**:配置AFIO时钟从系统时钟中分频而来,通常会用到APB1或APB2时钟。你可以使用`RCC_APB1PeriphClockCmd()`或`RCC_APB2PeriphClockCmd()`函数来启用相应的AFIO时钟。
```c
if (GPIO_AFIOClock == RCC_APB1Periph_AFIO) {
HAL_RCC_APB1PeriphClockCmd(RCC_APB1Periph_AFIO, ENABLE); // 启用APB1时钟给AFIO
} else if (GPIO_AFIOClock == RCC_APB2Periph_AFIO) {
HAL_RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); // 启用APB2时钟给AFIO
}
```
3. **检查时钟是否启用**:最后,可以使用`HAL_GPIO_GetPinClock()`函数来确认AFIO时钟是否已经被成功激活。
```c
GPIO_PinClockSourceTypeDef source;
source.PinClock = GPIO_PIN_ClockSource_AFIO;
HAL_GPIO_GetPinClock(GPIO_AFIO_BASE, GPIO_Pin_0 | GPIO_Pin_1); // 使用实际需要的AFIO引脚
if (source.PinClock == AFIO_PinClockSource_Enable) {
// AFIO时钟已启用
} else {
// AFIO时钟未启用
}
```
阅读全文