2022-01-10 07:01 AM
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?
Solved! Go to Solution.
2022-01-10 07:06 AM
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.
2022-01-10 07:06 AM
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.
2022-01-10 07:07 AM
What STM32 are you talking about?
2022-01-10 04:10 PM
STM32G491RE
2022-01-10 05:05 PM
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.
2022-01-10 05:48 PM
2022-01-10 10:27 PM
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
I 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.
2022-01-11 06:44 AM
> 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.