5

As the title suggest I would like to use swo for debugging on an stm32F1 device without the use of st-link utils.I think I have flashed the code to send messages via swo on my chip but I can not establish a connection with the correct port as some tutorials suggested I use putty with the telnet port 2332 . Specifics about my configuration:cubemx swo configuration Relative code on my main

    int _write(int file, char *ptr, int len)
{
    int DataIdx;
    for (DataIdx = 0; DataIdx < len; DataIdx++)
    {
        __io_putchar(*ptr++);
    }
    return len;
}

...

   int main(){
    while (1)
      {
        printf("Hi\n");
      }
}

I have seen some tutorials using eclipse configurations or st-link utils but I have a very custom toolchain (I use conan, obko cmake configurations https://github.com/ObKo/stm32-cmake , ocb and linux) for the sole purpose of using c++ 2017 and libraries like boost so I can not use st-link utils.

Spyros Mourelatos
  • 484
  • 1
  • 8
  • 19

2 Answers2

2

You need to enable ITM port 0 (or another one) then output the chars using this port.

When it works you can wrap it into the printf

uint32_t ITM_SendChar (uint32_t ch)
{
  if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0) &&      /* ITM enabled */
      ((ITM->TER & 1) != 0)   )     /* ITM Port #0 enabled */
  {
    while (ITM->PORT[0].u32 == 0)
    {
      __NOP();
    }
    ITM->PORT[0].u8 = (uint8_t)ch;
  }
  return (ch);
}


0___________
  • 60,014
  • 4
  • 34
  • 74
  • 1
    Thank you I up voted your answer as it helped a lot but this doesn't say anything about how to connect to the right port ,so I will do an answer myself including openocd configurations for the default port – Spyros Mourelatos Mar 06 '20 at 09:48
  • 1
    line 4 & 5 checks if it is connected. Connection is just by setting those bits – 0___________ Mar 06 '20 at 10:35
  • I think this exact function is defined in cmsis headers file `CMSIS/Include/core_cm3.h:1698:26` so it wassomething else not working – Spyros Mourelatos Apr 08 '20 at 06:26
1

The problem with my configurations was that I didn't have a parser on my computer for the ITM messages so even after having the right configurations on the chip when I was opening the port to communicate with the chip my terminal was empty of messages . Hopefully I found this very helpful parser on github so all I had to do after compiling the program with the above configurations was to run openocd with configuring two options about the frequency of the f1 chip and the fact that ITM port was open (here is my .cfg file ):

source [find interface/stlink-v2.cfg]
source [find target/stm32f1x.cfg]
init
tpiu config internal - uart off 72000000
itm ports on

and on another terminal I runed the parser script from github python3 swo_parser.py

Spyros Mourelatos
  • 484
  • 1
  • 8
  • 19