Serial Wire Viewer (SWV)

Source: Internet
Author: User

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

    • Use the in-circuit debugger. This was 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 T o 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 Plugge  D 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 has an USB module.
    • Use the Serial wire Output (SWO). This feature would 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 would describe how to use and set up the Serial wire Viewer for the stm32f3-discovery. The other options is also explained in seperate sections.

Here is 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 are used in the Keil MDK (uVi  sion) to download the source code to the ARM microcontroller.  This would also provide the interface through which the ARM microcontroller would send a value to being printed to the SWV. The following is required:

    • Update the St-link Utility to the latest version (currently it was v3.3.0) at the following link:http://www.st.com/web/en/ catalog/tools/pf258168
    • Update The ST-LINK/V2 programmer ' s firware using the St-link Utility.
    1. Disconnect the USB cable.
    2. Remove the Jumpers (CN4) on the board.
    3. Connect the USB cable
    4. Open the St-link Utility
    5. Select st-linkFirmware 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 jumpers (CN4)

Stm32f3-discovery Board

By default, the SWO pin of the STM32F303VCT6 microcontroller is isn't 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 pads together. This was a more permanent option, but can being reversed by carefully de-soldering the both pads and making sure with a multi-m Eter that they is indeed seperated.

IMPORTANT NOTICE * * *

Please note this PB3 can now is used as a normal GPIO pin, until the above changes is reversed.

Configuring a Keil Project

Assuming that you had an already working project which was correctly set up for Flash programming and debugging, do the FO Llowing to add the SWV capability (you can use the example source files on 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 for use of the Trace on ITM Stimulus Port 0. 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 is retargetted to print to the SWV and to the USART (or even a 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 did, do the following to use the SWV:

    1. Open the STM32nd-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 a 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 wil  L now is not being possible. To reprogram changes or new source code to the Stm32f3-discovery board, you'll have a to:

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

The handle and interface to the ST-LINK/V2 programmer are now released and can being used in Keil uvision again to program the Device as usual.

Clicking start in the SWV window would 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:st M32f3-discovery description:example Program This uses Trace Events to write "Hello world!" via the St-link Programm Er 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 PB 3 'll now is 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 T He 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--------------------------------------*/voidInitleds (void);//prototype for the user function to initialize the user LEDs/*#global Variables-----------------------------------------*///Unused Global variables that has to is included to ensure correct compiling * ///###### Don't change ######// ===============================================================================__io uint32_t Timingdelay =0;//used with the Delay function__io uint8_t Dataready =0; __io uint32_t usbconnecttimeout= -; __io uint32_t userbuttonpressed=0; __io uint8_t prevxfercomplete=1;// ===============================================================================intMainvoid) {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/ + ) )     while(1 )      ; //Would end up in this infinite loop if there is an error with Systick_configinitleds ();//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 is writing it to the high byte (Pe15-pe8)Count= Count +1; Delay ( - ); }}/*retarget the C library printf function to the SWO Viewer. overwrites int FPUTC (int ch, FILE *f) function used by printf. */intFPUTC (intCH, FILE *f) {  return(Itm_sendchar (CH));}voidInitleds (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//###### Don't change ######voidDelay (__io uint32_t ntime) {Timingdelay=Ntime;  while(Timingdelay! =0);}//Function to decrement the timingdelay variable.//###### Don't change ######voidTimingdelay_decrement (void ){  if(Timingdelay! =0x00) {Timingdelay--; }}//Unused functions that has to is included to ensure correct compiling//###### Don't change ######// =======================================================================uint32_t L3gd20_timeout_usercallback (void ){  return 0;} uint32_t Lsm303dlhc_timeout_usercallback (void ){  return 0;}// =======================================================================

Serial Wire Viewer (SWV)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.