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
Lawliet KG
Associate III
Posted on December 14, 2016 at 19:42

Hi reh.tilmann,

If you want to use the PB3 as a GPIO pin, you should not use the asynchronous trace over the SW debug.

Lawliet.

Posted on December 14, 2016 at 23:26

Hello Lawliet,

I really appreciate that you want to help - but did you read the previous posts, starting with the very first one?

I do not use async trace, and mentioned that often.

Tilmann

Posted on December 15, 2016 at 00:25

What debugger hardware and software are you using?

Been years since I was actively building with F1 parts but don't recall PB3 being unusable.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
tilmann
Associate III
Posted on December 15, 2016 at 11:15

Hello everybody,

problem solved - indeed it was a small typo in the MAPR assignment, so in fact JTAG was not disabled in the application code. The bootloader didn't have that typo, so JTAG was disabled there, but during initialization of the application all peripherals are reset - and it appears that this partially resets the JTAG port assigment... (Remember that PB4 and PA15 still worked as GPIO, that's why I didn't notice that typo for such a long time (and obviously I overlooked it very many times when checking the code)).

Sorry, my fault. Now PB3 works as expected.

Tilmann

Posted on December 15, 2016 at 11:22

>problem solved - it was a small typo in the MAPR assignment

This is why I asked you to post the read-back content of relevant registers.

JW

Posted on December 15, 2016 at 11:32

Remember that particularly these bits of MAPR are write-only, unfortunately.

Tilmann

Posted on December 15, 2016 at 11:41

>Remember that particularly these bits of MAPR are write-only, unfortunately.

Ah, I did not know that, sorry then. I don't 'F1.

Jan

Micha Valach
Associate III
Posted on March 12, 2017 at 09:35

Hello Tilmann,

I'm having the same problem.

Not sure, how did you solve the GPIO PB.3 problem?

You had mention '

small typo in the MAPR assignment

' , in my case I call once to: AFIO->MAPR = 0x02000000;  and still it doesn't work. Please be more specific what is the fixed value you wrote to MAPR?

Thanks In Advance,

Micha 

Posted on March 12, 2017 at 12:43

Don't you use the 'asynchronous trace', enabled possibly by your toolchain (maybe by enabling some form of 'semihosting' )?

JW

markus-muc
Associate II
Posted on June 01, 2017 at 17:59

I am having the same problem. I am using the STM32 peripherals library for configuration, so my init code looks like this:

// Disable JTAG, keep SWD => Enable PB3, PB4 for GPIO output

GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);

// Activate port B periphery

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

// PB3 (output, high active): PP

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;

GPIO_Init(GPIOB, &GPIO_InitStructure);

// PB4 (output, high active): PP

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;

GPIO_Init(GPIOB, &GPIO_InitStructure);

As a result, PB4 works as expected, but PB3 doesn´t. 

I am using Atollic TrueStudio, so it may be that 'asynchronous trace' is enabled. However, I cannot find any option to configure it - and Google is _not_ my friend (i.e. couldn´t find how to turn 'asynchronous trace' off in Atollic).

Anybody any idea?