cancel
Showing results for 
Search instead for 
Did you mean: 

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 level.

fhu.11
Associate II

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?

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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".

View solution in original post

7 REPLIES 7
TDK
Guru

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".
Peter BENSCH
ST Employee

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.

STM32G491RE​

fhu.11
Associate II

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.

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".

When I just call HAL_FLASHEx_OBProgram, I find the NRST_MODE in Flash_OPTR is already changed to 2. Why it doesn't work?

I check the reference manual and find some description as follow

0693W00000HrBZfQAN.pngI don't know how to understand internal option register. What is the difference between internal option register and Flash_OPTR I saw in the debug window?

I thought the Flash_OPTR like a display register, it's just a copy value of internal OPTR and direct modification is invalid. Only change internal OPTR will actually config the chip and I thought the internal OPTR was in ROM. It looks like I am wrong.

Please tell me the option bytes config procedure, when and where.

> Please tell me the option bytes config procedure, when and where.

Didn't I already do that in my first reply? You need to launch the option bytes in order to apply them, as described in the "Option byte loading" section you've highlighted.

The OPTR registers provide the interface to the option bytes, not the option bytes themselves.

If you feel a post has answered your question, please click "Accept as Solution".