0

I am trying to learn how to debug an MCU non-intrusively using SWD & openOCD.

while (1)
  {
      my_count++;
      HAL_GPIO_TogglePin(LD2_GPIO_Port,LD2_Pin);
      HAL_Delay(750);
  }

The code running on my MCU has a free running counter "my_count" . I want to sample/trace the data stored in the address holding "my_count" in real time : I was doing it this way:

 while(1){// generic algorithm no specific language
mdw 0x00000000200000ac; //openOCD command to read from an address
}

0x200000ac is the address of the variable my_count from the .map file. But, this method is very slow and experiences data drops at high frequencies. Is there any other way to trace the data at high frequencies without experiencing data drops?

  • how frequently do you actually need it? There is a thousand ways, but you have to be more specific – Ilya Jun 21 '22 at 10:15
  • As low as 25 microseconds i.e the toggle period of the LED without any data drops. And if that is not possible what is the maximum limit for which we can trace data without any data drops? – Arindom Bora Jun 21 '22 at 11:39

1 Answers1

0

I made some napkin math, and I have an idea that may work.

As per Reference Manual, page 948, the max baud rate for UART of STM32F334 is 9Mbit/s.

If we want to send memory at the specific address, it will be 32 bits. 1 bit takes 1/9Mbps or 1.111*10^(-7)s, multiply that by 32 bits, that makes it 3.555 microseconds. Obviously, as I said, it's purely napkin math. There are start and stop bits involved. But we have a lot of wiggle room. You can easily fit 64 bits into transmission too.

Now, I've checked with the internet, it seems the ST-Link based on STM32F103 can have max baud rate of 4.5Mbps. A bummer, but we simply need to double our timings. 3.55*2 = 7.1us for 32-bit and 14.2us for 64-bit transmission. Even given there is some start and stop bit overhead, we still seem to fit into our 25us time budget.

So the suggestion is the following:

You have a timer set to 25us period that fires an interrupt, that activates DMA UART transmission. That way your MCU actually has very little overhead since DMA will autonomously handle the transmission, while your MCU can do whatever it wants in the meantime. Entering and exiting the timer ISR will be in fact the greatest part of the overhead caused by this, since in the ISR you will literally flip a pair of bits to tell DMA to send stuff over UART @ 4.5Mbps.

Ilya
  • 992
  • 7
  • 14
  • Thank You for your suggestion. But,I have already tried this. But I want to trace the memory address without modifying my algorithm at run time and without halting the processor while tracing is taking place i.e non-intrusively. – Arindom Bora Jun 21 '22 at 12:47