2024-11-19 01:06 AM
Hello,
I need to use a nRST pin as MCO in my aplication and programm my STM with STlink v3-set. I set up a MCO to output 8MHz signal and set nRST pin to GPIO with code you can see bellow. Now I have a problem with booting - I cannot connect to STM, CubeProgrammer have a error: 10:00:55 : Error: Data read failed
Can you please help me, how to fix that? I tried to used software reset, which does not help.
btw I can connect to STM only via STlink - I made a custom PCB for my application
Thank you
HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();
OBInit.OptionType = OPTIONBYTE_USER;
OBInit.USERType = OB_USER_NRST_MODE;
OBInit.USERConfig = FLASH_OPTR_NRST_MODE_1;
HAL_FLASHEx_OBProgram(&OBInit);
HAL_FLASH_OB_Launch();
HAL_FLASH_OB_Lock();
HAL_FLASH_Lock();
Solved! Go to Solution.
2024-11-19 02:28 AM
Unless you have disabled SWDIO or SWCLK, the debug connection should still work - no hardware reset is neede. Set the debug interface to reset method - sysresetrq, normal connection of live/hot connection.
2024-11-19 02:28 AM
Unless you have disabled SWDIO or SWCLK, the debug connection should still work - no hardware reset is neede. Set the debug interface to reset method - sysresetrq, normal connection of live/hot connection.
2024-11-19 02:32 AM
11:31:31 : Debug in Low Power mode is not supported for this device.
11:31:32 : UPLOADING OPTION BYTES DATA ...
11:31:32 : Bank : 0x00
11:31:32 : Address : 0x40022020
11:31:32 : Size : 84 Bytes
11:31:32 : UPLOADING ...
11:31:32 : Size : 1024 Bytes
11:31:32 : Address : 0x8000000
11:31:32 : Read progress:
11:31:32 : Error: Data read failed
2024-11-19 02:36 AM
So the debug connection is basically working. Try to restore the factory settings - reset option bytes and do a full chip erase, then play again, more carefully.
2024-11-19 03:00 AM
Thank you,
can you please me with reseting memory? I am kinda lost...
I set NRST_MODE back to 1, as you can see bellow
Then I tried to erase flash memory, but it give me a error
2024-11-19 03:05 AM
I figured out, how it works, so thank you for help.
Anyway, what should I do to properly activate MCO instead of nRST on my STM, but still keep debugger functional? I read something about delay (or timer?) before changing nRST to MCO...
2024-11-19 03:52 AM
If you keep SWD enabled, nRST is not needed for debugging/programming at all. (But there is a quirk with Cortex-M0+ MCUs - you can't connect if the MCU is put to sleep without frequent interrupts.) If you need to use SWD pins for some other function, then set their function few seconds after the code starts, so that you have a chance to connect the debugger right after powering on the device.
My usual solution is to enable SleepOnExit and change SWD pins functions after approx. 5 seconds, in timer interrupt handler (I almost never use "main loop" approach in my projects).
Unfortunately, in STM32 it's not possible to disable nRST in software; it must be done permanently with option bytes. The urban legend says that it's still enabled during poweron before option bytes are loaded - I have to check it practically some day on my bricked G030J. ;)