2021-07-26 03:38 AM
Hello,
I am facing problem where ST link is not able to detect the MCU.
My board was programmed and functional but for some reason we have to change the code and we programmed the hex file.
Afterwards that MCU is not being detected in STLINK tool/STM cube programmer and also the code execution is not happening.
This problem I faced in 14 out of 60 boards those we programmed using the same hex file.
It is not a hardware problem. I am 100% sure but I checked again and no issue found.
My code has read protection level-1 before main loop as shown below and I am doubting on it. In any case if it is doing read protection level-2 then MCU will no longer accessible.
FLASH_OBProgramInitTypeDef OBInit;
void enable_read_protection(void)
{
HAL_FLASHEx_OBGetConfig(&OBInit);
if(OBInit.RDPLevel == OB_RDP_LEVEL_0)
{
/* Unlock the Flash to enable the flash control register access *************/
HAL_FLASH_Unlock();
/* Unlock the Options Bytes *************************************************/
HAL_FLASH_OB_Unlock();
OBInit.OptionType = OPTIONBYTE_RDP;
OBInit.RDPLevel = OB_RDP_LEVEL_1;
HAL_FLASHEx_OBProgram(&OBInit);
if (HAL_FLASH_OB_Launch() != HAL_OK)
{
/* User can add here some code to deal with this error */
HAL_FLASH_OB_Lock();
HAL_FLASH_Lock();
while (1)
{
}
}
}
HAL_FLASH_OB_Lock();
HAL_FLASH_Lock();
}
I will be really thankful if you can point out something.
Thanks
2021-08-01 12:07 AM
Hello,
Looking for your help! Please let me know if I should try anything.
I am stuck.
Thanks.