2017-10-24 10:04 PM
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.
2017-10-24 10:55 PM
Hi!
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'
LOCK:
BRES FLASH_IAPSR,#3
RET
HEADER ULOCK 'ULOCK'
ULOCK:
MOV FLASH_DUKR,#0xAE
MOV FLASH_DUKR,#0x56
1$: BTJF FLASH_IAPSR,#3,1$ ; PM0051 4.1 requires polling bit3=1 before writing
RET
2017-10-25 01:32 AM
will this work ?
org 04800h
LOCKBYTE:dc.b 0AAh; Read out Bytes
OPT1:dc.b 000h
NOPT1:dc.b 0ffhOPT2:dc.b 081h
NOPT2:dc.b 07ehOPT3:dc.b 000h
NOPT3:dc.b 0ffhOPT4:dc.b 000h
NOPT4:dc.b 0ffhOPT5:dc.b 000h
NOPT5:dc.b 0ffhOPT6:dc.b 000h
NOPT6:dc.b 0ffhOPT7:dc.b 000h
NOPT7:dc.b 0ffhend
2017-10-25 10:20 AM
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
Chapter 4.1. That's what the code above does. It's likely that there is also a STM8 library function to do it.