AnsweredAssumed Answered

Setting RDP back to level 0 error

Question asked by kovaliov.nikolaj on Dec 6, 2014
Latest reply on Dec 7, 2014 by kovaliov.nikolaj
I want to be able to set RDP level from my code from 0 to 1 and backwards.
Is it possible?

After setting RDP to level 1 I am unable to set it back to 0, only through ST-Link.

Here some test code I made.
     
01.uint8_t SetRDPF4(uint8_t OB_RDP_Level)
02.{
03.  FLASH_Status FLASHStatus = FLASH_COMPLETE;
04.  
05.  FLASH_Unlock();
06.  
07.  FLASH_OB_Unlock();
08.   
09.    FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR | FLASH_FLAG_BSY);
10.     
11.  if (!FLASH_OB_GetRDP())
12.  {
13.    FLASH_OB_RDPConfig(OB_RDP_Level); // level 0 unlocks, level 1 locks, level 2 kills chip
14.  
15.    if (FLASH_OB_Launch() != FLASH_COMPLETE)
16.   {
17.      printf("\nSET OB RDP ERROR!");
18.      return 1;
19.   }
20.      
21. if(OB_RDP_Level == OB_RDP_Level_0)printf("\nSet to: OB_RDP_Level_0");
22. if(OB_RDP_Level == OB_RDP_Level_1)printf("\nSet to: OB_RDP_Level_1");
23.      
24.  }
25.     
26.    FLASH_Lock();
27.  
28.  FLASH_OB_Lock();
29.     
30.    return 0;
31.}
32. 
33. 
34.     
35.int main(void)
36.{
37.uint8_t counter = 1;
38.STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO);
39.if(SysTick_Config(SystemCoreClock / 1000)){while (1);}
40. 
41.DBGU_Init();
42.printf("\nstart");
43.     
44.while(1){
45.if ((STM_EVAL_PBGetState(BUTTON_USER) == 0x01) && (counter == 0x01)){SetRDPF4(OB_RDP_Level_0); counter = 2; mdelay(500);} //first time button press set to level 0
46. 
47.if ((STM_EVAL_PBGetState(BUTTON_USER) == 0x01) && (counter == 0x02)){SetRDPF4(OB_RDP_Level_1); counter = 1; mdelay(500);} //second time button press set to level 1
48.}//end of while 1
49. 
50.}


Thank you,

//Nikolaj

Outcomes