老习惯,先上代码
void Hw_Input_Chage_Init(void)
{GPIO_InitTypeDef GPIO_InitStructure;RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);RCC_APB1PeriphClockCmd(RCC_APB1Periph_IOMUX, ENABLE);GPIOMUX->NRST_PIN_KEY = (uint32_t)(0x00005AE1); //KEYGPIOMUX->PKG_PIN_SEL &= (uint32_t)(0xFFFFFF00); //NRSTPA0_PIN_SEL = 0GPIOMUX->NRST_PIN_KEY = (uint32_t)(0x00005AE1); //KEYGPIOMUX->NRST_PA0_SEL |= (uint32_t)(0x00000007); //bit0:NRST 1 PA0 bit1-2:SWCLK 11 PB5 bit5-6:SWDIO 00 PD5GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //引脚输入模式GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_2;GPIO_InitStructure.GPIO_Schmit = GPIO_Schmit_Disable;GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //内部上拉//NRST --> PA0//GPIO_IOMUX_ChangePin(IOMUX_PIN2, IOMUX_NRST_SEL_NRST);// TSSOP16 PIN2(NRST)PA0 IO IOMUX_NRST_SEL_NRST IOMUX_NRST_SEL_PA0GPIO_Init(GPIOA, &GPIO_InitStructure);
}
上面这段代码将SWCLK/SWDIO/RST复用成GPIO,配置RST为输入
void Hw_Key_Init(void)
{GPIO_InitTypeDef GPIO_InitStructure;EXTI_InitTypeDef EXTI_InitStructure;NVIC_InitTypeDef NVIC_InitStructure;RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);//SWCLK PB5 as GPIO//GPIO_IOMUX_ChangePin(IOMUX_PIN11, IOMUX_PB5_SEL_PB5); //TSSOP20PIN11(PD5)PB5 IOGPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //引脚输入模式GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_2;GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //内部上拉GPIO_Init(GPIOB, &GPIO_InitStructure);/* 配置EXTI */EXTI_InitStructure.EXTI_Line = EXTI_Line5;EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;EXTI_InitStructure.EXTI_LineCmd = ENABLE;EXTI_Init(&EXTI_InitStructure);SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource5);EXTI_ClearITPendingBit(EXTI_Line5);NVIC_InitStructure.NVIC_IRQChannel = EXTI5_IRQn;NVIC_InitStructure.NVIC_IRQChannelPriority = 0;NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NVIC_InitStructure);}//SWCLK
unsigned char Hw_Key_Get_Power_Key_Value(void)
{return GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_5);
}unsigned char g_temp = 0;void EXTI5_IRQHandler(void)
{if(EXTI_GetFlagStatus(EXTI_Line5) != RESET){g_temp = !g_temp;if(g_temp)Hw_Led_Green_Enable();else Hw_Led_Green_Disable();EXTI_ClearITPendingBit(EXTI_Line5);}
}
上面这段代码将SWCLK配置为EXTI5
void Hw_Adc_Init(void)
{GPIO_InitTypeDef GPIO_InitStructure;ADC_InitTypeDef ADC_InitStructure;RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC, ENABLE);RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOD, ENABLE );RCC_APB1PeriphClockCmd(RCC_APB1Periph_IOMUX, ENABLE);//初始化模拟IO PD5GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;//GPIO_IOMUX_ChangePin(IOMUX_PIN2, IOMUX_PD5_SEL_PD5);// TSSOP20 PIN2(PD5) PD5 IOGPIO_Init(GPIOD, &GPIO_InitStructure);GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_7);ADC_DeInit(ADC1);ADC_StructInit(&ADC_InitStructure);ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConvEdge_None;ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward;ADC_Init(ADC1,&ADC_InitStructure);/* ADC1 regular channels configuration */ ADC_ChannelConfig(ADC1, ADC_Channel_0 , ADC_SampleTime_239_5Cycles);//ADC_GetCalibrationFactor(ADC1);/* Enable ADC1 */ADC_Cmd(ADC1, ENABLE);while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADRDY)); ADC_StartOfConversion(ADC1);
}
上面这段代码将SWDIO配置为ADC的通道0
航顺的资料是偏少的,21论坛提问也很难得到有用的回复,建议大家还是仔细看看官方的例程,如果有问题,就仔细对照各个例程的代码。
资源已经上传,链接如下:
https://download.csdn.net/download/Dr_Haven/21567721