2017-10-10 03:42 AM
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; // AF0PA8 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.
2017-10-10 03:51 AM
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
2017-10-10 05:56 AM
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.
2017-10-10 06:13 AM
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?
2017-10-10 07:05 AM
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?
2017-10-10 07:06 AM
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
2017-10-10 08:15 AM
They default to 10 and not 01.
Also, you don't want to override their OSPEEDR settings too.
JW
2017-10-10 08:43 AM
Sorry my typo, thanks.
2017-10-10 09:56 AM
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]
2017-10-10 10:42 AM
Thanks, I will keep this in mind.