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
Mon2
Senior III
Posted on December 14, 2016 at 12:41

Just found the following using Google. You will have to locate the respective call to disable the use of the JTAG pins which are common to PB3.

http://www.stm32duino.com/viewtopic.php?t=1458&p=18818

 

http://www.stm32duino.com/viewtopic.php?t=1130#p13918

 
Imen.D
ST Employee
Posted on December 14, 2016 at 14:36

Hello

Reh.Tilmann

,

You can refer to the reference manual RM0008 for more clarification, in 'General-purpose and alternate-function I/Os (GPIOs and AFIOs)' and 'JTAG/SWD alternate function remapping' section.

Hope this helps you.

Best Regards

-Imen-

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Lawliet KG
Associate III
Posted on December 14, 2016 at 18:09

Hi,

In 'STM32F1 getting started hardware development' application note , you can see that PB3 is used by the SW debug port. PB5 and PA15 are only used by JTAG, this is why you can use them as GPIO pins by disabling the JTAG and keeping the SWD enabled.

If you want to use PB3 pin, you must also disable the SWD.

Lawliet.

Posted on December 14, 2016 at 17:39

Thanks for your answers - however in my post I already mentioned that I have disabled JTAG and still PB3 does not work as GPIO. Of course I can also use Google and read the RM, and you can be sure I extensively did. Otherwise, I wouldn't have asked here...

The other two ports that can be used by JTAG (PB4 and PA15) are working correctly as GPIO, so disabling JTAG basically works - however not PB3.

Best regards,

Tilmann

Posted on December 14, 2016 at 17:54

Post the read-out content of relevant registers.

JW

Posted on December 14, 2016 at 17:55

Isn't PB3 (SWO) part of the SWD connectivity?

The SPL example demonstrates the use of PB3

STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Examples\GPIO\JTAG_Remap\main.c

/* Disable the Serial Wire Jtag Debug Port SWJ-DP */

GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);

GPIO_Remap_SWJ_JTAGDisable should allow PB3 to be used if Trace isn't used or negotiated by the debugger. The usability here may strongly depend on the specific debugger pod and debugger software being utilized, which isn't mentioned here.

The F1 is about a decade old, so I doubt this is a new bug. There are situation where you need to debug without the aid of JTAG/SWD

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

Yes, PB3 can be used as trace data output (asynchronous trace). That's why I explicitly took care to have trace turned off (via DBGMCU_CR), even though it's off by default after reset. I didn't find any other function that could use PB3 with a higher priority (except for JTDO which is disabled as well).

I can't turn off SWD completely since that's the only access to my boot loader. However, from all known documents it should work perfectly fine with only  JTAG turned off (and SWD enabled) by AFIO->MAPR. I don't use the SPL but simply write to that register directly.

I don't use debug in this case (it's also impossible due to r/w protection of the flash, BTW), so from all those documents PB3 should be available as GPIO - however it just doesn't work. (Opposed to PB4 and PA15 which work exactly as documented.)

So I would really like to know if (and particularly how) anyone ever managed to use PB3 with this device...

Regards,

Tilmann

Posted on December 14, 2016 at 18:18

Lawliet KG wrote:

If you want to use PB3 pin, you must also disable the SWD.

That really isn't what the RM0008 manual says...

0690X00000603ElQAI.jpg
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on December 14, 2016 at 18:21

Hello Lawliet,

if that is true, it is indeed a bug - see Table 220 in the RM (on page 1086, below). It is clearly specified that PB3 is released as GPIO as soon as JTAG is disabled.

0690X00000605ozQAA.png

Best regards,

Tilmann