cancel
Showing results for 
Search instead for 
Did you mean: 

Broken device through optoin bytes

machinist
Associate III

Hello,

I am currently fiddling around with a STM32G491 in bare metal. I wanted to test the write protection. So I executed following code

 

 

 

 

 

 

 

	FLASH->KEYR = FLASH_KEY1;
	FLASH->KEYR = FLASH_KEY2;
	while(FLASH->CR&bit31);		// wait for unlock
	FLASH->OPTKEYR = FLASH_OPTKEY1;
	FLASH->OPTKEYR = FLASH_OPTKEY2;
	while(FLASH->CR&bit30);		// wait for option unlock
	//#define PROTECT(start, end)	FLASH->WRP1AR = (((start>>11)&0xFF)|(((end>>11)&0xFF)<<16))
	PROTECT(0x5000, 0x6000);
	FLASH->CR |= bit17;			// option start 
	while(FLASH->CR&bit17);		// wait for option done
	FLASH->CR |= bit27;			// option load 
	while(FLASH->CR&bit27);		// wait for option reload done
	FLASH->CR |= bit30;			// lock option
	FLASH->CR |= bit31;			// lock 

 

 

 

 

 

 

 

Just to note my code worked fine (except the locking) until I added line 12. It seems the OB_LAUNCH bit is never reset to 0.

The problem is now that I can not reach my device any more. I am connected through SWD via STlinkV2 with a hardware reset connectd. But none of the connection methods works any more using STProg or STCubeIDE. Not even connect under reset works. How can that be? Is there anything I can do to erase it?

Edit: the error I get is

Target no device found

 

Error in initializing ST-LINK device.

Reason: No device found on target.

1 ACCEPTED SOLUTION

Accepted Solutions

Is it stuck running this code again? 

Try pulling BOOT0 High?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

3 REPLIES 3

Is it stuck running this code again? 

Try pulling BOOT0 High?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks for the reply. But it didnt do anything pulling boot0 to high. Also not when trying to connect while Boot0 is high.

I hooked up a logic analyzer to the reset line. I see ~3,8ms high pulse every ~140ms. The reset is low otherwise. Also when the STLink is not connected these pulses are there.

This pattern does not change if the STlink is connected and I try to connect under reset. Shouldn't the STlink pull the reset low in order to connect?

machinist
Associate III

Working again. Seems fiddeling with the Boot0 pin high and low while connecting somehow anabled STprog to connect.

Thanks.