Fully integrated microstepping motor driver (70 pages)
Summary of Contents for ST STM8
Page 1
STM8 SWIM communication protocol and debug module Introduction This manual is addressed to developers who build programming, testing or debugging tools for the STM8 8-bit MCUs family. This document explains the debug architecture of the STM8 core. The STM8 8-bit MCUs debug system includes two modules: •...
UM0470 Debug system overview The STM8 MCUs debug system interface allows a debugging or programming tool to be connected to the MCU through a single wire. This connection results in a bidirectional communication based on an open-drain line and provides a non-intrusive read/write access to RAM and peripherals during the program execution.
UM0470 Communication layer Communication layer The SWIM is a single wire interface based on asynchronous, high sink (8 mA), open-drain, bidirectional communication. While the CPU is running, the SWIM allows a non-intrusive read/write accesses to be performed on-the-fly to the RAM and peripheral registers, for debug purposes.
ACTIVE: this mode is entered when a specific sequence is detected on the SWIM pin while it is in the OFF state. In this state, the SWIM pin is used by the host tool to control the STM8 device with three commands: SRST (system reset), ROTF (read on-the-fly) and WOTF (write on-the-fly).
UM0470 Single wire interface module (SWIM) SWIM entry sequence After a POR (power on reset), and as long as the SWIM is in OFF mode, the SWIM pin is sampled for entry sequence detection. In order to do this, the internal LSI (low speed RC - resistor/capacitor) clock is automatically turned ON after the POR and remains forced ON as long as the SWIM is in OFF mode.
Once the option byte loading has occurred and that the stabilization time is reached, the CPU is in phase 8: - STM8 is stalled and HSI = 16 Mhz (see STM8 datasheets for HSI clock accuracy) - SWIM clock is at HSI/2 = 8 Mhz...
UM0470 Single wire interface module (SWIM) Bit format The bit format is a return-to-zero format, which allows a synchronization of every bit. Two communication speeds are available. At SWIM activation, the low speed is selected, while the high speed is selected by setting the HS bit in the SWIM_CSR register with the SWIM protocol.
Single wire interface module (SWIM) UM0470 3.3.2 Low speed bit format 1 bit is generated with twenty-two SWIM clock pulses. The bit format is: • 2 pulses at ‘0’ followed by 20 pulses at ‘1’ for ‘1’ value. • 20 pulses at ‘0’ followed by 2 pulses at ‘1’ for ‘0’ value. When the SWIM receives a data packet, it will decode: •...
UM0470 Single wire interface module (SWIM) SWIM communication protocol When in SWIM is in ACTIVE mode, the communication can be initiated either by the host or by the device. Each byte or command is preceded by a 1-bit header in order to arbitrate if both host and device initiate the communication at the same time.
Single wire interface module (SWIM) UM0470 SWIM commands The host can send a command when the line is idle or after each data byte from the device. After sending the command, the host releases the line. When the SWIM is ready to answer to the command, it initiates the transfer.
UM0470 Single wire interface module (SWIM) 3.5.3 WOTF: write on-the-fly 1 command followed by the number of bytes to be written followed by the address on three bytes. WOTF D[@] D[@+N] Parameters: The 8 bits are the number of bytes to write (from 1 to 255) @E/H/L: This is the 24-bit address to be accessed.
UM0470 CPU register access The CPU registers are mapped in the STM8 memory, and they can be read or written directly using the ROTF and the WOTF SWIM commands. the write operations to the CPU registers are committed only when the CPU is stalled.
UM0470 Single wire interface module (SWIM) Physical layer During the communication, the SWIM pin will be in pseudo-open drain configuration. The SWIM pin in the device is capable of sinking 8 mA when it drives the line to 0. The external pull-up on the SWIM line should be sized in a way that the maximum rise time t of the SWIM line is less than 1 sampling period of the bit (which is 100 ns +/- 4 %).
SAFE_MASK: Mask internal RESET sources This bit can be read or written through the SWIM only. It cannot be accessed through Bit 7 the STM8 bus. It includes the watchdog reset. 0: Internal reset sources are not masked 1: Internal reset sources are masked.
HSIT: High speed internal clock is trimmed This bit is read only through SWIM only. It cannot be accessed through STM8 bus. It is set when the HSIT bit is set in the core configuration register and reset by an external Bit 1 reset.
Debug module (DM) UM0470 Debug module (DM) Introduction The debug module (DM) allows the developer to perform certain debugging tasks without using an emulator. For example, the DM can interrupt the MCU to break infinite loops or to output the core context (stack) at a given point. The DM is mainly used for in-circuit debugging.
Debug module (DM) UM0470 Debug The DM registers can be read and written only through the SWIM interface. The STM8 core has no access to these registers. 4.3.1 Reset Once the SWIM is active and that the SWIM_DM bit is set in the SWIM_CSR register, a ‘data read’...
UM0470 Debug module (DM) Breakpoint decoding table Table 4. Decoding table for breakpoint interrupt generation DM_CR1 DM_CSR1 BREAK CONDITIONS BK1F BK2F BRW Disabled (RESET state) Data Write on @=BK1 and Data=BK2L Data Read on @=BK1 and Data=BK2L Data R/W on @=BK1 and Data=BK2L Instruction fetch BK1<=@<=BK2 Data Write on BK1<=@<=BK2 Data Read on BK1<=@<=BK2...
This paragraph defines when the debug module stalls the CPU when using the different breakpoint sources. • The STM8 MCU instruction can be modeled in time with an op-code/operand with a FETCH, DECODE and EXECUTION phases as shown in Figure The timing information is based on these models.
When the specified address does not correspond to a valid instruction address, no stall is generated. Figure 15. STM8 DM instruction break timing 4.10 Step mode The STM8 CPU stall is activated before the instruction execution, in the first decode cycle of the instruction. See Figure DocID14024 Rev 4 25/39...
Debug module (DM) UM0470 Figure 16. STM8 DM step timing Note: When the Step mode and the instruction break on the next instruction mode are both enabled, both the STF and the BKxF flags are set. When the user clears the STALL bit, the step function continues its normal operation.
Stack on @<=BK1” conditions and set BK1 to the upper value where the specific data is located in the stack. If the STM8 device tries to overwrite these values (after an interrupt or a CALL), the DM will generate a break. The four possible associated conditions allow to manage another breakpoint capability at the same time.
The SWIM can read and write to these bits via the ROTF/WOTF commands. read-only (r) The SWIM can only read these bits via the ROTF command. 4.12.1 DM breakpoint register 1 extended byte (DM_BKR1E) STM8 Address: 7F90h Reset value: 1111 1111 (FFh) BK1[23:16] BK1[23:16]: Breakpoint 1 extended byte value Bits 7:0 This register is written by software to define the extended address bits of breakpoint 1.
Debug module (DM) UM0470 4.12.7 DM control register 1 (DM_CR1) Address: 7F96h Reset value: 0000 0000 (00h) WDGOFF Reserved BC[2:0] Reserved WDGOFF Watchdog control enable. This bit must be set or cleared by software before the watchdogs (WWDG and/or IWDG) are activated. This bit has no effect if the hardware watchdog option is Bit 7 selected.
UM0470 Debug module (DM) 4.12.8 DM control register 2 (DM_CR2) Address: 7F97h Reset value: 0000 0000 (00h) Reserved FV_ROM Reserved FV_RAM Bit 7:3 These bits are reserved and must be kept at 0. FV_ROM Remap vector table in ROM. This bit is set or cleared by software. It remaps the vector table to a ROM location Bit 2 (product dependent) instead of program memory (usually 8000h).
UM0470 Debug module (DM) 4.12.10 DM control/status register 2 (DM_CSR2) Address: 7F99h Reset value: 0000 0000 (00h) Reserved SWBRK SWBKF STALL Reserved FLUSH Bits 7:6 Reserved. It must be kept at 0 SWBKE Software breakpoint control bit (read/write) This bit is used to enable/disable the software breakpoint capability with NOP instruction Bit 5 0: DM does not generate any event when NOP(SW BRK) instruction is fetched by the...
Debug module (DM) UM0470 4.12.11 DM enable function register (DM_ENFCTR) Address: 7F9Ah Reset Value: 1111 1111 (FFh) ENFCT7 ENFCT6 ENFCT5 ENFCT4 ENFCT3 ENFCT2 ENFCT1 ENFCT0 ENFCTx Enable function This bit is set and cleared by software. it allows to freeze a particular function of a peripheral when the core is stalled.
UM0470 Debug module (DM) 4.12.12 Summary of SWIM, DM and core register maps Table 5. STM8 MCU registers STM8 Register address name 7F00h Reset value 7F01h PC23 PC22 PC21 PC20 PC19 PC18 PC17 PC16 7F02h PC15 PC14 PC13 PC12 PC11...
Page 36
Debug module (DM) UM0470 Table 5. STM8 MCU registers (continued) STM8 Register address name Reserved DM_CSR2 Reserved SWBKE SWBKF STALL Reserved FLUSH 7F99h Reset value DM_ENFCTR ENFCT7 ENFCT6 ENFCT5 ENFCT4 ENFCT3 ENFCT2 ENFCT1 ENFCT0 7F9Ah Reset value The reset value for the SP and PC registers is product dependent. Refer to the device datasheet for more details...
UM0470 Description of the DM_ENFCTR register for each STM8 product Appendix A Description of the DM_ENFCTR register for each STM8 product Some peripherals can be frozen through the debug module during the debug and while using the DM_ENFCTR register (address: 7F9Ah).
Page 39
ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on ST products before placing orders. ST products are sold pursuant to ST’s terms and conditions of sale in place at the time of order acknowledgement.
Need help?
Do you have a question about the STM8 and is the answer not in the manual?
Questions and answers