Zephyr Lab RT1060 Debug - nxp-mcuxpresso/vscode-for-mcux GitHub Wiki

Objectives

In this lab, you will learn:

  • How to build and debug a Zephyr application in VS Code
  • How to use various debugging tools and controls
  • How to enable Zephyr thread awareness using Kconfig symbols
  • How to use the RTOS viewer tool
  • How to enable and use the Peripheral view

Debug Lab

In this lab, we will go through detailed steps to run the Zephyr Synchronization sample application on the RT1060 EVKB. The Debug lab includes steps to build/debug the application and details on debug tools/controls in VS Code. It also includes steps to enable thread awareness by setting up Kconfig symbols for the application example. We will take a closer look at key features like Thread status, Stack usage, Call Stack, Thread structure, and more.

1. Import Synchronization application example

Follow the steps to import the example, similar to the steps in the Zephyr Lab RT1060 Hello World.

  1. To import the synchronization application from the Zephyr Repository, click Import example from Repository in the Quickstart Panel.

    Import Example

  2. Select the following board settings to import the example:

    • For selecting the board, type RT1060 to find the board arm/mimxrt1060_evkb. Make sure that the board ends with ‘B’ for the EVKB.

    • For selecting the example, type synchronization to find the application samples/synchronization

    • For application type, select Repository Application.

    • Click Create and the example should be added to the PROJECTS view.

      Synchronization Zephyr

2. Enable thread awareness and build the example

To enable thread awareness for debugging, we need to add specific Kconfig symbols to the application example. These steps will modify the prj.conf file and verify the generated .config file, similar to the Zephyr Lab RT1060 Kconfig guide.

  1. Add the following Kconfig symbols to the prj.conf file and save the file (Ctrl+S):

    CONFIG_DEBUG_THREAD_INFO=y
    CONFIG_INIT_STACKS=y
    CONFIG_THREAD_STACK_INFO=y
    

    CONFIG Values

  2. Build the project by clicking the Build Selected Gear icon.

    Build Selected

    After the build, the debug console window displays the memory usage (or compiler errors if any).

    Build Output Results

To enable the Peripheral view in VS Code for debugging, we need to edit the debugger launch.json file, and add the svdPath pointing to the SVD file. The SVD files are located in a repository included with the MCUXpresso SDK. Please refer to the Zephyr Lab Installation and Preparation guide and follow the steps to import the MCUXpresso SDK repository.

  1. Switch to the Explorer view (Ctrl+Shift+E) and open the file

    synchronization > .vscode > launch.json

    Add this line to the launch.json file. Note, be sure to change the path to your SVD file, and save the file (Ctrl+S):

    "svdPath": "C:/Users/NXP/mcux-sdk/svd/MIMXRT1062/MIMXRT1062.xml",
    

    SVD Path Added

3. Exploring Debug Tools and Controls

After building the application and enabling thread awareness, let’s explore the debug tools and controls in the Run and Debug view.

  1. If not already connected to the board, connect the micro-USB cable to J1, to power and debug the EVK. Connect the Serial monitor to the EVK’s COM port and click Start Monitoring.

    Serical Monitor

  2. Click the play icon to Debug the Synchronization application.

    Debug Project

  3. When first connecting to a device and using the LinkServer debug probe, VS Code will use a pop-up to ask for the device part number. In the search field, enter MIMXRT1062xxxxx:MIMXRT1060-EVKB. You can search with part of the device or board part number.

    Select device

Note: In future revisions of the tool, this step will go away, and the extension will select the device automatically.

  1. The following debug tools/controls are enabled in the Run and Debug view:

    1. Debug controls: Resume/Pause, Step over, Step into, Restart, Stop

    2. Variables: Locals and Registers

    3. Watch: Add expressions to monitor

    4. Call Stack: List of active subroutines in the program

    5. Breakpoints: Add, toggle, and view breakpoints in the code

    6. Status ribbon: Ribbon color changes to orange

      Debug Perspective

  2. To continue with the debug execution click Resume. The application prints hello world (both threads) in the Serial Monitor view.

    Serial Monitor Output

4. Debugging with Thread awareness – RTOS Viewer

The synchronization application has two threads (threadA and threadB) taking turns printing a message to the console. The example uses semaphores to synchronize the two tasks.

  1. While the debug session is active, go to the Run and Debug view, and open the source file with the main() subroutine in the editor.

    Add a breakpoint by double-clicking on the left side of line 48. A red dot next to the line and an entry in the Breakpoints window confirms the addition of the breakpoint.

    Add Breakpoint

  2. The debug session will halt at the helloLoop(), and the debug controls can be used to resume or step through the code. The synchronization application will print to the terminal after clicking Resume a couple of times.

    When the debugger halts at the breakpoint, the application threads and details are displayed in the RTOS viewer window. Click the Embedded Tools tab to see the RTOS view. The details include the status of each thread along with its priorities, stack pointer, and stack usage.

    Pause the debug session to notice the changes in the status of each thread.

    RTOS VIEWER 2

  3. Along with the Embedded Tools view, the Call Stack window provides more information about the threads in the application:

    • Running thread:

      Running Thread

    • Pending thread:

      Pending Thread

    • Idle Thread:

      Idle Thread

  4. The Watch window and the Variables window can be used to add local variables and CPU registers that need to be monitored.

    Watch and Variables

  5. The Peripheral View will be added to the Debug view when the debugger is connected and the svdPath is added to the launch.json file. To search for a specific peripheral, type the name in the text box (eg. LPUART).

    Peripheral View

    Peripheral View LPUART

5. Clean up after lab

This lab is completed. But the following steps will clean up the VS Code workspace:

  1. Click Stop to end the debug session.

    Stop Debugger

  2. Close all Editor tabs. Right-Click on a tab, and select Close All.

  3. If this is the last lab and you are done using the board, you should disconnect the Serial Monitor. Find the Serial Monitor view, and click Stop Monitoring.

    Stop Serial Monitor

Additional Resources


Lab completed. Return to the RT1060 Zephyr Labs Overview Training Zephyr Getting Started RT1060