Stm8 Option Byte Programming

231 Views Asked by At

I want to program "Option Byte" on STM8S005k6 without stvp. I do it by programming its code on Option Byte area but this makes it write protected only, not read protected:

     void Read_Protect_Flash(void)
     {
         FLASH_SetProgrammingTime(FLASH_PROGRAMTIME_STANDARD);
        // FLASH_SetProgrammingTime(FLASH_PROGRAMTIME_STANDARD);    
        while(FLASH_ReadOptionByte(0x4800) != 0xAA)
     {
        FLASH_Unlock(FLASH_MEMTYPE_DATA);

        FLASH_EraseOptionByte(0x4800);
        FLASH_ProgramOptionByte(0x4800, 0xAA);
   
        FLASH_Lock(FLASH_MEMTYPE_DATA);
       }
     }

When I program it directly using IAR, it works. But when I program the functioning code on "PROGRAM MEMORY" area and the above code on "OPTION BYTE" area I just get write protection and not read protection. What should I do?

1

There are 1 best solutions below

2
Maximilian On

When ROP is enabled read/write access is denied for SWIM (ICP in circuit programming) but not for the MCU itself (IAP in application programming)

The only exception is the option bytes, which are handled specially.

in the reference manual you can find this table that confirms this:

enter image description here

RM0016 STM8S005k6 reference manual

Which are you having problems with? IAP or ICP? Are you sure that the code is executed correctly and that the ROP byte is really set to 0xAA? is the ROP still incorrect after a power on reset?