STM32 關閉JTAG 使用相應GPIO口 簡單記錄



    STM32 的PA13-PA14-PA15-PB3-PB4-PB5主要是用來JTAG調試用的,於是在默認下是啓動後爲JTAG模式,但是對於不需要JTAG而需要充分利用GPIO口時,就需要將JTAG關閉,設置爲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);   //打開復用時鐘----重要

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);

然後就可以直接當成GPIO口使用---高低電平設置---

GPIO_SetBits(GPIOA,GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);        
GPIO_ResetBits(GPIOB,GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5);


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章