【STM32】STM32F103C8T6 使用PB3和PB4引脚

技术交流,调试帮助,可添加,技术Vx:anwarmaries QQ:1083091092

STM32F103C8T6的引脚属于JTAG调试使用
使用时,需要添加语句

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
   GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);//关闭JTAG功能(PB3/4),只使用SWD(PA13/14)调试

如:

void LED_Init(void){
    
     //LED灯的接口初始化
	GPIO_InitTypeDef  GPIO_InitStructure; 	
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC,ENABLE);   
//PB4默认用作调试口,如果用作普通的IO,需要加上以下两句 
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
   GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);//关闭JTAG功能(PB3/4),只使用SWD(PA13/14)调试

    GPIO_InitStructure.GPIO_Pin = LED1 | LED2; //选择端口号(0~15或all)                        
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //选择IO接口工作方式       
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置IO接口速度(2/10/50MHz)    
	GPIO_Init(LEDPORT, &GPIO_InitStructure);			
}

代码为控制两个灯的状态在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/jiushiguang11/article/details/130543991