在使用PB3和PB4做普通GPIO使用時,發現普通的GPIO初始化程序無法正常使用PB3和PB4,后經查閱資料,發現是因為PB3和PB4在默認情況下是做JTAG調試用的。如果需要將其當普通GPIO使用,需要關閉JTAG調試功能;
配置方式入下:
1 /************************************************* 2 函 數 名 稱 : LibDriveKeyInit 3 功 能 描 述 : 按鍵初始化 4 被 調用清單 : 無 5 調 用 清 單 : 6 輸 入 參 數 : 無 7 輸 出 參 數 : 無 8 返 回 參 數 : 無 9 其 他 : 無 10 *************************************************/ 11 void LibDriveKeyInit(void) 12 { 13 GPIO_InitTypeDef GPIO_InitStruct; 14 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE); 15 16 GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); 17 GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU; 18 GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4; 19 GPIO_Init(GPIOB, &GPIO_InitStruct); 20 21 GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU; 22 GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_15; 23 GPIO_Init(GPIOA, &GPIO_InitStruct); 24 }