PrintF via SWO

DrBanana
Thu Oct 06, 2016 1:19 pm
I usually program stm32 board with ST Link, but problem is, I cannot debug as its not connected through Serial. Now Im wondering if there is method that can send strings from MCU to PC through SWO, so I can use ST Link Utility and its “PrintF via SWO” ?

stevestrong
Thu Oct 06, 2016 2:40 pm
Well, if you just want to debug, you have already the right tool (STlink adapter) in your hand. You just need to mix it with a bit of SW on you PC (Eclipse + OpenOCD) and there you have it.

The SWO feature would be interesting for me as well.


RogerClark
Thu Oct 06, 2016 8:53 pm
There is a way to send back debug strings STLink ( or any SWD programmer), but from what I have seen, it doesnt seem to be widely used.

Why not just hook up a USB to Serial adaptor to USART1 ( PA9 and PA10),


Slammer
Thu Oct 06, 2016 9:39 pm
stdio through SWO requires some initialization during startup and a function based on CMSIS, the ITM_SendChar(), with this it is very easy to expand a stream class to use it as putchar. The extra code for using SWO is more or less the same as UART and you need a special program to read it (openocd, ST Link Utility, etc).
I have tested with the arm eclipse plugin (it can be enabled during creation of the project), but finally I think that using a uart for this is a better option. Personally for difficult points I prefer to debug with ST-Link directly (with breakpoints, step execution, etc)
While SWO is working with Nucleo boards, this is not working with ST-Link V2 clones as the SWO does not exist.

martinayotte
Fri Oct 07, 2016 1:50 pm
There someone who did hacked STLink clones to add a SWO line on them :
http://www.eevblog.com/forum/microcontr … nk-clones/

Ollie
Fri Oct 07, 2016 3:10 pm
Personally, I like debugging with ST-Link. There are many use cases where the tracking print statements do not work.

If one day, Arduino or stm32duino will have the debugger support, I hope that it would go one step further and leverage all the capabilities built in the M3 platform. Please, take a look of the following blog explaining and demonstrating these capabilities.

http://essentialscrap.com/tips/arm_trace/theory.html

Cheers, Ollie


Pito
Fri Oct 07, 2016 4:24 pm
There someone who did hacked STLink clones to add a SWO line on them :
interesting the last post in the thread :)
I’ve figured it out, but still waiting with pulling the trigger :) (as I have currently only a single stlink dongle handy..)

RogerClark
Fri Oct 07, 2016 8:07 pm
Ollie

There is an active thread by @stevestrong where he now uses Eclipse + an Arduino plugin.

This may be the best of both worlds, but it looks like the install is a little tricky.

I dont think the Arduino IDE is going to get debugger support any time in the near future, as for AVR Arduino now recommends the use of Atmel Studio ( aka AVR Studio) if you want debugger support, and surprisingly the Arduino team seem to think debug support is not something beginners would want ( but I think debug support makes things easier for beginners not harder, even web browsers now come with Javascript debuggers by default)


victor_pv
Sun Jan 15, 2017 2:57 am
DrBanana wrote:I usually program stm32 board with ST Link, but problem is, I cannot debug as its not connected through Serial. Now Im wondering if there is method that can send strings from MCU to PC through SWO, so I can use ST Link Utility and its “PrintF via SWO” ?

victor_pv
Sun Feb 19, 2017 6:11 pm
I just had some time to test the SWO class with a j-link and an st-link, works fine on both.
It nicely prints information at about 2Mhz in stlink, and 4.5Mhz in swo viewer.

Now I do have a problem with #define and ifdef in the arduino IDE.

This works fine in both Eclipse and Arduino IDE if I define SWODEBUG, but if I comment it out “#define SWODEBUG” to eliminate the debug output, then in Arduino it doesn’t compile:

#define SWODEBUG

#ifdef SWODEBUG
SWO_Channel SWO;
#define SWO_ErrLog(...) SWO.printf(__VA_ARGS__);

#else /* Not DEBUG */
#define SWO_ErrLog(...)
#endif


stevestrong
Sun Feb 19, 2017 6:37 pm
Have you tried:
#define SWODEBUG 1

victor_pv
Mon Feb 20, 2017 12:13 am
stevestrong wrote:Have you tried:
#define SWODEBUG 1

RogerClark
Mon Feb 20, 2017 7:23 am
Did you try adding that define into either boards.txt or platform.txt so that it gets applied to all files that are complied

I suspect the problem is that it needs to be defined globally and if you only define it in the sketch it only gets applied to includes directly included by the sketch not by any of the other core files

You could also try putting it in something like arduino.h as I think that may get included in most files (though not all)


stevestrong
Mon Feb 20, 2017 8:28 am
Check the compile/build options, maybe one of them overrules your define.

victor_pv
Mon Feb 20, 2017 4:11 pm
I checked the compile/build options and there isn’t any overwriting this.

Nothing goes wrong when I declare the functions in the ino (or rather some of them) myself. It seems like Arduino IDE places the functions before the #define if there is only the pin one, and the #ifdef, but doesn’t do so where there is the other #define there.. In any case, seems to be totally a problem of the Arduino IDE and nothing else. Since I found a way around it if it happens again I can move forward to other things.
Thank you both for the suggestions.


stevestrong
Mon Feb 20, 2017 5:47 pm
Btw, which IDE version do you use and has this problem?

victor_pv
Mon Feb 20, 2017 6:11 pm
stevestrong wrote:Btw, which IDE version do you use and has this problem?

ddrown
Mon Feb 20, 2017 9:26 pm
victor_pv wrote:#if (SWODEBUG > 0)
SWO_Channel SWO;
#define SWO_ErrLog(...) \
SWO.printf(__VA_ARGS__); \
SWO.printf("LINE: %d, FUNCTION: %s, FILE: %s \r\n", __LINE__, __FILE__, __FUNCTION__);
#else /* Not DEBUG */
#define SWO_ErrLog(...)
#endif

victor_pv
Mon Feb 20, 2017 9:51 pm
ddrown wrote:

Also, what was the line above the toggleLED definition?

ddrown
Tue Feb 21, 2017 12:42 am
victor_pv wrote:ddrown wrote:

Also, what was the line above the toggleLED definition?

stevestrong
Tue Feb 21, 2017 8:41 am
As far as I remember, the Arduino_STM32 repo supports only Arduino IDE version 1.6.9 and above. So update…

Leave a Reply

Your email address will not be published. Required fields are marked *