cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 debuugger not working when PORTA in use

Mark Greally
Associate II
Posted on October 10, 2017 at 12:42

Hi.

Using a STM32F407 I am having an issue using the debugger when PORTA is in use. The debugger works fine when PORTA is not in use. I am using MCO1 which is on PORTA and when I set the MODER register the debugger fails.

    // Enable MCO1 clock on PA8

     GPIOA->MODER = (1 << 17);  // same as *GPIOAMODER = (1 << 17);

     GPIOA->OSPEEDR = 0x30000;  // very high speed. OSPEEDR8

     GPIOA->PUPDR = 0x0;        // No pull-up, pull-down

     GPIOA->AFR[0] = 0x0;       // AF0

     GPIOA->AFR[1] = 0x0;       // AF0

PA8 does not share any pins with the debugger so this should work. Is there some additional settings that need to be set to allow this??

Thanks.

9 REPLIES 9
Posted on October 10, 2017 at 12:51

Don't override MODER/AFRL/H for the SWD/JTAG pins (nor other GPIO registers for those pins).

Hint: look at their default values.

JW

Mark Greally
Associate II
Posted on October 10, 2017 at 14:56

Thanks Guys. I replaced the first line with GPIOA->MODER |= (1 << 17); to set the individual bit and it works now. I thought the pins P13, P14 and P15 defaulted to 00 not 01. Its not very clear in the RM.

Posted on October 10, 2017 at 13:13

Removing the alternate function code has no affect. The code works fine when not in debug mode as it should, The MCO clock is generating as it should. I also tried MCO2 which is on PORTC and debug mode works then when PORTA is not in use. Its only PORTA when in debug mode that it doesn't work. I have isolated it to: 

GPIOA->MODER = (1 << 17); 

It works for all other lines but of course I need the above for the clock. This is really strange because as soon as I program in non debug mode it works fine. Does setting the MODER (in PORTA) register somehow disable debugging mode?

Posted on October 10, 2017 at 14:05

Yes, because 

GPIOA->MODER = (1 << 17); nukes the ENTIRE register of its existing content, and the debug interface uses PA13/PA14. Perhaps you should modify the content while respecting the bits you aren't looking to change?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 10, 2017 at 14:06

I've told you above: don't override the debug pins' settings in GPIO.

Those two pins have to be  set as AF in MODER (plus their AFRL/AFRH setting as AF0 and OSPEDR as... some of the high speed).

Read the GPIO chapter in RM. And use the default values.

JW

Posted on October 10, 2017 at 15:15

They default to 10 and not 01.

Also, you don't want to override their OSPEEDR settings too.

JW

Posted on October 10, 2017 at 15:43

Sorry my typo, thanks.

Posted on October 10, 2017 at 16:56

Also the debugger can change clock and pin configurations to suit it's needs, so things might not always be in reset/default conditions.

You should mask off the content, and change the specific bits of interest for PA8 vs PA[0..15]

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 10, 2017 at 17:42

Thanks, I will keep this in mind.