0

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
  • To be clear the option byte is for readout protection rather than read protection. That is when set, you cannot read the flash via the debug/programming port. It does not prevent reading by the code executing on the part - given that the code is executed from that same flash, you clearly cannot stop the core processor from reading it. Commented Sep 21, 2023 at 6:09

1 Answer 1

0

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?

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer,I have problem in ICP modeAs shown in the picture. Yes I think it is correct. Yeah,after reset it is like before it.My problem is that readout protection doesnt apply.I used STVP programming toolkit to make my own programming software.
After setting the ROP byte try reading it back. If it is 0xAA ROP is enabled and it will be impossible to read the FLASH via ICP. just to be clear, ICP is the SWIM interface stlink connects to. I doubt the ROP byte is actually getting set. Did you set the OPT bit?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.