7
\$\begingroup\$

What is the use of the NRST pin in STM32F401RTC microcontroller. I am using the SWD interface to program and debug flash memory of the controller. I am finding NRST pins in both microcontroller as well as stlink debugger.

I am confused, what is the use of NRST pins? Is it used to reset the program which we flash and allow us to program it again? And why is a capacitor connected on the outer side of the pin and to ground?

enter image description here

What is the use of it in microcontroller and Stlink? How does it work?

I checked in Google. The explanation given was too technical, so kindly explain to me in simple terms.

\$\endgroup\$
1
  • \$\begingroup\$ it resets the chip, puts it in a known state, just about everywhere the word reset appears in the documentation be it the reset state of a register or when looking at the boot0 pin, for example strap boot0 high or low while asserting reset using nrst. once using swd to program the flash then the reset button/pin can be used to reset and load the new application in flash. \$\endgroup\$
    – old_timer
    Apr 5, 2020 at 5:20

2 Answers 2

10
\$\begingroup\$

Is it used to reset the program which we flash and allow us to program it again?

It seems you are confused about what reset actually resets. It does not "reset the program", it resets the MCU. The content of flash is not changed, so previously written program is still available.

Specifically, while NRST pin is connected to the ground the MCU stays in "reset state", i.e. it does not do anything, the clocks are stopped and the program that is already flashed is not running.

When you disconnect NRST pin from the ground (release the button) the internal pull-up resistor (marked RPU on the schematics) applies VDD voltage to it, which eventually flips Schmitt trigger and brings MCU out of reset state, at which point it starts executing the program at reset vector.

why is a capacitor connected on the outer side of the pin and to ground?

The capacitor is there to provide some EMS protection and avoid parasitic resets.

What is the use of it in microcontroller and Stlink? How does it work?

Usually the program at reset vector is a bootloader, which will either detect an attempt to upload new program (via USB, CAN, Serial etc. channels) or simply pass execution to the old program already in flash. It is the second case that can be interpreted as "program reset", since the program indeed begins execution from start. However the important difference is that NRST does much more than simple program restart, for example it resets all the MCU registers to their default states.

Note that in your particular case (using SWD interface for programming) the NRST pin is not actually useful, since SWD completely bypasses bootloader and can reset and flash MCU directly. It is only if your program reconfigured SWD pins as regular GPIO then you need hardware reset to flash a new one (remember that NRST resets all registers to default states, including pin configuration). ST-LINK usually uses software reset, however if it does not work you can go into setup interface and change this to hardware.

In short, NRST pin is used to activate bootloader when you need to flash new program using one of the communication channels and to reset MCU to default state when you want to flash new program using SWD interface and SWD pins are not available.

\$\endgroup\$
2
  • \$\begingroup\$ Thank you so much for your reply. So NJRST pin is not useful when i use SWD interface . so if i am using SWD interface i need to connect the NJRST pin to ground as you said if it is connected to ground it cannot reset the micro-controller. without resetting can i able to program multiple times by using SWD. \$\endgroup\$
    – Muthu
    Apr 5, 2020 at 14:19
  • 1
    \$\begingroup\$ You completely missed the point. If you connect NRST pin to ground your MCU will be permanently in reset state, i.e. you will not be able to do anything with it. Not only that, but you are now talking about NJTRST pin, which is JTAG reset and usually entirely different pin from NRST on STM MCUs. \$\endgroup\$
    – Maple
    Apr 5, 2020 at 20:36
4
\$\begingroup\$

It resets the MCU. In order to flash the MCU, the ST-LINK resets and then sends the program through SWD. It should be self explanatory that MCU can't run the program and being flashed at the same time. So how to stop the CPU execution and invoke the bootloader? The first step is to reset it.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Thank you so much for your reply . still i cant understand like it will stop the program which is already flashed in the memory and running . it will RESET it first and then it will again flash new program to the memory. that is why when we run a LED blink program already but when we again load the new LED blink program the already blinking LED stopped blinking till the new program is being flashed . am i right \$\endgroup\$
    – Muthu
    Apr 5, 2020 at 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.