STM32 關(guān)閉JTAG 使用相應(yīng)GPIO口 簡單記錄
STM32 的PA13-PA14-PA15-PB3-PB4-PB5主要是用來JTAG調(diào)試用的,于是在默認(rèn)下是啟動后為JTAG模式,但是對于不需要JTAG而需要充分利用GPIO口時,就需要將JTAG關(guān)閉,設(shè)置為GPIO模式。
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //打開PA時鐘
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //打開PB時鐘
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //打開復(fù)用時鐘----重要
GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable,ENABLE); //禁止所有SWJ----重要
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_13 | GPIO_Pin_14| GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_3 | GPIO_Pin_4| GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
然后就可以直接當(dāng)成GPIO口使用---高低電平設(shè)置---
GPIO_SetBits(GPIOA,GPIO_Pin_13 | GPIO_Pin_14| GPIO_Pin_15);
GPIO_ResetBits(GPIOB,GPIO_Pin_3 | GPIO_Pin_4| GPIO_Pin_5);