How to Implement CH3 Channel PWM Output IO Multiplexing with Option Byte

Functional realization goals

The PWM output IO multiplexed on the CH3 channel of the TIM2 is implemented by writing to the option byte and can be set to the PA3 or PD2 output.

Operate the link via STVP

Option byte

The option bytes include the configuration of the hardware features of the chip and the memory protection information. These bytes are stored in a dedicated block in memory. In addition to the ROP (readout protection) byte, each option byte must be saved twice, one for the usual format (OPTx) and one for backing up the complementary format (NOPTx). The option byte can be modified by the application in IAP mode, but the ROP option can only be modified in ICP mode (via SWIM). Refer to the STM8S Flash Programming Manual (PM0051) and the STM8 SWIM Communication Protocol and Debug Module User's Manual (UM0470) for the SWIM programming process.

The size of the option bytes of different chips is different. For details, refer to the chip data sheet. For example, with STM8S103F3, the option bytes are as follows:

How to Implement CH3 Channel PWM Output IO Multiplexing with Option Byte

STM8S103F multiplexing function for 20-pin packaged products:

How to Implement CH3 Channel PWM Output IO Multiplexing with Option Byte

It can be seen that we want to write the AFR1 bit in the OPT2 byte. By writing 0, the port A3 multiplexes the function TIM2_CH3, and by writing 1, the port D2 multiplexes the function TIM2_CH3. Then through the program to achieve this function, you can modify the value of AFR1 to see if the PWM output switches the pin, and if so, it is a write operation.

The option byte is stored in EEPROM, so the option byte can be modified by reading and writing the EEPROM. Applications can write directly to the target address. The address from the above figure we already know: 0x4803, 0x4804. The register configuration can be found in the reference manual (RM0016).

Related register operations:

How to Implement CH3 Channel PWM Output IO Multiplexing with Option Byte

How to Implement CH3 Channel PWM Output IO Multiplexing with Option Byte

Test program implementation

Note: When you implement the program to erase OpTIon Bytes, you cannot run the application. Otherwise, an error will occur! But still feel this trouble, ah, might as well use STVP to erase, if it can be placed in the application coexistence to erase it just fine, using programs to achieve reuse is so troublesome? I hope I can explore ways to find a good solution. At the end, I only found one that is not reliable. I just added a delay after erasing, but this time it doesn't work. Or read the data to see what is going on?

How to Implement CH3 Channel PWM Output IO Multiplexing with Option Byte

However, this error was encountered when erasing with STVP:

Error : Error on Option Bytes (complementary bytes). Reprogram Option Bytes of device

Error : " OPTION BYTE verifying failed.

123

Use STVP to erase Option Bytes. First set ROP to ON, and then write Option Bytes. Two prompt boxes appear. Select Yes, and then set ROP to OFF again to erase Option Bytes. , you can use STVD to write programs through stlink and simulation.

How to Implement CH3 Channel PWM Output IO Multiplexing with Option Byte

How to Implement CH3 Channel PWM Output IO Multiplexing with Option Byte

How to Implement CH3 Channel PWM Output IO Multiplexing with Option Byte
How to Implement CH3 Channel PWM Output IO Multiplexing with Option Byte
How to Implement CH3 Channel PWM Output IO Multiplexing with Option Byte
How to Implement CH3 Channel PWM Output IO Multiplexing with Option Byte

VOME BOX

Quick Description :
☑ Salt Nicotine:5%/3%/2%/0%
☑ Puffs:7500
☑ Capacity:15ml
☑ 240 pcs per carton
☑10 flavors available
☑ 850mah Rechargeable
☑ Mesh Coil
Flavor List:
1.Pina Colada
2.Pink Lemonade
3.Strawberry Mango
4.Mixed Berries
5.Tangerine Ice
6.Lychee Lemon
7.Gummy Bear
8.Cool Mint
9.Cuba Tobacco

10.Hawaii Coffee

1

Vome Box,7500 Puffs Disposable Vape ,850Mah Rechargeable ,Air Bars Disposable

Shenzhen Kester Technology Co., Ltd , https://www.kesterpuff.com