Skip to main content
fhu.11
Associate III
January 10, 2022
Solved

I need to use PG10-NRST as a GPIO. So I check the Reference manual to find out how to do it. I find that it can be done if I modify the field NRST_MODE to 2 and I really do this. But it doesn't work.The mcu still reset when PG10-NRST comes a low leve

  • January 10, 2022
  • 2 replies
  • 1941 views

Here is my code in main() to config field NRST_MODE:

HAL_FLASH_Unlock();

 HAL_FLASH_OB_Unlock();

 gFlashOBST.OptionType = OPTIONBYTE_USER;

 gFlashOBST.USERType  = OB_USER_NRST_MODE;

 gFlashOBST.USERConfig = FLASH_OPTR_NRST_MODE_1;

 HAL_FLASHEx_OBProgram(&gFlashOBST);

 HAL_FLASH_OB_Lock();

 HAL_FLASH_Lock();

I find the NRST_MODE changes from 3 to 2 in the SFRs window after my code when I run it online. Then I ground PG10-NRST directly and the mcu goes to reset.

I connect mcu to STM32CubeProgrammer and read the NRST_MODE, it is 3. I change it to 2 and run my code, I find the mcu no longer reset when PG10-NRST comes to low level even though I will change NRST_MODE to 3 in my project which means PG10-NRST will work as a reset pin.

I guess that the field NRST_MODE will follow the factory setup which is 3 when mcu power up, then it modified by the user code.

1.But why it still reset when I modify the NRST_MODE to 2 in my project?

2.How to config PG10-NRST as a GPIO by user code, because I can't change it using STM32CubeProgrammer one by one when there is a mass production?

This topic has been closed for replies.
Best answer by TDK

You need to launch the option bytes in order for them to update.

Call HAL_FLASH_OB_Launch immediately after the HAL_FLASHEx_OBProgram call, which will reset the chip and update option bytes.

The proper way to do this would be to read the current value and if it needs changed, then change it and reset. Else continue on with the program.

2 replies

TDK
TDKBest answer
January 10, 2022

You need to launch the option bytes in order for them to update.

Call HAL_FLASH_OB_Launch immediately after the HAL_FLASHEx_OBProgram call, which will reset the chip and update option bytes.

The proper way to do this would be to read the current value and if it needs changed, then change it and reset. Else continue on with the program.

"If you feel a post has answered your question, please click ""Accept as Solution""."
fhu.11
fhu.11Author
Associate III
January 11, 2022

Thanks, you succeed resolving my question!

Dose HAL_FLASH_OB_Launch modify the default value of NRST_MODE in the factory rom? Because every times I reset my mcu before I call HAL_FLASH_OB_Launch, the option bytes is the default value.

TDK
January 11, 2022
ROM can't be changed. Nothing is writing to ROM.
Calling HAL_FLASH_OB_Launch applies the settings you've changed, if any.
"If you feel a post has answered your question, please click ""Accept as Solution""."
Peter BENSCH
Technical Moderator
January 10, 2022

What STM32 are you talking about?

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
fhu.11
fhu.11Author
Associate III
January 11, 2022

STM32G491RE​