cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 - PB3 just doesn't work as GPIO

tilmann
Associate III
Posted on December 14, 2016 at 10:27

Hello,

did anyone ever manage to get PB3 working as an I/O port on an STM32F103?

I am having a hard time with the F103VB where I need PB3 as input - no matter what I try, PB3 simply is returning a 0 value.

AFIO->MAPR is set to SWD debug only, JTAG off (and AFIO clock is on, of course).

I also explicitly set DBGMCU_CR to turn TRACE off, although that should be default after reset.

The other two related port pins (PB4 and PA15) work perfectly fine as GPIO. Only PB3 simply appears dead.

The errata sheet also doesn't mention any problems with PB3 as GPIO.

Did I find a new bug?

Any help is greatly appreciated.

Thanks, Tilmann

32 REPLIES 32
_dalbert
Associate III
Sorry, I was agreeing with what you said and providing additional detail; in re-reading, I realize that wasn't clear, I've clarified my comment to state that.  Thanks Clive!
_dalbert
Associate III
I added a code snippet at the bottom of the thread to illustrate how to resolve the concern in the OP since the same issue had bitten me and apparently quite a few others.  I was going back through the thread to
try to clarify things and rushed it - resulting in the poorly stated
reply; I just wanted to make it clear to anyone who stumbles on this
issue in the future that the assertion was not true (the OP's assertion,
not yours), that the manual is correct and that the pins can be used,
and provide the code showing how to use them.  Thanks again for your
past post and sorry again for the poorly worded reply!
Alex_Babenko
Associate

Hi. I had the same problem. The solution was simple. Just added a delay between remapping and configuration PB3 as GPIO.

Code by using SPL:

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);

for(int u; u < 0x11A; u++);

/* Initialization reading pins */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4;

   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

   GPIO_Init(GPIOB, &GPIO_InitStructure);