8

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.

SamGibson
  • 17,231
  • 5
  • 37
  • 58
Muthu
  • 557
  • 2
  • 6
  • 16
  • 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. – old_timer Apr 05 '20 at 05:20

3 Answers3

10

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.

Maple
  • 11,755
  • 2
  • 20
  • 56
  • 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. – Muthu Apr 05 '20 at 14:19
  • 1
    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. – Maple Apr 05 '20 at 20:36
4

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.

Marko Buršič
  • 23,562
  • 2
  • 20
  • 33
  • 1
    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 – Muthu Apr 05 '20 at 00:07
0

The NRST pin on the STM32 microcontroller is the Reset pin. When the NRST pin is pulled low or connected to ground (logic low), it triggers a reset condition for the microcontroller. This means that the microcontroller will reset its internal state and restart its execution from the beginning.

When the NRST pin is pulled low, the following events typically occur:

1.The program execution is halted, and the microcontroller stops executing instructions.

2.The microcontroller's internal registers and memory contents may be reset to their default values.

3.The microcontroller restarts its execution from the reset vector, which is typically the address where the initial boot code resides.

Electronx
  • 483
  • 2
  • 9