Microchip® Advanced Software Framework

Quick Start Guide for Debug Print Service for FreeRTOS

In this use case, the Debug Print service is configured with the following settings:

  • 128-byte print buffer
  • output via the SERCOM UART connected to Embedded Debugger (EDBG) on an Xplained Pro board
  • 9600 baud transfer rate

A FreeRTOS task is created which every second prints a constant string and a string containing an incrementing 32-bit hexadecimal integer.

Setup

Prerequisites

FreeRTOS must be added to the project, and the clock driver must be configured to initialize GCLK 0 to 48 MHz. Note that FreeRTOS also has a setting for the system clock frequency which must be updated.

Code

The following must be added to the file conf_dbg_print.h:

#include <board.h>
#define CONF_DBG_PRINT_BUFFER_SIZE 128
#define CONF_DBG_PRINT_SERCOM EDBG_CDC_MODULE
#define CONF_DBG_PRINT_GCLK_SOURCE GCLK_GENERATOR_0
// #define CONF_DBG_PRINT_BAUD_RATE 9600
// This BAUD value gives 9600 baud with 48 MHz GCLK
#define CONF_DBG_PRINT_BAUD_VALUE 65326
#define CONF_DBG_PRINT_SERCOM_MUX EDBG_CDC_SERCOM_MUX_SETTING
#define CONF_DBG_PRINT_PINMUX_PAD0 EDBG_CDC_SERCOM_PINMUX_PAD0
#define CONF_DBG_PRINT_PINMUX_PAD1 EDBG_CDC_SERCOM_PINMUX_PAD1
#define CONF_DBG_PRINT_PINMUX_PAD2 EDBG_CDC_SERCOM_PINMUX_PAD2
#define CONF_DBG_PRINT_PINMUX_PAD3 EDBG_CDC_SERCOM_PINMUX_PAD3

Workflow

  1. Include board definition to get settings for output to EDBG:
    #include <board.h>
  2. Set buffer size to 128 byte:
    #define CONF_DBG_PRINT_BUFFER_SIZE 128
  3. Use SERCOM connected to EDBG CDC for output at 9600 baud:
    #define CONF_DBG_PRINT_SERCOM EDBG_CDC_MODULE
    #define CONF_DBG_PRINT_GCLK_SOURCE GCLK_GENERATOR_0
    // #define CONF_DBG_PRINT_BAUD_RATE 9600
    // This BAUD value gives 9600 baud with 48 MHz GCLK
    #define CONF_DBG_PRINT_BAUD_VALUE 65326
    #define CONF_DBG_PRINT_SERCOM_MUX EDBG_CDC_SERCOM_MUX_SETTING
    #define CONF_DBG_PRINT_PINMUX_PAD0 EDBG_CDC_SERCOM_PINMUX_PAD0
    #define CONF_DBG_PRINT_PINMUX_PAD1 EDBG_CDC_SERCOM_PINMUX_PAD1
    #define CONF_DBG_PRINT_PINMUX_PAD2 EDBG_CDC_SERCOM_PINMUX_PAD2
    #define CONF_DBG_PRINT_PINMUX_PAD3 EDBG_CDC_SERCOM_PINMUX_PAD3

Use Case

Code

Add the following to your main application C file:

uint32_t main_counter;
char main_string[] = "Main task iteration: 0x00000000\r\n";
static void main_task(void *params)
{
do {
dbg_print_str("Main task loop executing\r\n");
// Update hexadecimal 32-bit integer in string, and print it
dbg_sprint_hexint(&main_string[23], main_counter++);
dbg_print_str(main_string);
} while(1);
}

Add the following to your application's main() function:

(const char *)"Main task",
configMINIMAL_STACK_SIZE + 100,
NULL);

Workflow

  1. Define debug variables to print out:
    uint32_t main_counter;
    char main_string[] = "Main task iteration: 0x00000000\r\n";
  2. Define a FreeRTOS task for printing debug data forever:
    static void main_task(void *params)
    {
    do {
  3. Print a constant string at the start of the task-loop:
    dbg_print_str("Main task loop executing\r\n");
  4. Write a hexadecimal integer into a string and print it:
    // Update hexadecimal 32-bit integer in string, and print it
    dbg_sprint_hexint(&main_string[23], main_counter++);
    dbg_print_str(main_string);
    Note
    dbg_sprint_hexint() does not write the 0x prefix, only the hexadecimal digits.
  5. Add a 1 sec delay at the of the task-loop and close the task definition:
    } while(1);
    }
  6. In main(), initialize the system and debug print service:
  7. Create an instance of the debug printing task:
    (const char *)"Main task",
    configMINIMAL_STACK_SIZE + 100,
    NULL);
  8. Start the FreeRTOS scheduler: