2019-01-04 10:47 PM
Hi,
I am trying to program the option byte in STM8S003 controller. I am able to do the same using STVP tool. It is not a practical method on production, so want to add the option byte config in the source code. for that I added the below code snippet. But it is not happening properly. Please help me to fix this issue, correct me if I am doing wrong.
#define AFR_OPTION_BYTE_ADDR 0x4803
#define AFR0_ENABLE 0x01
void set_afr0_option_bit(void)
{
uint16_t option_status;
uint8_t option_byte=0;
option_status=FLASH_ReadOptionByte(AFR_OPTION_BYTE_ADDR);
printf("\n\rOption Byte Status = %04x ",option_status);
if(!(option_status & 0x0100))
{
//option_status |= 0x0100;
option_byte = (uint8_t) AFR0_ENABLE;
FLASH_ProgramOptionByte(AFR_OPTION_BYTE_ADDR, (uint8_t)AFR0_ENABLE);
printf("\n\rOption Byte updated successfully = %02x ",AFR0_ENABLE);
}
option_status=0;
option_status=FLASH_ReadOptionByte(AFR_OPTION_BYTE_ADDR);
printf("\n\rOption byte status %04x ",option_status);
}
The debug output is
------------------------------------
Option Byte Status = 00ff
Option Byte updated successfully = 01
Option byte status 00ff