STM32將PB3等IO用作普通IO

來源:互聯網
上載者:User
STM32F103 的 JTAG, 預設狀態是Full SWJ。
The default state after reset is “000” (whole pins assigned for a full JTAG-DP connection).

PB3作為JDO,被JTAG佔用。
在 TRACE Asynchronous mode,PB3還是TRACESWO。

若系統不需要JTAG,將PB3當作GPIO,需要如下設定:

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOB , ENABLE);
  GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable,ENABLE);


第一句中的 RCC_APB2Periph_AFIO 設定 AFIOEN(如果沒有這一句,後面兩句失效)。 如果一個模組的clock DISABLE,那麼,寄存器的值也無法讀寫。

有了上面兩句,就可以進一步對PB3進行操作了。
例如:
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOB, &GPIO_InitStructure);


  GPIOB->ODR = 0x08;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.