Serial Port debugging in Keil:

Source: Internet
Author: User

You can view the virtual debugging information of the serial port in Keil through view-serial windows-# usart1/2/3/4/debug (printf. Of course, you can also use the virtual serial port vspd + Serial Port debugging Assistant in the external implementation, the method is as follows:

Procedure

1. Download the virtual serial port software and the virtual two connected serial ports Coma/comb. These two serial ports have nothing to do with the real physical serial ports of the PC. The settings on both sides are the same

2. Open the serial communication assistant and assign a to the serial communication assistant. Then, B is allocated to the comx

2. Enter the command line in the MDK or load the following Debug. ini file.

Mode comb baudrate, parity, databits, stopbits

Assign comb <snin> snout // comb is the serial port of Keil uvision. Set N according to the serial port number of the microcontroller (if there is only one serial port, N can be omitted ).

 

2 printf implementation method 1 (function redirection): rewrite the fputc () function and implement it through a serial port of the microcontroller:

2.1 choose Use microlib from MDK-> option.

21.2 contains the standard library header file # include <stdio. h>. debug the serial port program of the Single Chip Microcomputer in advance.

2.3 rewrite the fput Function

/*

* Function name: fputc

* Description: redirects the C-library function printf to usart1.

* Call: called by printf

*/

Int fputc (int ch, file * F)

{

Usart_senddata (usart1, (unsigned char) CH );

// While (! (Usart1-> Sr & usart_flag_txe ));

While (usart_getflagstatus (usart1, usart_flag_tc )! = Set );

Return (CH );

}

2.4 use printf for calling.

3. Implemented Using SWO + hardware Debugger

Use DEBUG (printf) of MDK:

1. simulator settings: On the debug page, select cortex-M/r j-link/J-trace as the simulator, and click the setting option next to the simulator options to open the specific settings window.

In the displayed window, switch to the trace page, select enable, set core clock to 14 MHz, and set the frequency division option to core clock/16. The details are as follows:

 

2 rewrite the fputc () function as follows:

Struct _ file {int handle ;};

File _ stdout;

File _ stdin;

Int fputc (int ch, file * f ){

Itm_sendchar (CH );

Return (CH );

}

3. Enable SWO output to call the Function

Void setupswo (void)

{

Uint32_t * dwt_ctrl = (uint32_t *) 0xe0001000;

Uint32_t * tpiu_prescaler = (uint32_t *) 0xe0040010;

Uint32_t * tpiu_protocol = (uint32_t *) 0xe00400f0;

 

CMU-> hfperclken0 | = cmu_hfperclken0_gpio;

 

Gpio-> route | = gpio_route_swopen;

# If defined (_ efm32_giant_family)

 

Gpio-> route = (gpio-> route &~ (_ Gpio_route_swlocation_mask) | gpio_route_swlocation_loc0;

 

 

Gpio-> P [5]. Model & = ~ (_ Gpio_p_model_mode2_mask );

Gpio-> P [5]. model | = gpio_p_model_mode2_pushpull;

# Else

 

Gpio-> route = (gpio-> route &~ (_ Gpio_route_swlocation_mask) | gpio_route_swlocation_loc1;

 

Gpio-> P [2]. modeh & = ~ (_ Gpio_p_modeh_mode15_mask );

Gpio-> P [2]. modeh | = gpio_p_modeh_mode15_pushpull;

# Endif

 

CMU-> oscencmd = cmu_oscen1__auxhfrcoen;

 

While (! (CMU-> Status & cmu_status_auxhfrcordy ));

 

 

Coredebug-> dhcsr | = 1;

Coredebug-> demcr | = coredebug_demcr_trcena_msk;

 

 

* Dwt_ctrl = 0x400113ff;

 

* Tpiu_prescaler = 0xf;

 

* Tpiu_protocol = 2;

 

ITM-> lar = 0xc5acce55;

ITM-> Cr = 0x10009;

}

 

Pasted from

3. Include the header file # include <stdio. h> and call printf.

4. Open the output simulation in debug: View-serial-Debug (printf)

 

Pasted from

 

Keil debugging technology (replace printf with the SWO Function

 

Pasted from

 

 

A basic requirement in embedded software development is that debugging information can be output through a terminal, which can be achieved in two ways: UART on the Connection Board of a serial port and comport on the PC, you can use a Super Terminal on a PC to view debugging information. The other is the semi-host mechanism, but it may not be supported by the tool chain. The software debugging Based on the Cortex-M3 core breaks through this restriction, and the Cortex-M3 Kernel provides an ITM (instrumentation tracem1_cell) interface through swv (Serial wire viewer) debug the ITM data received by the SWO pins. ITM implements 32 common data channels. Based on this implementation, cmsis requires that channel 0 be used as a terminal to output debugging information, channel 31 is used for operating system output debugging (privileged mode access ). The itm_sendchar () function is defined in core_cm3.h. Therefore, you can call this function to override fputc to print debugging information through printf in the application, you can also view the debugging information through ITM viewer. With this implementation, embedded software developers can output debugging information without configuring serial ports or using terminal debugging software, reducing the workload to a certain extent.

Use SWO to replace the serial port for printf printing:

The cortex chip such as stm32 supports SWO output, and we use serial port debugging to only use TX output. We can completely send the serial port TX retarget of printf to the SWO port, you can directly use St-link to view printed information.

1: fast. The speed officially described by arm: High Performance Data Rate-4 MB Bytes/second @ 50 MHz

2: Do not use serial ports. In fact, if you use the JTAG port and change it to SWD debugging, one foot will not be used much.

3: because of the high speed, you only need to output data in block mode without interruption.

4: the problem of resource mutex is also solved due to block output.

Hardware condition: You have to connect the SWO foot of the chip to the debugging port. If you connect the chip by JTAG, this is already connected by default. However, many may only use the two lines of SWD, this is not answered.

 

Pasted from

Analysis of semihost/ITM mechanism and use jlink to debug stm32 single-chip microcomputer through ITM)

-Pasted from

 

Serial Port debugging in Keil:

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.