On 2019-11-09 09:29, Shivakumar R via Sdcc-user wrote: > The SPL example does not mention anything about changing the values of > the option bytes, but I see that in my STM8S003F3P6 chip(20 pin tssop) I > need to set the AFR0 bit of OPT2 (as well as NOPT2) to use the TIM1Ch2 > alternate function.
> #define P6_OPT2 0x4803 > #define P6_NOPT2 0x4804 > #define P6_AFR0 0x01 > _SFR_(P6_OPT2) |= P6_AFR0; > _SFR_(P6_NOPT2) &= ~P6_AFR0; You need to unlock the option byte before you can write to it. Here is what I use to enable the alternate function on STM8S105. It should be the same for STM8S003. Cheers, -Richard /****************************************************************************** * * Set remapping for output channel 3 on STM8S105K * in: 0 = no, 2 = yes */ static void set_remap(char val) { char cfg; eeprom_unlock(); FLASH_CR2 = 0x80; /* enable option byte */ FLASH_NCR2 = 0x7f; cfg = OPT2; cfg &= 0xfd; cfg |= val; OPT2 = cfg; NOPT2 = ~cfg; eeprom_lock(); } /****************************************************************************** * * Unlock EEPROM for writing * out: zero = fail */ #pragma disable_warning 59 char eeprom_unlock(void) { __asm mov _FLASH_DUKR, #0xae mov _FLASH_DUKR, #0x56 clr a 00001$: dec a jreq 00090$ btjf _FLASH_IAPSR, #3, 00001$ 00090$: __endasm; } /****************************************************************************** * * Lock EEPROM from writing after write */ void eeprom_lock(void) { __asm bres _FLASH_IAPSR, #3 __endasm; } _______________________________________________ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user