cancel
Showing results for 
Search instead for 
Did you mean: 

Where is port A registers configured for pins 13 and 14 to configure SWD?

MMust.5
Senior II

STM32F407VGT6

Here is my code:

#include "main.h"

int main(void)

{

RCC->AHB1ENR|=RCC_AHB1ENR_GPIOAEN;

 while (1)

 {

 }

}

For port A registers (pins 13 and 14) is the configuration done in the IDE? In the code, I did not find the configuration of port A registers, but SWD still works.

What settings are needed to install SWD on pins 13 and 14 of port A?

I looked at the GPIOA_MODER register, it looks like this: 1010 1000 0000 0000 0000 0000 0000 0000

It turns out pins 13 and 14 are set to Alternate function mode.

For some reason, pin 15 of port A is also set to Alternate function mode, although pin 15 of port A is a general purpose pin.

I cleared those GPIOA->MODER=0; bits, but they are not overwritten when the IDE is restarted.

I have to erase the whole chip to get into it.

In the code, I did not find where port A is configured, but if the configuration occurs through the IDE, then why are the bits not restored after I erase them GPIOA->MODER=0;

------------------------

Port A registers start at address 0x40020000.

0693W00000NqPK7QAN.png 

14 REPLIES 14

>> while still keeping it in a reset state, in which the CPU is not running 

Or is it ONLY in Connect under reset mode that the GPIOA->MODER register has the default (reset) value again?

And in normal mode, the GPIOA->MODER register is filled with zeros after my code (GPIOA->MODER=0;) ?

My previous comment talks about the CPU and software (firmware) on the MCU, not the IDE. Debugging with or without downloading doesn't matter here. Yes, the CPU starts executing instructions only after the reset is released and the MCU exits the reset state.

OK. Thank you. Understood.

Checked with this code:

RCC->AHB1ENR|=RCC_AHB1ENR_GPIODEN;

GPIOD->MODER=0xFFFF;

This is a normal start mode

0693W00000NqPuAQAV.pngThis is a launch in Connect under reset mode

0693W00000NqPuFQAV.png 

Registers are not set to the default value after a restart.

Only after erasing the entire chip, for some reason, the registers are set to the standard reset value.

0693W00000NqPuPQAV.pngAnd Connect under reset mode just helps you enter the chip with standard settings.

I thought that after each restart of the microcontroller, the bits from the "reset value" returned to the standard state.

As the reference manual shows, except for ports A and B, for the rest of the ports MODER reset value is zero. In the first image you are looking at the value after the firmware has modified it. In the second image you are looking at the value before the firmware has modified it. And in addition, when the respective peripheral clock is not enabled, the peripheral registers will mostly read as zero anyway.

Also the debugger can connect even without doing a reset. I don't know at what moment exactly you looked at those values (especially in the first picture) and what exactly that "Debug without Downloading" option does. But one thing is for sure - the reset definitely resets the values to the default ones!

>>I don't know at what moment exactly you looked at those values (especially in the first picture) 

In the picture, where is the value 0000FFFF stored under the address 0x40020C00?

These two images are made with the same code on the microcontroller.

The only difference between these two pictures is that in the first picture I used Normal Mode.

And in the second picture I used Connect Under Reset Mode.

0693W00000NqPw6QAF.pngSoftware: STM32 ST-LINK Utility

The code on the microcontroller was:

RCC->AHB1ENR|=RCC_AHB1ENR_GPIODEN;

GPIOD->MODER=0xFFFF;

These modes can be turned on and off as many times as you like. In Connect Under Reset Mode, only a TEMPORARY reset of register settings.

In normal mode, the register settings I saved with IDE are RETURNED AGAIN.

>>But one thing is for sure - the reset definitely resets the values to the default ones!

Pressing the reset button on my STM32F407 board? (This does not reset the registers to default settings.)

Soft reset also does not reset the registers to default settings.

As far as I understand Hard reset and Soft reset just help to replace the old code with a new one, I think a restart is more suitable than a reset.

I don't know of a way yet other than a complete wipe of the microcontroller to reset the registers to default settings PERMANENTLY.

If you meant Connect Under Reset, then yes, in this mode, the register settings are temporarily reset to the standard state.

>>and what exactly that "Debug without Downloading" option does.

This option is in the IDE IAR, with this option you can analyze the code that is on the Microcontroller without downloading the code from the IDE to the Flash memory of the Microcontroller.