2020-07-05 12:22 AM
I am using STM8AF6288TC and I face Error on Option bytes (Complementary bytes). Reprogram option bytes of device, Error Some times, I reprogram option bytes :-
1.In ROP select read out protection ON.
2.Then program current tab only.
3. Now again in ROP select read out protection OFF.
4. program current tab.
After that ECU recovers from this problem.
But what is the reason behind this error
1. Is STVP causes this error ? (I am using STVP 3.4.1 . I am using IAR Also for debug mode. )
2. Is code causes this error ?
part of my code where I modify option bytes :
/* write unlock keys */
FLASH->DUKR = 0xAE;
FLASH->DUKR = 0x56;
/* Check for write protection has been disabled
* by writing the correct MASS keys */
while(FALSE ==((FLASH->IAPSR)&(FLASH_IAPSR_DUL)))
{
;
}
/* Enabled Write access to option bytes */
FLASH->CR2 |= (uint8)(1u << 7u);
FLASH->NCR2 &= ~((uint8)(1u << 7u));
/* Select port D2 alternate function TIM2_CH3 */
OPT->OPT2 |= (uint8)(1u <<1u);
OPT->NOPT2 &= ~((uint8)(1u <<1u));
/* Check for End of programming flag */
while(FALSE == ((FLASH->IAPSR) & FLASH_IAPSR_EOP))
{
;
}
/*Lock EEPROM*/
FLASH->IAPSR &= ~(FLASH_IAPSR_DUL);
and Immediately after this perform watchdog reset