How to protect my application code read from MCU?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2021-03-26 4:55 AM
I want to protect my code by writing OB using HAL
bool SetFlashReadProtection(bool state)
{
FLASH_OBProgramInitTypeDef OptionsBytesStruct = {0};
HAL_FLASHEx_OBGetConfig(&OptionsBytesStruct);
if(state == true)
{
if(OptionsBytesStruct.RDPLevel == OB_RDP_LEVEL_0)
{
OptionsBytesStruct.OptionType = OPTIONBYTE_RDP;
OptionsBytesStruct.RDPLevel = OB_RDP_LEVEL_1;
HAL_FLASH_OB_Unlock();
if(HAL_FLASHEx_OBProgram(&OptionsBytesStruct) != HAL_OK)
{
HAL_FLASH_OB_Lock();
return false;
}
HAL_FLASH_OB_Lock();
}
}
else
{
if(OptionsBytesStruct.RDPLevel == OB_RDP_LEVEL_1)
{
OptionsBytesStruct.OptionType = OPTIONBYTE_RDP;
OptionsBytesStruct.RDPLevel = OB_RDP_LEVEL_0;
HAL_FLASH_OB_Unlock();
if(HAL_FLASHEx_OBProgram(&OptionsBytesStruct) != HAL_OK)
{
HAL_FLASH_OB_Lock();
return false;
}
HAL_FLASH_OB_Lock();
}
}
return true;
}
and call this SetFlashReadProtection(true) function inside void main but still my code is redable so at which place i can call this function?
This discussion is locked. Please start a new topic to ask your question.
0 REPLIES 0
