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:
#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_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
- Include board definition to get settings for output to EDBG:
- Set buffer size to 128 byte:
#define CONF_DBG_PRINT_BUFFER_SIZE 128
- 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_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";
Add the following to your application's main()
function:
(const char *)"Main task",
configMINIMAL_STACK_SIZE + 100,
Workflow
- Define debug variables to print out:
uint32_t main_counter;
char main_string[] = "Main task iteration: 0x00000000\r\n";
- Define a FreeRTOS task for printing debug data forever:
- Print a constant string at the start of the task-loop:
- Write a hexadecimal integer into a string and print it:
- Note
- dbg_sprint_hexint() does not write the
0x
prefix, only the hexadecimal digits.
- Add a 1 sec delay at the of the task-loop and close the task definition:
- In
main()
, initialize the system and debug print service:
- Create an instance of the debug printing task:
(const char *)"Main task",
configMINIMAL_STACK_SIZE + 100,
- Start the FreeRTOS scheduler: