How to write option bytes in assembly language for stm8 mcu in stvd developer using cosmic compiler.
I have to set Read out protection without using the stvp programmer.
If you translate this bit of Forth into assembly, then here is how to do it.
Note that "\ .." and "( .. )" are comments. Data is passed through the data stack, and you can probably keep it in registers when coding it in assembly.
\ STM8S option setting words
\ refer to github.com/TG9541/stm8ef/blob/master/LICENSE.md
\ store char c to (a), inverted value to (a+1)
: CN! ( c a -- )
2DUP C! SWAP NOT SWAP 1+ C! ;
\ unlock write protection, store option byte
: OPT! ( c a -- )
FLASH_CR2 DUP C@ $80 OR SWAP CN! \ unlock option bytes
ULOCK CN! LOCK \ unlock EEPROM, write c to (a) ;
\\ ULOCK and LOCK from forth.asm:
; LOCK ( -- )
; Lock EEPROM (STM8S)
HEADER LOCK "LOCK"
HEADER ULOCK "ULOCK"
1$: BTJF FLASH_IAPSR,#3,1$ ; PM0051 4.1 requires polling bit3=1 before writing
will this work ?
LOCKBYTE:dc.b 0AAh; Read out Bytes
OPT1:dc.b 000hNOPT1:dc.b 0ffh
OPT2:dc.b 081hNOPT2:dc.b 07eh
OPT3:dc.b 000hNOPT3:dc.b 0ffh
OPT4:dc.b 000hNOPT4:dc.b 0ffh
OPT5:dc.b 000hNOPT5:dc.b 0ffh
OPT6:dc.b 000hNOPT6:dc.b 0ffh
OPT7:dc.b 000hNOPT7:dc.b 0ffh
No, I don't think that this will work. You can't program the option bytes without unlocking the EEPROM first, and that's something a flash tool won't do while flashing the device.
You need to solve it either it on the tool chain level (using a programmer like ST-Link), or using IAP (in application programming) with the procedure laid out in PM0051 Chapter 4.1. That's what the code above does. It's likely that there is also a STM8 library function to do it.
Retrieving data ...