STM32F3 programming and debug using SWO

This post will guide you through steps to print values from any part of the program. This functionality will allow the user to debug the code easily and doesn’t need to add any extra hardware like LCD. Working with serial monitor eases the process of development and quite helpful in experimentation.

I am working on STM32F3 Cortex M-4 board in IAR workbench environment. I hope the user has prior knowledge of how to configure the workspace and write the basic program. This link is helpful in understanding the basic things to get start with basic steps and run your first blink program. Only needed some library name modification which is not difficult for a logical person. 🙂

So coming to the main theme of this post, follow through these steps:

1. Connect the last pin of SWD port to PB3 which will help print serial values. PB3 is reserved pin for SWO feature. There is other way to connect these pins via bridge. Referring technical manual, there is a list of solder bridge to make permanent connection:


2. Software modification:

a. Add library to support print function. As we know from basic C-programming, need to use standard                library.

#include “stdio.h”

b. Add printf function wherever you want inside main function.

printf(“LED -TOGGLE “);

3. After this hardware modification all we need to do is some software modification. Just right-click on the project template.


3. Go to options.


4.  Under general options, go to Library configuration to change the default “stdout/stderr” option to “Via SWO”. That’s all need to be done for setting.


5. Now make your main program, build it and debug it. In debug window you’ll notice a new icon appears named SWO. This shows our successful setup for serial view. Click on this green icon to view all settings of SWO but no need to change anything.


6. Now in order to get the window/terminal for Serial view, click on view-> Terminal I/O.


7. Running the code will show the output in terminal window.


Happy coding 🙂





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s