cancel
Showing results for 
Search instead for 
Did you mean: 

Setting RDP back to level 0 error

hitsumen
Associate II
Posted on December 06, 2014 at 12:15

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.


uint8_t SetRDPF4(uint8_t OB_RDP_Level)

{

FLASH_Status FLASHStatus = FLASH_COMPLETE;


FLASH_Unlock();


FLASH_OB_Unlock();


FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR | FLASH_FLAG_BSY);


if
(!FLASH_OB_GetRDP())

{

FLASH_OB_RDPConfig(OB_RDP_Level); 
// level 0 unlocks, level 1 locks, level 2 kills chip 


if
(FLASH_OB_Launch() != FLASH_COMPLETE)

{

printf
(
''\nSET OB RDP ERROR!''
);

return
1;

}


if
(OB_RDP_Level == OB_RDP_Level_0)
printf
(
''\nSet to: OB_RDP_Level_0''
);

if
(OB_RDP_Level == OB_RDP_Level_1)
printf
(
''\nSet to: OB_RDP_Level_1''
);


} 


FLASH_Lock();


FLASH_OB_Lock();


return
0;

}




int
main(
void
)

{

uint8_t counter = 1;

STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO);

if
(SysTick_Config(SystemCoreClock / 1000)){
while
(1);}


DBGU_Init();

printf
(
''\nstart''
);


while
(1){

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


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

}
//end of while 1


}

Thank you,

//Nikolaj

2 REPLIES 2
hitsumen
Associate II
Posted on December 07, 2014 at 18:23

Ah, after setting to 1 its impossible set to 0 from flash, because after setting to 1->0 flash should be mass erased, right?

One more thing, why after setting to 0->1 cpu freezes, only power switch make my code run? 

hitsumen
Associate II
Posted on December 07, 2014 at 21:29

I figured that out, there is something with reset pin on my discovery board, if I remove SWD programmer, it works.