Skip to main content
Explorer
June 4, 2025
Solved

STM8 SWIM Debug Protocol

  • June 4, 2025
  • 1 reply
  • 542 views

Hello,

I’ve been working on implementing a SWIM master using an STM8 device to interface with a STM8S105K6 target. This is part of a tester software project that was previously using the ST7 debug protocol and is now being ported to the STM8.

I’ve followed the entry sequence described in UM0470, and I believe the waveforms match what's expected. Attached below is a screenshot from the oscilloscope:

andryas_mariotto_0-1749051883648.png

  • Yellow trace = RESET pin

  • Green trace = SWIM pin

As you can see:

  1. A long low pulse initiates the SWIM entry sequence.

  2. Followed by 4 x 1kHz pulses and 4 x 2kHz pulses.

  3. Then I set the SWIM line high and switch it to input mode to await the slave response (Step 4 per UM0470).

However, no response is received from the target. The line stays high and never toggles.

Below is the relevant code section (i use raisonance ride7 dev environment):

 

unsigned char swim_entry(void){
unsigned long a;
unsigned char m = 1;
char buf[1];

swim_config(0);

ADC_disable;
RES(1);
SWIM(1);
delay_ms(10);

RES(0);
delay_ms(10);
SWIM(0);
delay(1000);
//delay (30); // 16us+ delay to get into SWIM mode

// start 1khz sequence:
for(a = 0; a < 4; a++){
SWIM(1);
delay(FIRST_PULSE);
SWIM(0);
delay(FIRST_PULSE);
}

// start 2khz sequence:
for(a = 0; a < 4; a++){
SWIM(1);
delay(SECOND_PULSE);
SWIM(0);
delay(SECOND_PULSE);
}
SWIM(1);
swim_config(1); // swim as input mode

for (a=0; a<10000; a++)
{
delay(125);
if (!IN_SWIM)
{
m = 0;
}

if (m == 0 && IN_SWIM)
{
m = 2;
break;
}
}

if(m != 2){
RES(1);
return FALSE;
}

swim_config(0);
SWIM(1);
delay(100);
// write 0x0A0 to the SWIM_CSR
buf[0] &= 0b000;
buf[0] |= SWIM_BITMASK;
if(!swim_write(3, 0, 0x7F, 0x90, buf)) {
RES(1);
return FALSE;
}

// End
SWIM(1);
RES(1);
delay_ms(20);
return TRUE;
}

Any ideas of what could be happening?

I appreciate any insight from others who’ve implemented custom SWIM masters, especially from STM8 to STM8 communication.

Thanks in advance!

    This topic has been closed for replies.
    Best answer by ahsrabrifat

    If the target has an enabled watchdog timer and no main firmware, it could be resetting before responding. Either disable the watchdog or flash a basic dummy firmware to keep it alive.

    1 reply

    Visitor II
    June 4, 2025

    If the target has an enabled watchdog timer and no main firmware, it could be resetting before responding. Either disable the watchdog or flash a basic dummy firmware to keep it alive.