Hide thumbs Also See for AT32:
Table of Contents

Advertisement

Introduction
It is common for the user to check the debug process information in the process of application code
debug. In most cases, this action can be done through the serial port debugging assistant.
However, it would be a headache for users to try to observe the testing process information when
the serial port assistant is not supported by the hardware.
To address the above concerns, this application note provides a complete set of example codes
describing how to output the debug process information, especially when the serial port debugging
assistant is not available.
Applicable products:
Part number
2019.08.05
AT32 Printf Debug Demo
AT32 Printf Debug Demo
AT32F403xx
AT32F413xx
AT32F415xx
AT32F403Axx
AT32F407xx
1
AN0015
Application Note
Rev 1.0.2
www.arterytek.com

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the AT32 and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

Summary of Contents for ARTERY AT32

  • Page 1 AT32 Printf Debug Demo AN0015 Application Note AT32 Printf Debug Demo Introduction It is common for the user to check the debug process information in the process of application code debug. In most cases, this action can be done through the serial port debugging assistant.
  • Page 2: Table Of Contents

    AT32 Printf Debug Demo Contents Overview ......................... 6 Detailed information ....................7 Printf via Terminal I/O in IAR ..................7 2.1.1 Introduction ........................7 2.1.2 Example code ....................... 7 2.1.3 Environment and hardware ..................7 2.1.4 Software ........................7 2.1.5 Debug and download ....................
  • Page 3 AT32 Printf Debug Demo 2.5.5 Debug and download ....................19 Printf via JLinkRTT ....................20 2.6.1 Introduction ......................... 20 2.6.2 Example code ......................20 2.6.3 Environment and hardware ..................20 2.6.4 Software ........................20 2.6.5 Debug and download ....................21 Notes ........................
  • Page 4 AT32 Printf Debug Demo List of tables Table 1. AT MCUs printf function use methods..................6 Table 2. Hardware connection table--(without JTDO) ................. 7 Table 3. Hardware connection table -- (without JTDO) ............... 9 Table 4. Hardware connection table--(USART) ................... 9 Table 5.
  • Page 5 AT32 Printf Debug Demo List of figures Figure 1. Virtual terminal window path ....................8 Figure 2. Virtual terminal interaction window ..................8 Figure 3. Serial port debugging assistant window ................10 Figure 4. Keil virtual terminal window path ..................12 Figure 5.
  • Page 6: Overview

    AT32 Printf Debug Demo Overview This application note describes how to use the printf function of AT chips in the environment of Keil and IAR. There are five methods to be listed in the table below, with each of them being detailed in this document.
  • Page 7: Detailed Information

    AT32 Printf Debug Demo Detailed information Printf via Terminal I/O in IAR 2.1.1 Introduction The IAR driver linked to the Terminal contains standard input and output driver functions such as scanf and printf so that the information interaction of the project files can be done via the Terminal I/O.
  • Page 8: Figure 1. Virtual Terminal Window Path

    AT32 Printf Debug Demo window. Figure 1. Virtual terminal window path Figure 2. Virtual terminal interaction window 2019.08.05 Rev 1.0.2 www.arterytek.com...
  • Page 9: Redirect Printf As Serial Ports In Iar

    AT32 Printf Debug Demo Redirect Printf as serial ports in IAR 2.2.1 Introduction Redirect the Printf function to a set of actual serial ports in the chip, and output via TX pin and finally implement information interaction through the serial port debugging assistant.
  • Page 10: Software

    AT32 Printf Debug Demo 2.2.4 Software 2.2.4.1 Header files Add the “stdio.h” to the code project files. 2.2.4.2 Redirection settings Initialize the serial ports and redirect the Printf function to the actual serial ports. The redirection function is as follows: PUTCHAR_PROTOTYPE USART_SendData(AT32_PRINT_UART, ch);...
  • Page 11: Printf Via Debug (Printf) Viewer In Keil

    AT32 Printf Debug Demo Printf via Debug (printf) Viewer in Keil 2.3.1 Introduction The Keil platform comes with a Debug (printf) Viewer that can be used for standard Printf interaction on the premise that the ARM core integrates standard input and output driver functions such as scanf and printf.
  • Page 12: Debug And Download

    AT32 Printf Debug Demo 2.3.4.3 Printf mapping int fputc(int c, FILE *f) if (c == '\n') SER_PutChar('\r'); return (SER_PutChar(c)); int SER_PutChar (int c) ITM_SendChar(c); return (c); 2.3.5 Debug and download Compile the code and downloaded it to the MCU, and enter debug environment to call up the virtual terminal window through View->Serial Windows->Debug (printf) Viewer, then run the code, and...
  • Page 13: Figure 5. Keil Virtual Terminal Interaction Window

    AT32 Printf Debug Demo Figure 5. Keil virtual terminal interaction window 2019.08.05 Rev 1.0.2 www.arterytek.com...
  • Page 14: Redirect Printf As Serial Ports In Keil (Using Microlib)

    AT32 Printf Debug Demo Redirect Printf as serial ports in Keil (using MicroLIB) 2.4.1 Introduction The Keil environment comes with a MicroLIB that contains some codes supporting Printf function. Tick the MicroLIB option to implement information interaction through the serial port debugging assistant when the Printf is redirected to the serial ports.
  • Page 15: Software

    AT32 Printf Debug Demo 2.4.4 Software 2.4.4.1 Header files Add the “stdio.h” to the code project files. 2.4.4.2 Redirect Printf PUTCHAR_PROTOTYPE USART_SendData(AT32_PRINT_UART, ch); while ( USART_GetFlagStatus(AT32_PRINT_UART, USART_FLAG_TRAC) == RESET ); return ch; 2.4.4.3 MicroLIB settings Figure 6. MicroLIB settings 2.4.5...
  • Page 16: Figure 7. Serial Port Interaction Window

    AT32 Printf Debug Demo Figure 7. Serial port interaction window 2019.08.05 Rev 1.0.2 www.arterytek.com...
  • Page 17: Redirect Printf As Serial Ports In Keil (Not Use Microlib)

    AT32 Printf Debug Demo Redirect Printf as serial ports in Keil (not use MicroLIB) 2.5.1 Introduction The Keil environment has a MicroLIB that contains some codes supporting Printf function. When the Printf is redirected to the serial ports and the MicroLIB option box is not ticked, the information interaction can be done through the serial port debugging assistant after adding the codes that supports Printf to the engineering project files.
  • Page 18: Software

    AT32 Printf Debug Demo 2.5.4 Software 2.5.4.1 Header files Add the “stdio.h” to the code project files. 2.5.4.2 Redirect Printf PUTCHAR_PROTOTYPE USART_SendData(AT32_PRINT_UART, ch); while ( USART_GetFlagStatus(AT32_PRINT_UART, USART_FLAG_TRAC) == RESET ); return ch; 2.5.4.3 MicroLIB settings Figure 8. MicroLIB settings 2019.08.05 Rev 1.0.2...
  • Page 19: Debug And Download

    AT32 Printf Debug Demo 2.5.4.4 Printf function supports code addition #pragma import(__use_no_semihosting) struct __FILE int handle; FILE __stdout; _sys_exit(int x) x = x; 2.5.5 Debug and download Compile the code and download it into the MCU, and run the code at full speed, you can find that the “Hello World”...
  • Page 20: Printf Via Jlinkrtt

    AT32 Printf Debug Demo Printf via JLinkRTT 2.6.1 Introduction JLink has its own debug output function that can debug the code and output to the corresponding window according to the specified instructions after the JLink RTT library code is added.
  • Page 21: Debug And Download

    AT32 Printf Debug Demo 2.6.4.3 Output to PC Then, call either SEGGER_RTT_WriteString or SEGGER_RTT_printf command from the code and output to PC. SEGGER_RTT_WriteString(0, "SEGGER Real-Time-Terminal Sample\r\n\r\n"); SEGGER_RTT_printf(0, "printf Test: %%c, 'S' : %c.\r\n", 'S'); 2.6.5 Debug and download 2.6.5.1 Printf via JLinkRTTClient window Compile the code and download it into the MCU, and enter the debug environment, open the JLinkRTTClient application in the JLink installation path.
  • Page 22: Figure 11. Jlinkrttclient Window Output Information

    AT32 Printf Debug Demo Figure 11. JLinkRTTClient window output information 2.6.5.2 Printf via JLinkRTTViewer window 1. Compile the code and download it to the MCU, and open the JLinkRTTViewer window, as presented in Figure 12. Figure 12. JLinkRTTViewer window 2019.08.05 Rev 1.0.2...
  • Page 23: Figure 13. Device Selection Window

    AT32 Printf Debug Demo 2. Click on OK,then click on OK again in the pop-up window, and input and select the following information, and then click on OK, as shown in Figure 13. Figure 13. Device selection window 3. Take the aforementioned code to enter the debug environment, and run it step by step, the print information will be displayed in the JLinkRTTViewer window, as shown in Figure 14.
  • Page 24: Notes

    AT32 Printf Debug Demo Notes  Only J-Link can be used for the testing in the section 2.3 and 2.6, and AT-Link is not supported;  For the testing in the section 2.1 and section 2.2, if the AT-Link is used, in the Options-- >CMSIS DAP-->Reset, either Hardware or System must be selected, otherwise it will not be...
  • Page 25: Revision History

    AT32 Printf Debug Demo Revision history Document revision history Table 11. Date Revisio Changes 2019.01.07 1.0.0 Initial release. 2019.07.29 1.0.1 Changed the IAR version. 2019.08.05 1.0.2 Added the JLinkRTTClient description. 2019.08.05 Rev 1.0.2 www.arterytek.com...
  • Page 26 Purchasers hereby agrees that Artery’s products are not authorized for use as, and purchasers shall not integrate, promote, sell or otherwise transfer any Artery’s product to any customer or end user for use as critical components in (a) any medical, life saving or life support device...

Table of Contents