Serial Wire Viewer (SWV)

Being able to display values for counters, sensors and other debugging information is an important part of software development for microcontrollers.  Writing software for PCs is much easier in this regard as there is already a monitor to which you could print values etc. to simply the development process.  For microcontrollers the obvious choice is to use a LCD connected to some of the microcontroller‘s port pins and with the use of the proper LCD library one can then print these values to the LCD.  This does however increase your development cost as the LCDs will normally cost in the region of R100 - R300 and often supporting interfacing circuitry will have to be build for the correct operation of the LCD.  With the SMT32 microcontrollers, there are fortunately other options:

  • Use the in-circuit debugger.  This is a very powerful feature, but requires a bit of learning.
  • Use the UART/USART module.  By connecting the TX and RX pins through an appropriate voltage level converter to a PC‘s COM port, one can print values to a Serial Monitor (e.g. Termite, Hyperterminal, etc.) application on the PC, and even get values from the PC.
  • Use a Virtual COM Port (VCP).  Provides the same functionality as the UART/USART, but does not require the use of a voltage level converter and is plugged into a USB port which simulates a COM port.  This does require appropriate drivers on the PC and also on the microcontroller.  Furthermore the microcontroller must have an USB module.
  • Use the Serial Wire Output (SWO).  This feature will allow one to print values to a Serial Wire Viewer (SWV) via the SWO pin on the mictrontoller and the in-circuit programmer with no additional hardware, cables or drivers.

This section will describe how to use and set up the Serial Wire Viewer for the STM32F3-Discovery.  The other options are also explained in seperate sections.

Here are the topics to cover for using the SWV:

ST-Link/V2

The STM32F3-Discovery includes a built-in ST-Link/V2 in-circuit programmer and debugger which is used in the Keil MDK (uVision) to download the source code to the ARM microcontroller.  This will also provide the interface through which the ARM microcontroller will send a value to be printed to the SWV.  The following is required:

  1. Disconnect the USB cable.
  2. Remove the two jumpers (CN4) on the board.
  3. Connect the USB cable
  4. Open the ST-Link Utility
  5. Select ST-Link → Firmware update
  6. Click Device Connect
  7. Click Yes
  8. Close the update window and the ST-Link Utility
  9. Disconnect the USB cable
  10. Replace the two jumpers (CN4)

STM32F3-Discovery board

By default the SWO pin of the STM32F303VCT6 microcontroller is is NOT linked to the ST-Link/V2 programmer.  To create the link, we can do the following:

  • Connect a wire link between PB3 and pin6 of the SWD connector (CN3)

OR

  • Close the solder bridge (jumper) SB10 at the botom of the board by soldering the two pads together.  This is a more permanent option, but can be reversed by carefully de-soldering the two pads and making sure with a multi-meter that they are indeed seperated.

*** IMPORTANT NOTICE ***

Please note that PB3 can now not be used as a normal GPIO pin, until the above changes are reversed.

Configuring a Keil project

Assuming that you have an already working project which is correctly set up for Flash programming and debugging, do the following to add the SWV capability (you can use the example source files at the top of this page):

  1. Open the project in Keil MDK (uVision)
  2. Right-click on the project name in the Project window and select Options for target ...
  3. In the Debug tab, select Settings
  4. In the Trace tab, make the following selections:
  5. Click OK
  6. Close the Options for Target dialog
  7. Compile and Flash Download (program)/Debug as usual.

Add code

The standard printf statement makes use of the fputc function.  We need to retarget the fputc function to use the Trace on ITM Stimulus Port 0.  To do this, simply add the following code to your programs that uses the SWV:

int fputc(int ch, FILE *f)
{
    return(ITM_SendChar(ch));
}

The fputc function could actually be retargetted to print to the SWV and to the USART (or even an LCD) at the same time, e.g:

int fputc(int ch, FILE *f)
{
    /* the USART */
    UART4->TDR = (ch & (uint16_t)0x01FF);
    while ((UART4->ISR & USART_FLAG_TXE) == (uint16_t) RESET);
    
    /* the SWV */
    return(ITM_SendChar(ch));
}

Using the Serial Wire Viewer (SWV)

Once all the previous topics were done, do the following to use the SWV:

  1. Open the STM32 ST-Link Utility
  2. Select ST-LINK → Printf via SWO viewer
  3. Set the System clock to 72000000
  4. Set the Stimulus port to 0
  5. Click Start

The SWV is now ready for receiving characters and values from the printf statements in the source code.  It has now grabbed the handle and interface to the ST-Link/V2 programmer and Flash Downloading and Debuggin in uVision will now not be possible.  To reprogram changes or new source code to the STM32F3-Discovery board, you will have to:

  1. Click STOP in the SWV window
  2. Click the Disconnect button

The handle and interface to the ST-Link/V2 programmer is now released and can be used in Keil uVision again to program the device as usual.

Clicking Start in the SWV window will now reset the board and start the serial connection again.

/*#############################################################
 File Name       : ex1_SWOViewer_HelloWorld.c
 Author          : Grant Phillips
 Date Modified   : 13/05/2014
 Compiler        : Keil ARM-MDK (uVision V4.70.0.0)
 Tested On       : STM32F3-Discovery

 Description     : Example program that uses Trace Events to
 write "Hello World!" via the ST-Link programmer
 to the ST-Link Utility‘s SWO Viewer and then
 display a count from 0 to 255 repeatedly. The
 count value is also written to the 8 USER LEDs.
 Visit the following link for more information
 regarding the SWO Viewer:
 http://controlsoft.nmmu.ac.za/STM32F3-Discovery
 -Board/Example-programs/SWO-Viewer     

 Requirements    : * STM32F3-Discovery Board

 Circuit         : * A wire link between PB3 and pin6 of the SWD
 connector (CN3)
 OR
 solder the solder bridge SB10 closed underneath
 the board

 Note that PB3 will now not be available as a
 normal GPIO pin.

 See the STM32F3-Discovery User Manual (UM1570) for the block
 diagram of the STM32F303VCT6 processor (p13), a summary of
 the GPIO connections (p21-29) and the schematic diagram (p31-34)

 ##############################################################*/

/* #includes -------------------------------------------------*/
#include "main.h"
//main library to include for device drivers, peripheral drivers, etc.

/* #defines --------------------------------------------------*/

/* #function prototypes --------------------------------------*/
void InitLEDs( void ); //prototype for the user function to initialize the USER LEDs

/* #global variables -----------------------------------------*/

// Unused global variables that have to be included to ensure correct compiling */
// ###### DO NOT CHANGE ######
// ===============================================================================
__IO uint32_t TimingDelay = 0;                    //used with the Delay function
__IO uint8_t DataReady = 0;
__IO uint32_t USBConnectTimeOut = 100;
__IO uint32_t UserButtonPressed = 0;
__IO uint8_t PrevXferComplete = 1;
// ===============================================================================

int main( void )
{
  uint8_t count = 0;    //8-bit integer variable to hold the count value (0-255)

  RCC_ClocksTypeDef RCC_Clocks; //structure used for setting up the SysTick Interrupt

  /* Set the SysTick Interrupt to occur every 1ms) */
  RCC_GetClocksFreq( &RCC_Clocks );
  if ( SysTick_Config( RCC_Clocks.HCLK_Frequency / 1000 ) )
    while ( 1 )
      ; //will end up in this infinite loop if there was an error with Systick_Config

  InitLEDs( ); //initialize the USER LEDs for this application                                               

  //print a message to the SWO Viewer (make sure the fputc function is
  //retargeted as shown by the fputc function just after main()
  printf( "Hallo World!\n" );

  /* Main program loop */
  while ( 1 )
  {
    printf( "\n%2X", count );       //print a newline and integer value (in HEX)

    GPIO_Write( GPIOE, count << 8 );
    //shift the value 8 spaces to the left,
    //because we are writing it to the high byte (PE15 - PE8)

    count = count + 1;

    Delay( 250 );
  }
}

/*
 Retarget the C library printf function to the SWO Viewer.
 Overwrites int fputc(int ch, FILE *f) function used by printf.
 */
int fputc( int ch, FILE *f )
{
  return ( ITM_SendChar( ch ) );
}

void InitLEDs( void )
{
  GPIO_InitTypeDef GPIO_InitStructure; //structure used for setting up a GPIO port

  /* GPIOE Periph clock enable */
  RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOE, ENABLE );

  /* Configure PE15 - PE8 in output pushpull mode */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15 | GPIO_Pin_14 | GPIO_Pin_13
    | GPIO_Pin_12 | GPIO_Pin_11 | GPIO_Pin_10 | GPIO_Pin_9 | GPIO_Pin_8;
  //which pins to setup, seperated by |
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init( GPIOE, &GPIO_InitStructure );
}

// -------------------------------------------------------------------------------

// Function to insert a timing delay of nTime
// ###### DO NOT CHANGE ######
void Delay(__IO uint32_t nTime)
{
  TimingDelay = nTime;

  while(TimingDelay != 0);
}

// Function to Decrement the TimingDelay variable.
// ###### DO NOT CHANGE ######
void TimingDelay_Decrement( void )
{
  if ( TimingDelay != 0x00 )
  {
    TimingDelay--;
  }
}

// Unused functions that have to be included to ensure correct compiling
// ###### DO NOT CHANGE ######
// =======================================================================
uint32_t L3GD20_TIMEOUT_UserCallback( void )
{
  return 0;
}

uint32_t LSM303DLHC_TIMEOUT_UserCallback( void )
{
  return 0;
}
// =======================================================================
时间: 2024-10-25 09:38:37

Serial Wire Viewer (SWV)的相关文章

Introduction to Cortex Serial Wire Debugging

Serial Wire Debug (SWD) provides a debug port for severely pin limited packages, often the case for small package microcontrollers but also complex ASICs where limiting pin-count is critical and can be the controlling factor in device costs. SWD repl

Serial Wire Debug (SWD) Interface -- PSoc5

PSoC 5 supports programming through the serial wire debug (SWD) interface. There are two signals in SWD interface: data signal (SWDIO) and a clock for data signal (SWDCK). The host programmer always drives the clock line, whereas either the programme

The J-Link hardware debugging Eclipse plug-in

Quicklinks If you already know what are the features of the new plug-in and just want to know how to install/use it, you can directly skip to: J-Link install J-Link plug-in usage Why a new plug-in? Until now, debugging with the J-Link probe in Eclips

Keil debugging techniques and alternative printf (SWO function)

One of the basic needs of the embedded software development through the terminal to output debugging information, generally two ways to achieve: one is the COM port on the UART and PC using a serial cable connecting plate through the PC HyperTerminal

嵌入式OS入门笔记-以RTX为案例:十.Keil的RTX调试支持

嵌入式OS入门笔记-以RTX为案例:十.Keil的RTX调试支持 调试(debug)是软件开发的一个重要环节,对于嵌入式开发而言这个环节其实比较依赖一些硬件资源(硬件debugger)的支持.传统的嵌入式系统的调试比较依赖断点(breakpoint)和单步调试(single step through).而 ARM cortex-M 系列的芯片其实有很强的CoreSight片上调试支持,实际上就是一个小的调试硬件,作为ARM的标准,内嵌在ARM的芯片里.在ARM自家的调试器ULINK-pro等的帮

keil中的串口调试:

keil中串口的虚拟调试信息在通过View-serial windows-#usart1/2/3/4/debug(printf)可以看到.当然也可以通过虚拟串口VSPD+串口调试助手在外部实现,方法如下: 虚拟 串口使用:步骤 1 下载虚拟串口软件,虚拟2个连接的串口COMA/COMB,这两个串口与PC机的真实物理串口没关系.两边的设置相同 2 打开串口通讯助手,将A分配给串口通讯助手,则B就分配给下面的COMx 2 在MDK中输入命令行或者将下面的做成debug.ini文件加载 MODE CO

Bus Blaster v4 design overview

Bus Blaster v4 design overview Bus Blaster v4 is an experimental, high-speed JTAG debugger for ARM processors, FPGAs, CPLDs, flash, and more. Thanks to a reprogrammable buffer, a simple USB update makes Bus Blaster v4 compatible with many different J

ARM Cortex Design Considerations for Debug

JTAG was the traditional mechanism for debug connections for ARM7/9 parts, but with the Cortex-M family, ARM introduced the Serial Wire Debug (SWD) Interface. SWD is designed to reduce the pin count required for debug from the 5 used by JTAG (includi

KL46 custom board SWD reset is never asserted - SWS Waveform

KL46 custom board SWD reset is never asserted Hi everybody, I'm trying to program a custom board based on the KL46. However the reset signal for the SWD port is stuck at logic LOW. My programmer is a P&E Multilink FX. I can successfully program my te