AN3342 Application note Getting started with STM8TL5xxx Introduction This application note complements the information in the STM8TL5xxx datasheets by describing the minimum hardware and software environment required to build an application around an STM8TL5xxx 8-bit microcontroller device. A brief description of the principal hardware components is given. The power supply, reset control and ProxSense lines are described in some detail. In addition, some hardware recommendations are given. This application note also contains detailed reference design schematics with descriptions of the main components. The STM8 development tools and software toolchain are common to STM8TL5xxx, STM8L, STM8S and STM8A and are presented in Section 9, and 10. Section 11 describes how to set up the STM8 development environment. Finally, Section 12 provides a list of relevant documentation and online support resources. Table 1. September 2012 Applicable products Type Product sub-class Microcontroller STM8TL5xxx Doc ID 18461 Rev 3 1/39 www.st.com Contents AN3342 Contents 1 Hardware requirements summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2 Power supply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3 2.1 Power supply overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.2 Main operating voltages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.3 Power-on/power-down reset (POR/PDR) . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Clock management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.1 4 Reset control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 4.1 4.2 5 6 Internal clocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Reset management overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 4.1.1 Output characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 4.1.2 Input characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Hardware reset implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 ProxSense line management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 5.1 ProxSense line management overview . . . . . . . . . . . . . . . . . . . . . . . . . . 13 5.2 Hardware ProxSense implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Recommendations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 6.1 Printed circuit board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 6.2 Component position . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 6.3 Ground and power supply (VSS, VDD, VSSIO, VDDIO) . . . . . . . . . . . . . . . . 16 6.4 Decoupling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 6.5 Other signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 6.6 Unused I/Os and features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 6.6.1 7 2/39 20-pins package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Reference design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 7.1 Component references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 7.2 Schematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Doc ID 18461 Rev 3 AN3342 8 9 Contents STM8TL5x firmware libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 8.1 STM8TL5x standard peripheral library . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 8.2 STM8TL5x STMTouch library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 8.3 Online help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 STM8 development tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 9.1 9.2 10 11 Single wire interface module (SWIM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 9.1.1 SWIM overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 9.1.2 SWIM connector pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 9.1.3 Hardware connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 RLink and STLink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 STM8 software toolchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 10.1 Integrated development environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 10.2 Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Setting up the STM8 development environment . . . . . . . . . . . . . . . . . 27 11.1 Installing the tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 11.2 Using the tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 11.2.1 11.3 Project editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Running the demonstration software . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 11.3.1 Compiling the project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 11.3.2 Selecting the correct debug instrument . . . . . . . . . . . . . . . . . . . . . . . . . 31 11.3.3 Connecting the hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 11.3.4 Starting the debug session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 11.3.5 Running the software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 11.3.6 Follow up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 12 Documentation and online support . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 13 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Doc ID 18461 Rev 3 3/39 List of tables AN3342 List of tables Table 1. Table 2. Table 3. Table 4. 4/39 Applicable products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Component list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 SWIM connector pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Doc ID 18461 Rev 3 AN3342 List of figures List of figures Figure 1. Figure 2. Figure 3. Figure 4. Figure 5. Figure 6. Figure 7. Figure 8. Figure 9. Figure 10. Figure 11. Figure 12. Figure 13. Figure 14. Figure 15. Figure 16. Figure 17. Figure 18. Figure 19. Figure 20. Figure 21. Figure 22. Figure 23. Power supply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Typical layout of VDD/VSS pair . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Reset management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Output characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Input characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 ProxSense management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Touch key layout example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Reference design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 STM8TL5x standard peripheral driver online help manual . . . . . . . . . . . . . . . . . . . . . . . . . 21 STM8TL5x STMTouch driver online help manual. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 STM8TL5x STMTouch Examples online help manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Debug system block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Hardware connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 STM8 software toolchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 STVD open example workspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 STVD MCU edit mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 STVD: Building the project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 STVD: Selecting the debug instrument. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 STM8TL53 Touch keypad in standalone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 STM8TL53 Touch keypad Evaluation board and STMT-BOX™ Display board . . . . . . . . . 33 STM8TL53 Touch keypad with the STMT-BOX™ Display board and Isolation board . . . . 34 STVD: Starting the debug session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 STVD: Run the software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Doc ID 18461 Rev 3 5/39 Hardware requirements summary 1 AN3342 Hardware requirements summary To build an application around an STM8TL5xxx device, the application board should provide the following features: ● Power supply (mandatory) ● Reset management (optional) ● ProxSense line management (optional) ● Debugging tool support: Single wire interface module (SWIM) connector (optional) 2 Power supply 2.1 Power supply overview The STM8TL5xxx needs to be powered by a 1.65 V to 3.6 V external source. An on-chip power management system provides the constant digital supply to the core logic, both in normal and low power modes. This ensures that the logic consumes a constant current level over the voltage range. It is also capable of detecting voltage drops and generate a reset to avoid erratic behavior. The STM8TL5xxx device provides: ● One pair of power supply pins (VDD/VSS) for the main operating voltage (1.65 V to 3.6 V). ● Another pair of power supply pins (depending of package) (VDDIO/VSSIO) for the IOs (1.65 V to 3.6 V) The STM8TL5xxx device manages the supply voltage needed by the ProxSense interface by connecting a 1 µF capacitor low ESR ( 1 ) to the PXS_VREG pin (see Figure 1). 6/39 Doc ID 18461 Rev 3 AN3342 Power supply Figure 1. Power supply NRST PXS_VREG 1 μF VDD + VSS VDD VDDIO 3.6 V – 1.65 V (see note 1) + 1 μF 100 nF 100 nF VSSIO VSS VSS MS18954V1 1. The device keeps operating as long as the battery voltage is above 1.65 V and no reset is generated. Note: The capacitors must be connected as close as possible to the device power supply pins (VDDx pins). The decoupling capacitor must be connected as close as possible to the ground pins (VSSx pins). 2.2 Main operating voltages The STM8TL5xxx devices embed an internal voltage regulator for generating the 1.8 V power supply for the core and peripherals and a second internal voltage regulator providing a stable power supply (around 1.55 V) for the ProxSense peripheral. Doc ID 18461 Rev 3 7/39 Power supply 2.3 AN3342 Power-on/power-down reset (POR/PDR) The input supply to the main and low power regulators is monitored by a power-on/powerdown reset circuit. The monitoring voltage begins at 0.7 V. During power-on, the POR/PDR keeps the device under reset until the supply voltage (VDD) reach its specified working area. This internal reset is maintained for a period of ~1ms in order to wait for supply stabilization. At power-on, a defined reset should be maintained below 0.7 V. The upper threshold for a reset release is defined in the electrical characteristics section of the product datasheets. A hysteresis is implemented (POR > PDR) to ensure clean detection of voltage rise and fall. The POR/PDR also generates a reset when the supply voltage drops below the VPOR/PDR threshold (isolated and repetitive events). Recommendations All VDD and VSS pins including VDDIO and VSSIO need to be properly connected to the power supplies. These connections, including pads, tracks and vias should have the lowest possible impedance. This is typically achieved with thick track widths and preferably dedicated power supply planes in multi-layer printed circuit boards (PCBs). In addition, the power supply pair should be decoupled with filtering ceramic capacitors (C) at 100 nF with one chemical C (1..2 µF) in parallel on the STM8TL5xxx device. The ceramic capacitors should be placed as close as possible to the appropriate pins, or below the appropriate pins, on the opposite side of the PCB. Typical values are 10 nF to 100 nF, but exact values depend on the application needs. Figure 2 shows the typical layout of such a VDD/VSS pair. Figure 2. Typical layout of VDD/VSS pair Via to VDD Via to VSS Cap. VDD STM8 8/39 Doc ID 18461 Rev 3 VSS AN3342 3 Clock management Clock management The STM8TL5xxx has no external clock so no precautionary measures are needed. 3.1 Internal clocks STM8TL5xxx devices have three kinds of internal clock: A high speed internal clock (HSI) running at 16 MHz, a low speed internal clock (LSI) running at 38 kHz and a high speed internal clock dedicated to the ProxSense (HSI_PXS) running at 16 MHz. The HSI_PXS clock runs once the ProxSense is enabled if the LowPower bit is reset. If LowPower bit is set HSI_PXS clock runs only when an acquisition is being performed. After reset, the CPU starts at speed of 2 MHz driven by the internal RC (HSI clock signal) divided by 8. Doc ID 18461 Rev 3 9/39 Reset control AN3342 4 Reset control 4.1 Reset management overview The reset pin is a 3.3 V bidirectional I/O (supplied by VDDIO). After startup it can be programmed by software to be used as a general purpose output. Its output buffer driving capability is fixed to IolMIN = 2 mA @ 0.45 V in the 1.65 V to 3.6 V range which includes a ~40 k pull-up. Output buffer is reduced to the n-channel MOSFET (NMOS). The receiver includes a glitch filter, whereas the output buffer includes a 20 µs delay. There are many reset sources, including: ● External reset through the NRST pin ● Power-on reset (POR): During power-on, the POR keeps the device under reset until the supply voltage (VDD) reach the right voltage level. ● Independent watchdog reset (IWDG) ● Window watchdog reset (WWDG), featuring also software reset. ● SWIM reset: An external device connected to the SWIM interface can request the SWIM block to generate a microcontroller reset. ● Illegal opcode reset: If a code to be executed does not correspond to any opcode or prebyte value, a reset is generated. Figure 3 shows a simplified functional I/O reset schematic. Figure 3. Reset management STM8TL5xxx VDD_IO RPU (typ 40 kΩ) External reset circuit NRST System reset Filter 100 nF Illegal op code reset Pulse generator (min 20 µs) IWDG/WWDG/software reset SWIM reset POR reset Delay MS18949V2 4.1.1 10/39 Output characteristics ● A valid pulse on the pin is guaranteed with a 20 ns pulse duration on the internal output buffer. ● After a valid pulse is recognized, a pulse on the pin of at least 20 µs is guaranteed starting from the falling edge of A (output of the OR between the different reset sources). Doc ID 18461 Rev 3 AN3342 Reset control Figure 4. Output characteristics ≥ 20 ns A 20 μs pulse stretch min. Pin Reset requested MS18950V1 4.1.2 Input characteristics ● All pulses with a duration less than 50 ns are filtered ● All train/burst spikes with a ratio of 1/10 must be filtered. This means that a negative spike of up to 50 ns is always filtered, when a 5 ns interval between spikes occurs (ratio 1/10). ● All pulses with duration more than 300 ns are recognized as valid pulses Figure 5. Input characteristics >5 ns >5 ns >300 ns Pad >50 ns >50 ns >50 ns Valid reset requested Negative train of glitch filtered System reset MS18951V1 Doc ID 18461 Rev 3 11/39 Reset control 4.2 AN3342 Hardware reset implementation The STM8TL5xxx does not require an external reset circuit to power-up correctly. Only a pull-down capacitor is recommended (see Figure 3). However, charging/discharging the pull-down capacitor through an internal resistor has a negative influence on the device power consumption. Therefore, the recommended capacitor value of 100 nF can be reduced down to 10 nF to limit such power consumption. The STM8TL5xxx reset state is released 1 ms after the POR value (1.35 V to 1.65 V) is reached. At this time, VDD should be in the 1.65 V to 3.6 V range. 12/39 Doc ID 18461 Rev 3 AN3342 ProxSense line management 5 ProxSense line management 5.1 ProxSense line management overview Since the STM8TL5xxx provides a ProxSense interface, it is mainly used to perform capacitance variation acquisition. The principle of this interface is to transfer a charge from a capacitance (the electrode CX) to another one (the sample CS, inside the MCU) by driving the PXS_TX and activating some switches. This allows detection of proximity as well as touch by monitoring on PXS_RX. The many features of the ProxSense interface include: ● 10 independent receiver channels, allowing 10 measurements to be performed in parallel ● Each of the 10 receiver channels can be associated with two different pins, effectively allowing an application to have up to 20 receiver channels. ● Each receiver channel can be independently configured to perform projected capacitance measurements. ● The size of each CS capacitor can be independently configured with 5 bits of resolution. Figure 6 shows a simplified functional schematic of the ProxSense interface. Figure 6. ProxSense management PXS_RX PXS_TX (1) (1) 1K 1K 1K Touch key 1K MS18955V1 1. The receiver and transmit numbers are application dependent. Doc ID 18461 Rev 3 13/39 ProxSense line management 5.2 AN3342 Hardware ProxSense implementation The STM8TL5xxx does not require any external circuitry to transfer the charge correctly. However, 1K serial resistors are recommended (see Figure 6) for ESD robustness. Several configurations are possible such as, ● 10 PXS_RX with 1 PXS_TX (10 measurements in parallel) or ● 10 PXS_TX with 1 PXS_RX (10 measurements in serial). However, any combination of 20 RX and 15 TX is allowed. Up to 15 PXS_TX are allowed to be used. Furthermore the 20 RX are organized in 2 groups, all RX belonging to the same group being acquired simultaneously. Advanced features such as an antenna (to detect noise) and external trigger may be implemented via the PXS_RFIN and PXS_TRIG pins in order to increase the robustness of the application. The footprint shown in Figure 7 gives an example of a touch key implementation on a PCB (for more details please refer to AN2869: Guidelines for designing touch sensing applications). Figure 7. Touch key layout example PXS_TX PXS_RX To next touchkey Rx To next touchkey Tx MS18957V1 The PXS_RX pins cannot be used as GPIOs, they are dedicated to ProxSense acquisition. Nevertheless, any PXS_RX pin can also be configured as a transmitter, this can ease the layout in some cases, allow to get a greater number of keys in a matrix configuration for devices with a reduced number of PXS_TX pins or save some PXS_TX pins for general purpose functions. This is easily done using the firmware library by configuring the acquisition bank with a RXn instead of a TXm in the transmitter definition. 14/39 Doc ID 18461 Rev 3 AN3342 ProxSense line management For devices with PXS_RXna and PXS_RXnb pins, i.e. with RX_GROUPA and RX_GROUPB, only the pins belonging to the same group are activated simultaneously. The disabled pins and the pins belonging to the not selected group are driven to VSS or configured in high impedance according to PXS_RXINSR register. Doc ID 18461 Rev 3 15/39 Recommendations AN3342 6 Recommendations 6.1 Printed circuit board For technical reasons, it is best to use a multi-layer PCB with a separate layer dedicated to the VSS and another layer to the VDD supply. This results in a good decoupling, as well as a good shielding effect. For many applications, economic requirements prohibit the use of this type of board. In this case, the most important requirement is to ensure a good structure for the VSS and power supply. 6.2 Component position A preliminary layout of the PCB must separate the different circuits according to their electromagnetic interference (EMI) contribution. This reduces cross-coupling on the PCB, for instance, noisy, high-current circuits, low voltage circuits, and digital components. 6.3 Ground and power supply (VSS, VDD, VSSIO, VDDIO) The VSS should be distributed individually to every block (noisy, low level sensitive, and digital) with a single point for gathering all ground returns. Loops must be avoided or have a minimum surface. The power supply should be implemented close to the ground line to minimize the surface of the supply loop. This is due to the fact that the supply loop acts as an antenna, and is therefore the main emitter and receiver of EMI. All component-free surfaces of the PCB must be filled with additional grounding to create a kind of shield (especially when using single-layer PCBs). 6.4 Decoupling The standard decoupler for the external power is a 1 µF capacitor. Supplementary 100 nF capacitors must be placed as close as possible to the VSS/VDD and VSSIO/VDDIO pins of the microcontroller to reduce the area of the current loop. As a general rule, decoupling all sensitive or noisy signals improves electromagnetic compatibility (EMC) performances. There are two types of decouplers: 16/39 ● Capacitors close to components. Inductive characteristics, which apply to all capacitors beyond a certain frequency, must be taken into account. If possible, parallel capacitors with decreasing values (0.1, 0.01,... µF) should be used. ● Inductors. Although often ignored, ferrite beads, for example, are excellent inductors due to their good dissipation of EMI energy and there is no loss of DC voltage (which is not the case when simple resistors are used). Doc ID 18461 Rev 3 AN3342 6.5 Recommendations Other signals When designing an application, the following areas should be closely studied to improve EMC performances: ● Noisy signals (clock) ● Sensitive signals (high impedance) Signals for which a temporary disturbance affects operation of the application permanently, for example, interrupts and handshaking strobe signals (but not LED commands). ● A surrounding VSS trace for such signals increases EMC performances, as does a shorter length or absence of noisy and sensitive traces (crosstalk effect). For digital signals, the best possible electrical margin must be reached for the two logical states. Slow Schmitt triggers are recommended for eliminating parasitic states. 6.6 Unused I/Os and features Microcontrollers are designed for a variety of applications, where often a particular application does not use 100 % of the microcontroller resources. To avoid unnecessary power consumption (especially important for battery powered applications) and also to improve EMC performance, unused clocks, counters, or I/Os, should not be left free, I/Os should be forced externally (pull-up or pull-down to the unused I/O pins), and unused functions should be ‘frozen’ or disabled. Alternatively, unused I/Os can be programmed as push-pull ‘low’ to keep them at a defined level without using external components. However in this case, the I/O is not driven during the power up phase, until the I/O is configured. This can add a little extra power consumption, and may be undesirable in very power sensitive applications. The unused PXS_RX pins should follow the same rule and can be driven to VSS by resetting the PXS_RXINSR register. 6.6.1 20-pin package A special care of I/O configuration must be taken with STM8TL5xFx devices. The port A, B and D I/Os are not all configured by default as it is the case on 28-pin packages. The user code must configure PA6, PA7, PD2, PD3, PD7 as output push pull low level. It is recommended to program all the unused I/Os to push-pull 'low level' even the ones not present in the device. While accessing to the GPIO registers, it is strongly recommended to mask the unused bit in order not to change their configuration or state. Concerning the PXS_RX: PXS_RXENRH and PXS_RXINSRH (and more generally all the MSByte of the register related to PxS_RX and PXS_TX) must be kept clear. Doc ID 18461 Rev 3 17/39 Reference design AN3342 7 Reference design 7.1 Component references Table 2. ID Component list Component name Reference Quantity Comments Refer to the ‘pinouts and pin description’ and ‘package characteristics’ sections of the STM8TL5xxx datasheets, to choose the right package 1 Microcontroller STM8TL5xxx 1 2 Battery 1.65 V to 3.6 V 1 3 Capacitor 1 µF 1 Decoupling capacitor 4 Capacitor 1 µF Low ESR ( 1 ) 1 Decoupling capacitor for the PXS regulator 5 Capacitor 100 nF 2 Ceramic capacitor (decoupling capacitor) Components below are optional 18/39 6 SWIM connector 4 pins 1 7 Resistor 1K n Doc ID 18461 Rev 3 Serial resistors for PXS_TX and PXS_RX pins AN3342 7.2 Reference design Schematics Figure 8. Reference design External reset circuit 100 nF NRST 1 μF PXS_VREG VDD VSS VDD 3.6 V – 1.65 V VDDIO + 1 μF 100 nF 100 nF V SSIO VSS VSS PXS_RX PXS_TX 1K 1K 1K 1K MS18956V2 1. For best performance, select a low ESR ( 1 ) capacitance. Doc ID 18461 Rev 3 19/39 STM8TL5x firmware libraries 8 AN3342 STM8TL5x firmware libraries In order to ease the development start-up, two firmware libraries are provided: 8.1 ● The STM8TL5x standard peripheral library ● The STM8TL5x STMTouch library STM8TL5x standard peripheral library This STM8TL5x firmware library contains the standard peripheral drivers (timers, I2C, SPI, USART, watchdogs, etc...) and a complete set of source code examples for each STM8TL5x peripheral. It is written in strict ANSI-C and it is fully MISRA C 2004 compliant. All examples can be used with four workspace and project definition files: ● One for the STVD and Cosmic C compiler ● One for the STVD and Raisonance Compiler ● One for the Raisonance integrated debugging environment and compiler (RIDE7 IDE) ● One for the IAR embedded workbench for STM8 (EWSTM8). This enables the user to load and compile them easily into their preferred development environment. 8.2 STM8TL5x STMTouch library The STM8TL5x STMTouch library is dedicated to the management of the ProxSense (PXS) peripheral. It follows the same coding rules as the standard peripheral library. The STM8TL5x STMTouch library allows you to enable touch sensing capabilities on STM8TL5x devices. This simple firmware offers a complete and robust solution to manage capacitive sensing keys, wheels or sliders. 20/39 Doc ID 18461 Rev 3 AN3342 8.3 STM8TL5x firmware libraries Online help For each firmware driver, an online help is directly available from the firmware installation directory (see Figure 9 and Figure 10). Figure 9. STM8TL5x standard peripheral driver online help manual Figure 10. STM8TL5x STMTouch driver online help manual Doc ID 18461 Rev 3 21/39 STM8TL5x firmware libraries AN3342 The STM8TL5x STMTouch library is provided with a set of examples all together with their online help manual, available from the examples directory (see Figure 11). Figure 11. STM8TL5x STMTouch Examples online help manual 22/39 Doc ID 18461 Rev 3 AN3342 9 STM8 development tools STM8 development tools Typically, the following tools are needed to get started: ● STVD, IAR workbench, or RIDE for integrated development environment ● STM8 C compiler (from Cosmic, Raisonance, or IAR) ● ST toolset from STMicroelectronics ● Firmware libraries from STMicroelectronics (STM8TL5x_StdPeriph_Lib and STM8TL5x_STMTouch_Lib for STM8TL5x) ● STM8TL53 Touch keypad Evaluation board or STMT-BOX™ (a) Evaluation kit from STMicroelectronics. ● The debug interface ST-LINK is included in STMT-BOX™ Display board ● If you do not use STMT-BOX™ Display board, you may need the hardware debug interface ST-Link from STMicroelectronics or "Rlink" from Raisonance. ● STMStudio is a graphical user interface that allows sampling and viewing user variables in real time using any hardware debugging tool while the application is running. 9.1 Single wire interface module (SWIM) 9.1.1 SWIM overview In-circuit debugging mode or in-circuit programming mode are managed through a single wire hardware interface based on an open-drain line, featuring ultra fast memory programming. Coupled with an in-circuit debugging module, the SWIM also offers a nonintrusive read/write to RAM and peripherals. This makes the in-circuit debugger extremely powerful and close in performance to a full-featured emulator. The SWIM pin can be used as a standard I/O (with 8 mA capability) which has some restrictions if the user wants to use it for debugging. The most secure way to use it is to provide a strap option on the PCB. Please refer to the STM8 SWIM communication protocol and debug module user manual (UM0470) for more SWIM protocol details. Figure 12. Debug system block diagram 100 kHz Osc Peripheral DBG SWIM entry Comm CMD layer decode DM STM8 core RAM NVM Internal RC a. The STMT-BOX™ is an STMicroelectronics trademark. Doc ID 18461 Rev 3 23/39 STM8 development tools 9.1.2 AN3342 SWIM connector pins The SWIM connector pins consist of four pins as described in Table 3. Table 3. 9.1.3 SWIM connector pins Pin number Pin name Pin 1 VDD Pin 2 SWIM pin Pin 3 VSS Pin 4 Reset Hardware connection Figure 13. Hardware connection AD/ICC SWIM adapter Application board SWIM connector VDD 1 1 2 3 2 3 4 4 VDD STM8 SWIM cable Caution: It is recommended to place the SWIM header as close as possible to the STM8TL5xxx device, as this minimizes any possible signal degradation caused by long PCB tracks. 9.2 RLink and STLink RLink and STLink are debug tools that allow any user application board with the SWIM interface to be connected to a host PC via USB for debugging and programming. See Section 11.3.3: Connecting the hardware on page 32. 24/39 Doc ID 18461 Rev 3 AN3342 10 STM8 software toolchain STM8 software toolchain To write, compile and run the first software on an STM8TL5xxx device, the following components of the software toolchain are required (see Figure 14): ● Integrated development environment ● Compiler ● Firmware library (optional, used to ease the startup) Figure 14. STM8 software toolchain Doc ID 18461 Rev 3 25/39 STM8 software toolchain 10.1 AN3342 Integrated development environment The integrated development environment ST visual develop (STVD) provides an easy-touse, efficient environment for start-to-finish control of application development, from building and debugging the application code to programming the microcontroller. STVD is delivered as part of the free ST toolset, which also includes the ST visual programmer (STVP) programming interface and the ST assembler linker. To build applications, STVD provides seamless integration of C and assembly tool chains for ST including the Cosmic and Raisonance C compilers and the ST assembler linker. When debugging, STVD provides an integrated simulator (software) and supports a complete range of hardware tools including the low-cost RLink in-circuit debugger/programmer and the high-end STice emulator. To program applications to an STM8TL5xxx, the STVD also provides an interface for reading from the microcontroller memories, writing to them and verifying them. This interface is based on the ST visual programmer (STVP), and supports all the target devices and programming tools supported by STVP. The free ST toolset for STM8 is available from STMicroelectronics home page (see www.st.com). 10.2 Compiler STM8TL5xxx device can be programmed by a free assembler toolchain which is included in the ST toolset. As the core is designed for optimized high-level-language support, use of a C compiler is recommended! C compilers for STM8 are offered by the third party companies Cosmic, Raisonance, and IAR. A free version of the C compiler with up to 32 Kbytes of generated code is available at: www.cosmic-software.com and www.raisonance.com. 26/39 Doc ID 18461 Rev 3 AN3342 Setting up the STM8 development environment 11 Setting up the STM8 development environment 11.1 Installing the tools All software tools are delivered with a setup wizard which guides the user through the installation process. It is recommended to install the tools in the following order: 1. C compiler 2. ST toolset 3. STM8TL5x firmware libraries ST-LINK does not need any dedicated software installation in the STM8 development environment because the necessary drivers are delivered with the ST toolset. The R-link drivers must be launched separately as follows: Start/Programs/STtoolset/Setup/Install Rlink driver. Doc ID 18461 Rev 3 27/39 Setting up the STM8 development environment 11.2 AN3342 Using the tools Once the tools installation is complete, the ST visual develop (STVD) integrated development environment can be launched. The user then has the choice to generate either a new workspace with a new project or to open an existing workspace. If using the STVD for the first time, it is recommended to open an existing project from one of the STM8TL5x firmware libraries. Note: Even if you are not intending to use the library, an existing library project can be used as a template to configure all the compiler options. Enter your own code after main(). The STM8TL5x standard peripheral firmware library includes several examples for each peripheral plus one workspace containing a blank project which is ready to receive your C code. It is located in the firmware subdirectory \Project\Examples (see Figure 15). You can choose between STVD\Cosmic, STVD\Raisonance, RIDE, or EWSTM8. The STM8TL5x STMTouch library provides all functions required for an easy and quick development of your own touch sensing application, using the full set of STM8TL5x touch sensing features. The STM8TL5x STMTouch library contains the touch sensing drivers dedicated to the STM8TL5x and its ProxSense peripheral but also a set of examples showing the STM8TL5x performances. Figure 15. STVD open example workspace 28/39 Doc ID 18461 Rev 3 AN3342 11.2.1 Setting up the STM8 development environment Project editing All project source files are visible and can be edited (see Figure 16). Figure 16. STVD MCU edit mode Doc ID 18461 Rev 3 29/39 Setting up the STM8 development environment 11.3 AN3342 Running the demonstration software ● Choose STM8TL53 STMT-BOX™ Touch keypad firmware ● Open the desired project workspace within the chosen demonstration firmware package. To run the demonstration software on the STM8TL53 Touch keypad evaluation board, the project has to be compiled and the correct HW tool must be selected before the debug session can be started. 11.3.1 Compiling the project The project can be compiled using the ‘Build’ function in the ‘Build’ menu (see Figure 17). Figure 17. STVD: Building the project 30/39 Doc ID 18461 Rev 3 AN3342 11.3.2 Setting up the STM8 development environment Selecting the correct debug instrument STM8TL53 Touch keypad evaluation board in standalone In the example below, the ST-Link tool is used for communicating via the SWIM interface with the on-board debug module of the STM8. The ST-Link tool can be selected from the ‘Debug Instrument Selection’ list in the ‘Debug Instrument Settings’ dialog (see Figure 18). Figure 18. STVD: Selecting the debug instrument Note: The Rlink can also be used for communicating via the SWIM interface. STM8TL53 Touch keypad evaluation board with the STMT-BOX™ Display board The Display board embeds a built-in ST-Link V2 debug tool. If the evaluation board is connected directly or through an isolation board to the Display board, the SWIM ST-Link debug tool must be selected in the ‘Debug Instrument Settings’ window. Doc ID 18461 Rev 3 31/39 Setting up the STM8 development environment 11.3.3 AN3342 Connecting the hardware STM8TL53 Touch keypad Evaluation board in standalone The debug tool, ST-Link or Rlink, must be connected to the USB connector of the PC. The SWIM connector for STM8 of the ST-Link or Rlink must be connected to the 4-pin SWIM connector of the STM8TL53 Touch keypad evaluation board. This board must also be powered through its USB connector. The figure below shows the STM8TL53 Touch keypad in standalone. Figure 19. STM8TL53 Touch keypad in standalone 32/39 Doc ID 18461 Rev 3 AN3342 Setting up the STM8 development environment STM8TL53 Touch keypad Evaluation board and STMT-BOX™ Display board If the evaluation board is directly connected to the STMT-BOX™ Display board, the kit is only powered through the USB connector of the STMT-BOX™ Display board and the STLink debug tool must be selected. The figure below shows the STM8TL53 Touch keypad with the STMT-BOX™ Display board. Figure 20. STM8TL53 Touch keypad Evaluation board and STMT-BOX™ Display board Doc ID 18461 Rev 3 33/39 Setting up the STM8 development environment AN3342 STM8TL53 Touch keypad Evaluation board with STMT-BOX™ Display board and Isolation board In the case the STMT-BOX™ Isolation board is inserted between the Display board and the evaluation board, these 2 boards must be independently powered. The debugging will be performed through the ST-Link built-in to the Display board. The figure below shows the STM8TL53 Touch keypad with the STMT-BOX™ Display board and Isolation board. Figure 21. STM8TL53 Touch keypad with the STMT-BOX™ Display board and Isolation board 34/39 Doc ID 18461 Rev 3 AN3342 11.3.4 Setting up the STM8 development environment Starting the debug session Debug mode can be entered by the command ‘Debug Start Debugging’ (see Figure 22). Figure 22. STVD: Starting the debug session Doc ID 18461 Rev 3 35/39 Setting up the STM8 development environment 11.3.5 AN3342 Running the software After entering debug mode, the software can be started by the run command in the menu ‘Debug Run’ (see Figure 23). Figure 23. STVD: Run the software 11.3.6 Follow up Step by step, additional peripherals of STM8TL5xxx devices can be run, following on from the initial debug session described above. Many features of STM8TL5xxx devices are supported by dedicated hardware on the STM8TL53 Touch keypad evaluation board with the STMT-BOX™ Display. The necessary software drivers, including STM8TL5x peripheral drivers (USART, I2C, SPI) and driver for the touch sensing modules (buttons, wheel, slider), are delivered in the STM8TL5x firmware standard peripheral library and the STM8TL5x STMTouch library. 36/39 Doc ID 18461 Rev 3 AN3342 12 Documentation and online support Documentation and online support Documentation resources related to tool usage includes: Application ● STM8TL5x datasheet. ● How to program Flash memory and data EEPROM on STM8TL5x microcontrollers (PM0212). ● STM8TL5x reference manual (RM0312) ● STM8 CPU programming manual (PM0044) ● AN2869 Guidelines for designing touch sensing applications Tools ● STM8TL5x firmware standard peripheral library and release note (detailed descriptions of the library are included as help files). ● STM8TL5x STMTouch library and release note (detailed descriptions of the library are included as help files). ● Cosmic, Raisonnance, or IAR C compiler user manual ● STMT-BOX™ Evaluation kit user manual ● STM8TL53 STMT-BOX™ Touch keypad firmware ● ST Visual Develop tutorial (included as help files in the ST-toolchain) ● ST Visual Develop (STVD) user manual ● STM8 SWIM communication protocol and debug module user manual (UM0470) The microcontroller discussion forum on www.st.com can be used by developers to exchange ideas. It is the best place to find different application ideas. In addition, the website has a knowledge base of FAQs for microcontrollers, which provide answers to many queries and solutions to many problems. Doc ID 18461 Rev 3 37/39 Revision history 13 AN3342 Revision history Table 4. Document revision history Date Revision 10-Mar-2011 1 Initial release 2 STM8TL53xx product name update Changed references to associated documents Updated Section 8: STM8TL5x firmware libraries on page 20 Updated Section 11.2: Using the tools on page 28. 3 STM8TL5xxx product name update Updated Figure 6: ProxSense management on page 13 Added references to associated documents Updated Section 5.2: Hardware ProxSense implementation on page 14 Added Section 6.6.1: 20-pins package on page 17 Updated Table 2: Component list on page 18 Updated Figure 8: Reference design on page 19 Updated Figure 9: STM8TL5x standard peripheral driver online help manual on page 21 Updated Figure 10: STM8TL5x STMTouch driver online help manual on page 21 Added Figure 11: STM8TL5x STMTouch Examples online help manual on page 22 Updated Section 11.3.2: Selecting the correct debug instrument on page 31 Replaced Section 11.3.3: Connecting the hardware on page 32 06-Dec-2011 05-Sep-2012 38/39 Changes Doc ID 18461 Rev 3 AN3342 Please Read Carefully: Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at any time, without notice. All ST products are sold pursuant to ST’s terms and conditions of sale. Purchasers are solely responsible for the choice, selection and use of the ST products and services described herein, and ST assumes no liability whatsoever relating to the choice, selection or use of the ST products and services described herein. No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein. UNLESS OTHERWISE SET FORTH IN ST’S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY WITH RESPECT TO THE USE AND/OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWS OF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT. UNLESS EXPRESSLY APPROVED IN WRITING BY TWO AUTHORIZED ST REPRESENTATIVES, ST PRODUCTS ARE NOT RECOMMENDED, AUTHORIZED OR WARRANTED FOR USE IN MILITARY, AIR CRAFT, SPACE, LIFE SAVING, OR LIFE SUSTAINING APPLICATIONS, NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY, DEATH, OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE. ST PRODUCTS WHICH ARE NOT SPECIFIED AS "AUTOMOTIVE GRADE" MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER’S OWN RISK. Resale of ST products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, any liability of ST. ST and the ST logo are trademarks or registered trademarks of ST in various countries. Information in this document supersedes and replaces all information previously supplied. The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners. © 2012 STMicroelectronics - All rights reserved STMicroelectronics group of companies Australia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan Malaysia - Malta - Morocco - Philippines - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of America www.st.com Doc ID 18461 Rev 3 39/39