2014-11-10 06:03 AM
Hi,
I'm having a problem with the CMSIS peripheral library call to set Readout Protection on STM32F10x: I call FLASH_ReadOutProtection(ENABLE) I have put a flag into this function to verify that it's setting OB->RDP = 0x00 everything seems fine, except... it doesn't set readout protection. Even after a power cycle, when I call FLASH_GetReadOutProtectionStatus() I get a result 0 This is corroborated using STLink-V2 Any ideas? #rdp #readout-protection2014-11-10 08:36 AM
Hi Henry,
Did you tried to use the ST-Link Utility?This can help yo to confirm if issue is in hardware side or firmware one.-Mayla-To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2014-11-10 09:07 AM
Try doing it without the debugger attached, and pay attention to flags and status
void Flash_ReadOutProtection(int x) // 0=Status, 1=Lock, 2=Unlock - sourcer32@gmail.com
{
printf(''Flash_ReadOutProtection :
'');
if (FLASH_GetReadOutProtectionStatus())
printf(''Read Out Protected
'');
else
printf(''Read Out Un-Protected
'');
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);
if (x == 1)
{
printf(''Attempting to lock
'');
if (FLASH_GetReadOutProtectionStatus() != SET)
{
if (FLASH_ReadOutProtection(ENABLE) == FLASH_COMPLETE)
printf(''Read Out Passed
'');
else
printf(''Read Out Failed
'');
}
printf(''Cycle Power Now!
'');
Debug_Flush(); // Ensure telemetry clears threshold
while(1);
// NVIC_GenerateSystemReset();
}
else if (x == 2)
{
printf(''Attempting to unlock, Cycle Power Now!
'');
Debug_Flush();
FLASH_ReadOutProtection(DISABLE); // If it succeeds it nukes the part, not coming back here
}
}
2014-11-10 09:48 AM
Hi,
thanks - Mayla, yes I tested using STLink_V2, which confirmed it was a firmware problem. Clive, yes I was looking at all the flags and status returned, all looked as I would expect; the ONLY things that were wrong were that FLASH_GetReadOutProtectionStatus() was reporting 0 (not protected) and this was confirmed using ST-Link (i.e. independent and reliable means). I did try with the debugger disconnected, same result. What I have now noticed though, looking at your code - was that I was missing ''FLASH_Unlock()''. Looking at the code for FLASH_ReadOutProtection() it seemed as though it was setting keys to authorize access, but in fact it's only authorizing access to the Option bytes. I needed FLASH_Unlock() to unlock the FPEC first!!! So now it all works. Thanks!