10. Debugging via Serial Port

Enabling UART provides a convenient way to output diverse debugging information to a terminal emulator application. In this section, we’ll demonstrate how to activate UART for seamless debugging.

10.1. Serial Port Terminal

In the following we will demonstrate this using a standard and free terminal emulator, Tera Term but you can use any terminal emulator that you are comfortable with (PuTTY, RealTerm or else).

  • First, we will set up Tera Term by selecting the virtual COM port and set the port configuration in the Setup->Serial Port window as shown below:
    _images/serial_port_setup.png

    Figure 15 Tera Term, serial port settings

  • Click ‘OK’ to accept the port settings

Tera Term

Tera Term can be downloaded from https://osdn.net/projects/ttssh2/releases/

10.2. Enabling Serial Port

  1. At this juncture, you can effortlessly enable UART by making a simple modification to the configuration file: …_config_basic.h Choose the appropriate file based on your desired target (User configuration modules).

    Scroll down and find the #undef CFG_PRINTF statement and change it to:
    - #undef CFG_PRINTF
    + #define CFG_PRINTF
    
  2. In user_periph_setup.h change the gpio used as the UART transmit output by the DA14531 or DA1453x DevkitP and USB to P0_5 as follows:

    // Define UART2 Tx Pad
    #if defined (__DA14531__)
       #define UART2_TX_PORT           GPIO_PORT_0
       #define UART2_TX_PIN            GPIO_PIN_5
    #else
       #define UART2_TX_PORT           GPIO_PORT_0
       #define UART2_TX_PIN            GPIO_PIN_4
    #endif
    
  3. This will automatically select and configure the proper GPIO for the UART TX. In order to give ourselves access to a more user friendly API, we will add the following include statement to user_empty_peripheral_template.c:

    #include "arch_console.h"
    
    We can now use the following functions:
    • arch_puts(), to transmit a simple string via the UART

    • arch_printf(), to format and transmit a string via the UART

10.3. Using the Serial Port:

  1. In our timer function, my_timer_cb(), from the previous section of this tutorial, add the following statement:

    arch_puts("Turning the LED off after 2 seconds\n\r");
    
  2. Build the project and load it onto target

  3. Use your BLE explorer app to connect to the device and observe that the LED turns off 2 seconds after a BLE connection has been established while also transmitting Turning the LED off after 2 seconds via the UART:

    _images/serial_port_test.png

Warning

The LED will not turn on if you are holding the button down while connecting!