MCUXpresso VSCode: Difference between revisions

From Variscite Wiki
No edit summary
 
(20 intermediate revisions by 3 users not shown)
Line 3: Line 3:
--> {{#lst:MCUXpresso_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{#lst:MCUXpresso_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{#lst:MCUXpresso_Platform_Customization|MCUXPRESSO_GLOBALS}} <!--
--> {{#lst:MCUXpresso_Platform_Customization|MCUXPRESSO_GLOBALS}} <!--
--> {{#vardefine:DTB_DEBUG | <!--
-->    {{#switch:{{#var:HARDWARE_NAME}} | <!--
-->      DART-MX8M = imx8mq-var-dart-dt8mcustomboard-m4-sd-lvds.dtb | <!--
-->      DART-MX8M-MINI = imx8mm-var-dart-dt8mcustomboard-m4.dtb | <!--
-->      VAR-SOM-MX8M-NANO = imx8mn-var-som-symphony-m7.dtb | <!--
-->      DART-MX8M-PLUS = imx8mp-var-dart-dt8mcustomboard-m7.dtb | <!--
-->      VAR-SOM-MX8X = imx8qxp-var-som-symphony-sd-m4.dtb | <!--
-->      VAR-SOM-MX8 = imx8qm-var-som-symphony-lvds-m4.dtb | <!--
-->    }} <!--
--> }} <!--
--> {{#vardefine:DTB_RPMSG | <!--
-->    {{#switch:{{#var:HARDWARE_NAME}} | <!--
-->      DART-MX8M = imx8mq-var-dart-dt8mcustomboard-m4.dtsi | <!--
-->      DART-MX8M-MINI = imx8mm-var-dart-dt8mcustomboard-m4.dtsi | <!--
-->      VAR-SOM-MX8M-NANO = imx8mn-var-som-symphony-m7.dtsi | <!--
-->      DART-MX8M-PLUS = imx8mp-var-common-m7.dtsi | <!--
-->      VAR-SOM-MX8X = imx8qxp-var-som-symphony-m4.dtsi | <!--
-->      VAR-SOM-MX8 = imx8qm-var-m4.dtsi | <!--
-->    }} <!--
--> }} <!--
--> {{#vardefine:YOCTO_RELEASE_NOTES_LINK | <!--
-->    {{#switch:{{#var:HARDWARE_NAME}} | <!--
-->      DART-MX8M = https://variwiki.com/index.php?title=DART-MX8M_Release_Notes&release=RELEASE_DUNFELL_V1.5_DART-MX8M | <!--
-->      DART-MX8M-MINI = https://variwiki.com/index.php?title=DART-MX8M-MINI_Release_Notes&release=RELEASE_HARDKNOTT_V1.1_DART-MX8M-MINI | <!--
-->      VAR-SOM-MX8M-NANO = https://variwiki.com/index.php?title=VAR-SOM-MX8M-NANO_Release_Notes&release=RELEASE_DUNFELL_V1.6_VAR-SOM-MX8M-NANO | <!--
-->      DART-MX8M-PLUS = https://variwiki.com/index.php?title=DART-MX8M-PLUS_Release_Notes&release=RELEASE_HARDKNOTT_V2.2_DART-MX8M-PLUS | <!--
-->      VAR-SOM-MX8X = https://variwiki.com/index.php?title=VAR-SOM-MX8X_Release_Notes&release=mx8x-yocto-hardknott-5.10.72_2.2.1-v1.0 | <!--
-->      VAR-SOM-MX8 = https://variwiki.com/index.php?title=VAR-SOM-MX8_Release_Notes&release=mx8-yocto-hardknott-5.10.72_2.2.1-v1.0 | <!--
-->    }} <!--
--> }} <!--
--> {{#vardefine:DEBUG_BOARD | <!--
-->    {{#switch:{{#var:HARDWARE_NAME}} | <!--
-->      DART-MX8M = VAR-DT8MCustomBoard | <!--
-->      DART-MX8M-MINI = VAR-DT8MCustomBoard | <!--
-->      VAR-SOM-MX8M-NANO = Symphony | <!--
-->      DART-MX8M-PLUS = VAR-DT8MCustomBoard | <!--
-->      VAR-SOM-MX8X = Symphony | <!--
-->      VAR-SOM-MX8 = Symphony | <!--
-->    }} <!--
--> }} <!--
--> {{#vardefine:USE_CM_STRING_UBOOT | <!--
-->    {{#switch:{{#var:HARDWARE_NAME}} | <!--
-->      DART-MX8M = <br> => setenv use_m4 yes | <!--
-->      DART-MX8M-MINI = | <!--
-->      VAR-SOM-MX8M-NANO = | <!--
-->      DART-MX8M-PLUS = | <!--
-->      VAR-SOM-MX8X = | <!--
-->      VAR-SOM-MX8 = | <!--
-->    }} <!--
--> }} <!--
--> {{#vardefine:USE_CM_STRING_LINUX | <!--
-->    {{#switch:{{#var:HARDWARE_NAME}} | <!--
-->      DART-MX8M = <br> $ fw_setenv use_m4 yes | <!--
-->      DART-MX8M-MINI = | <!--
-->      VAR-SOM-MX8M-NANO = | <!--
-->      DART-MX8M-PLUS = | <!--
-->      VAR-SOM-MX8X = | <!--
-->      VAR-SOM-MX8 = | <!--
-->    }} <!--
--> }} <!--
-->{{#vardefine:SEGGER_JLINK_DEBUGGING_EXTERNAL_RAM_THREAD|https://forum.segger.com/index.php/Thread/2948-SOLVED-DEBUGGING-doesn-t-work-in-external-RAM-but-in-internal-RAM/?postID=11144&highlight=LMEM#post11144}} <!--
-->{{#vardefine:SEGGER_JLINK_8MP_PATCH|https://www.nxp.com/webapp/Download?colCode=SDK_MX8MP_3RDPARTY_Patch&appType=license}} <!--
-->{{PageHeader|{{#var:HARDWARE_NAME}} - MCUXpresso {{#var:MCUXPRESSO_VERSION}} Development with VS Code}}{{DocImage|category1={{#var:HARDWARE_NAME}}|category2=MCUXpresso}}
-->{{PageHeader|{{#var:HARDWARE_NAME}} - MCUXpresso {{#var:MCUXPRESSO_VERSION}} Development with VS Code}}{{DocImage|category1={{#var:HARDWARE_NAME}}|category2=MCUXpresso}}
=Overview=
=Overview=
Line 25: Line 95:
==Install Segger JLink==
==Install Segger JLink==
  $ Download JLink_Linux_V760b_x86_64.deb from https://www.segger.com/downloads/jlink/
  $ Download JLink_Linux_V760b_x86_64.deb from https://www.segger.com/downloads/jlink/
  Direct Download: https://www.segger.com/downloads/jlink/JLink_Linux_V760b_x86_64.deb
  $ sudo dpkg -i JLink_Linux_V760b_x86_64.deb
  $ sudo dpkg -i JLink_Linux_V760b_x86_64.deb
The software will be installed in /opt/SEGGER folder
The software will be installed in /opt/SEGGER folder
{{#ifeq: {{#var:HARDWARE_NAME}} | DART-MX8M-PLUS |
{{Note|'''Note:''' The JLink SEGGER script need to be patched<br>
  Download the patch from {{#var:SEGGER_JLINK_8MP_PATCH}}
  Unzip the JLink.zip and override the NXP_iMX8M_Connect_CortexM7.JLinkScript in your SEGGER installer path.
}}}}
==Install MCUXpresso Toolchain and SDK==
==Install MCUXpresso Toolchain and SDK==
Download and install GNU-ARM bare-metal toolchain:
Download and install GNU-ARM bare-metal toolchain:
Line 33: Line 110:
  $ wget {{#var:TOOLCHAIN_URL}}
  $ wget {{#var:TOOLCHAIN_URL}}
  $ tar xvf {{#var:TOOLCHAIN_BZ2_NAME}}
  $ tar xvf {{#var:TOOLCHAIN_BZ2_NAME}}
Download MCUXpresso SDK for the SOM:
Download MCUXpresso SDK for the SOM:
  $ cd {{#var:SDK_PATH}}
  $ cd {{#var:SDK_PATH}}
  $ git clone {{#var:SDK_GIT_URL}} -b {{#var:SDK_GIT_BRANCH}}
  $ git clone {{#var:SDK_GIT_URL}} -b {{#var:SDK_GIT_BRANCH}}
  $ cd freertos-variscite
  $ cd freertos-variscite
=Add Visual Studio Code support to the Variscite examples=
=Add Visual Studio Code support to the Variscite examples=
==Available Demos==
==Available Demos==
Line 44: Line 123:
   {{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER1}}
   {{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER1}}
   }}
   }}
Variscite provides a script to simplify the Project Configuration
Variscite provides a script to simplify the Project Configuration
{{#ifeq: {{#var:HARDWARE_NAME}} | VAR-SOM-MX8 |
{{Note|'''Note:''' Using var_add_vscode_support.sh script you can specify for which Cortex-M4 core to generate vscode support: (-c <cm_c0 or cm_c1>)<br>
If the Cortex-M4 core id is missing the default is setted as core 0
}}}}
==Configure a single Project==
==Configure a single Project==
For this example, we will configure the hello_world demo. However, the process is the same for all demos.
For this example, we will configure the hello_world demo. However, the process is the same for all demos.
Line 53: Line 138:
  $ ./var_add_vscode_support.sh -b {{#var:BOARD_SDK}} -e all -t tcm -d /opt/SEGGER/JLink  (for TCM target)
  $ ./var_add_vscode_support.sh -b {{#var:BOARD_SDK}} -e all -t tcm -d /opt/SEGGER/JLink  (for TCM target)
  $ ./var_add_vscode_support.sh -b {{#var:BOARD_SDK}} -e all -t ddr -d /opt/SEGGER/JLink  (for DDR target)
  $ ./var_add_vscode_support.sh -b {{#var:BOARD_SDK}} -e all -t ddr -d /opt/SEGGER/JLink  (for DDR target)
{{#ifeq: {{#var:CORTEX_M_TYPE}} | m4 |
 
{{Note|'''Note:''' Some J-Link debuggers support connecting to your host computer via Ethernet or Wi-Fi. To enable this, add the IP Address of your J-Link to launch.json:<br>
 
$ vi {{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}}/demo_apps/hello_world/.vscode/launch.json
{
    "configurations": [
    {
      "ipAddress": "<J-Link IP Address>"
    ...
}}
 
{{#varexists:DEACTIVATE_LMEM_CACHE_PATCH |
==Disable LMEM caches to debug demos mapped in DDR==
==Disable LMEM caches to debug demos mapped in DDR==
{{Note|'''Note:''' to debug applications mapped in DDR, is mandatory to deactivate the LMEM caches<br>
{{Note|'''Note:''' to debug applications mapped in DDR, is mandatory to deactivate the LMEM caches<br>
Line 59: Line 155:
  $ git apply patches/{{#var:DEACTIVATE_LMEM_CACHE_PATCH}}
  $ git apply patches/{{#var:DEACTIVATE_LMEM_CACHE_PATCH}}
Please visit the SEGGER forum to additional information<br>
Please visit the SEGGER forum to additional information<br>
https://forum.segger.com/index.php/Thread/2948-SOLVED-DEBUGGING-doesn-t-work-in-external-RAM-but-in-internal-RAM
{{#var:SEGGER_JLINK_DEBUGGING_EXTERNAL_RAM_THREAD}}
}}
}}}}
}}
 
==Open a Demo in VS Code==
==Open a Demo in VS Code==
For this example, we will use the hello_world demo mapped in TCM. However, the process is the same for all demos.
For this example, we will use the hello_world demo mapped in TCM. However, the process is the same for all demos.
From a terminal, launch VS Code and open the hello_world demo directory:
From a terminal, launch VS Code and open the hello_world demo directory:
  $ code {{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}}/demo_apps/hello_world/
{{#ifeq: {{#var:HARDWARE_NAME}} | VAR-SOM-MX8 |
  $ code {{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}}/demo_apps/hello_world/cm4_core0
|
$ code {{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}}/demo_apps/hello_world
}}
VS Code should open and look similiar too:
VS Code should open and look similiar too:


Line 75: Line 175:


If the build task completes successfully, the following output files will be generated:
If the build task completes successfully, the following output files will be generated:
{{#ifeq: {{#var:HARDWARE_NAME}} | VAR-SOM-MX8 |
{{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}}/demo_apps/hello_world/cm4_core0/armgcc/debug/hello_world_m40.bin  (for TCM target, load in U-Boot)
{{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}}/demo_apps/hello_world/cm4_core0/armgcc/debug/hello_world_m40.elf  (for TCM target, load using debugger or remoteproc)
{{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}}/demo_apps/hello_world/cm4_core0/armgcc/ddr_debug/hello_world_m40.bin  (for DDR target, load in U-Boot)
{{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}}/demo_apps/hello_world/cm4_core0/armgcc/ddr_debug/hello_world_m40.elf  (for DDR target, load using debugger or remoteproc)
|
  {{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}}/demo_apps/hello_world/armgcc/debug/hello_world.bin  (for TCM target, load in U-Boot)
  {{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}}/demo_apps/hello_world/armgcc/debug/hello_world.bin  (for TCM target, load in U-Boot)
  {{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}}/demo_apps/hello_world/armgcc/debug/hello_world.elf  (for TCM target, load using debugger or remoteproc)
  {{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}}/demo_apps/hello_world/armgcc/debug/hello_world.elf  (for TCM target, load using debugger or remoteproc)
  {{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}}/demo_apps/hello_world/armgcc/ddr_debug/hello_world.bin  (for DDR target, load in U-Boot)
  {{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}}/demo_apps/hello_world/armgcc/ddr_debug/hello_world.bin  (for DDR target, load in U-Boot)
  {{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}}/demo_apps/hello_world/armgcc/ddr_debug/hello_world.elf  (for DDR target, load using debugger or remoteproc)
  {{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}}/demo_apps/hello_world/armgcc/ddr_debug/hello_world.elf  (for DDR target, load using debugger or remoteproc)
}}
Please visit Variscite's {{Varlink|MCUXpresso#Running_a_demo|{{#var:RELEASE_LINK}}|MCUXpresso Guide}} for instructions to run the demo using U-Boot or the Linux Remote Processor Framework.
Please visit Variscite's {{Varlink|MCUXpresso#Running_a_demo|{{#var:RELEASE_LINK}}|MCUXpresso Guide}} for instructions to run the demo using U-Boot or the Linux Remote Processor Framework.


Line 87: Line 194:
  JTAG Debbugger: J-Link PLUS: https://www.segger.com/products/debug-probes/j-link/models/j-link-plus/
  JTAG Debbugger: J-Link PLUS: https://www.segger.com/products/debug-probes/j-link/models/j-link-plus/
  ARM-JTAG-20-10 adapter: https://www.digikey.it/it/products/detail/olimex-ltd/ARM-JTAG-20-10/3471401
  ARM-JTAG-20-10 adapter: https://www.digikey.it/it/products/detail/olimex-ltd/ARM-JTAG-20-10/3471401
  Variscite Board: VAR-DT8MCustomBoard
  Variscite Board: {{#var:DEBUG_BOARD}}
Software<br>
Software<br>
You can see the Yocto release details at link:<br>
You can see the Yocto release details at link:<br>
Line 99: Line 206:


For this example we will use {{#var:DTB_DEBUG}}:
For this example we will use {{#var:DTB_DEBUG}}:
{{#ifeq: {{#var:HARDWARE_NAME}} | VAR-SOM-MX8 |
{{Note|'''Note:''' To debug the demos from linux user space we need to add the following lines to '''{{#var:DTB_RPMSG}}'''<br>
<pre>
&imx8qm_cm40 {
/delete-property/ power-domains;
};


&imx8qm_cm41 {
/delete-property/ power-domains;
};
</pre>
Save the changes, compile the device tree and update the SD card/eMMC.
}}}}
{{#ifeq: {{#var:HARDWARE_NAME}} | VAR-SOM-MX8X |
{{Note|'''Note:''' To debug the demos from linux user space we need to add the following lines to '''{{#var:DTB_RPMSG}}'''<br>
<pre>
&imx8x_cm4 {
/delete-property/ power-domains;
};
</pre>
Save the changes, compile the device tree and update the SD card/eMMC.
}}}}
From U-Boot
From U-Boot
   u-boot> setenv fdt_file {{#var:DTB_DEBUG}}
   => setenv fdt_file {{#var:DTB_DEBUG}} {{#var:USE_CM_STRING_UBOOT}}
   u-boot> saveenv
   => saveenv
   Saving Environment to MMC... Writing to MMC(1)... OK
   Saving Environment to MMC... Writing to MMC(1)... OK
   Power off / Power on the board
   Power off / Power on the board
From Linux
Or, from Linux
   $ fw_setenv fdt_file {{#var:DTB_DEBUG}}
   $ fw_setenv fdt_file {{#var:DTB_DEBUG}} {{#var:USE_CM_STRING_LINUX}}
   $ reboot
   $ reboot


Line 123: Line 251:


==Debug RPMSG demos==
==Debug RPMSG demos==
The RPMSG demos can be debugged only starting from U-Boot<br>
The RPMSG demos can be debugged only starting from U-Boot.<br>
You need even to change M4 Kernel Device Tree enabling rpmsg and disabling imx8mm-cm4<br>
You need even to change M4 Kernel Device Tree enabling rpmsg node and disabling cortex-m node.<br>
Edit arch/arm64/boot/dts/freescale/imx8mm-var-dart-dt8mcustomboard-m4.dtsi.<br>
 
==Change M4 Kernel Device Tree==
Edit arch/arm64/boot/dts/freescale/{{#var:DTB_RPMSG}}<br>
<pre>
<pre>
imx8mm-cm4 {
imx8mm-cm4 {
     ....
     ...
     ....
     ...
     status = "disabled";
     status = "disabled";
};
};


&rpmsg {
&rpmsg {
     ....
     ...
     ....
     ...
     status = "okay";
     status = "okay";
};
};
</pre>
</pre>
Save the changes.<br>
Save the changes.<br>
Compile the device tree and update the SD-Card/eMMC.<br>
Compile the device tree and update the SD card/eMMC.<br>
{{Note|'''Note:''' If rpmsg node is missing in the arch/arm64/boot/dts/freescale/{{#var:DTB_RPMSG}} file discard the [[#Debug RPMSG demos|Change M4 Kernel Device Tree]] section above}}
{{#ifeq: {{#var:HARDWARE_NAME}} | DART-MX8M |
For this example, we will debug pingpong demo mapped in TCM.
{{Note|'''Note:''' rpmsg demos mapped in DDR can't be debugged due to the disabled lmem caches need to have the demo working}}
$ cd ~/var-mcuxpresso/freertos-variscite
$ ./var_add_vscode_support.sh -b {{#var:BOARD_SDK}} -e {{#var:BOARD_FOLDER}}/multicore_examples/rpmsg_lite_pingpong_rtos/linux_remote -t tcm -d /opt/SEGGER/JLink
$ code {{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}}/multicore_examples/rpmsg_lite_pingpong_rtos/linux_remote/
|
For this example, we will debug pingpong demo mapped in DDR.
For this example, we will debug pingpong demo mapped in DDR.
{{#varexists:DEACTIVATE_LMEM_CACHE_PATCH |
<br>
  $ cd ~/var-mcuxpresso/freertos-variscite
  $ cd ~/var-mcuxpresso/freertos-variscite
{{#ifeq: {{#var:CORTEX_M_TYPE}} | m4 |
  $ git apply patches/{{#var:DEACTIVATE_LMEM_CACHE_PATCH}}
  $ git apply patches/{{#var:DEACTIVATE_LMEM_CACHE_PATCH}}
}}
  $ ./var_add_vscode_support.sh -b {{#var:BOARD_SDK}} -e {{#var:BOARD_FOLDER}}/multicore_examples/rpmsg_lite_pingpong_rtos/linux_remote -t ddr -d /opt/SEGGER/JLink
  $ ./var_add_vscode_support.sh -b {{#var:BOARD_SDK}} -e {{#var:BOARD_FOLDER}}/multicore_examples/rpmsg_lite_pingpong_rtos/linux_remote -t ddr -d /opt/SEGGER/JLink
  $ code {{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}}/multicore_examples/rpmsg_lite_pingpong_rtos/linux_remote/
  $ code {{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}}/multicore_examples/rpmsg_lite_pingpong_rtos/linux_remote/
{{Note|'''Note:''' Debugging applications mapped in the DDR, the use of SDK_DelayAtLeastUs function is not recommended<br>
|
because it produces a long delay time.<br>  
<br>
$ cd ~/var-mcuxpresso/freertos-variscite
$ ./var_add_vscode_support.sh -b {{#var:BOARD_SDK}} -e {{#var:BOARD_FOLDER}}/multicore_examples/rpmsg_lite_pingpong_rtos/linux_remote -t ddr -d /opt/SEGGER/JLink
$ code {{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}}/multicore_examples/rpmsg_lite_pingpong_rtos/linux_remote/
}}
}}
{{Note|'''Note:''' Debugging applications mapped in the DDR, the use of SDK_DelayAtLeastUs function is not recommended because it produces a long delay time.<br>
You can use vTaskDelay() instead.<br>
You can use vTaskDelay() instead.<br>
}}
}}
Line 157: Line 301:
Build application following the guide at the [[#Build_Demo_using_VS_Code|Build Demo using VS Code]] section above:<br>
Build application following the guide at the [[#Build_Demo_using_VS_Code|Build Demo using VS Code]] section above:<br>


Power on the Board and interrupt the boot in the U-Boot prompt<>
Power on the Board and interrupt the boot in the U-Boot prompt.<br>
From Visual Studio Code start Debugging<br>
From Visual Studio Code start Debugging.<br>
From U-Boot prompt<br>
From U-Boot prompt:<br>
  $ u-boot=> boot
  => boot
Waiting for completed boot kernel<br>
Waiting for completed boot kernel<br>
From Userspace prompt<br>
From Userspace prompt:<br>
  $ sysctl kernel.printk=7
  $ sysctl kernel.printk=7
  $ modprobe imx_rpmsg_pingpong
  $ modprobe imx_rpmsg_pingpong


if everything worked well the program will stop at the configured breakpoint<br>
If everything worked well the program will stop at the configured breakpoint:<br>


[[File:Vscode_MCUXpresso_RPMSG_StoppedAtBreakPoint.png]]
[[File:Vscode_MCUXpresso_RPMSG_StoppedAtBreakPoint.png]]


{{Note|'''Note:''' Debugging RPMSG demos be careful to set breakpoint or debug step by step because when the M core is stopped even A core is blocked}}
{{Note|'''Note:''' Debugging RPMSG demos be careful to set breakpoint or debug step by step because when the M core is stopped even A core is blocked}}

Latest revision as of 15:41, 23 May 2022

DART-MX8M-MINI - MCUXpresso 2.10.0 Development with VS Code

Overview

This guide demonstrates how to develop and cross compile applications for the DART-MX8M-MINI Cortex-m4 co-processor using Microsoft Visual Studio Code.

Please visit Variscite's MCUXpresso Guide for additional information about manually building demos, integration with Yocto, running applications from U-Boot and Linux, and JTAG debugging.

Setup Host Computer Environment

Follow the steps below to prepare a fresh Ubuntu 20.04 installation for VS Code debugging:

Install Dependencies

$ sudo apt-get -y update
$ sudo apt-get -y install build-essential gdb gdb-multiarch git cmake

Install VS Code

$ sudo snap install --classic code

Install VS Code Extensions

VS Code has a graphical interface for installing and managing extensions. To learn more, please see Using extensions in Visual Studio Code

For this guide, we will install the required extensions using the command line:

$ code --install-extension ms-vscode.cpptools
$ code --install-extension marus25.cortex-debug
$ code --install-extension dan-c-underwood.arm

Install Segger JLink

$ Download JLink_Linux_V760b_x86_64.deb from https://www.segger.com/downloads/jlink/
  Direct Download: https://www.segger.com/downloads/jlink/JLink_Linux_V760b_x86_64.deb
$ sudo dpkg -i JLink_Linux_V760b_x86_64.deb

The software will be installed in /opt/SEGGER folder


Install MCUXpresso Toolchain and SDK

Download and install GNU-ARM bare-metal toolchain:

$ mkdir ~/var-mcuxpresso
$ cd ~/var-mcuxpresso
$ wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/10-2020q4/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
$ tar xvf gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2

Download MCUXpresso SDK for the SOM:

$ cd ~/var-mcuxpresso
$ git clone https://github.com/varigit/freertos-variscite -b mcuxpresso_sdk_2.10.x-var01
$ cd freertos-variscite

Add Visual Studio Code support to the Variscite examples

Available Demos

All of the Variscite examples are located under the following folder.

~/var-mcuxpresso/freertos-variscite/boards/dart_mx8mm

Variscite provides a script to simplify the Project Configuration


Configure a single Project

For this example, we will configure the hello_world demo. However, the process is the same for all demos.

$ ./var_add_vscode_support.sh -b dart_mx8mm -e boards/dart_mx8mm/demo_apps/hello_world -t tcm -d /opt/SEGGER/JLink  (for TCM target)
$ ./var_add_vscode_support.sh -b dart_mx8mm -e boards/dart_mx8mm/demo_apps/hello_world -t ddr -d /opt/SEGGER/JLink  (for DDR target)

Configure all Projects

$ ./var_add_vscode_support.sh -b dart_mx8mm -e all -t tcm -d /opt/SEGGER/JLink  (for TCM target)
$ ./var_add_vscode_support.sh -b dart_mx8mm -e all -t ddr -d /opt/SEGGER/JLink  (for DDR target)


Note: Some J-Link debuggers support connecting to your host computer via Ethernet or Wi-Fi. To enable this, add the IP Address of your J-Link to launch.json:
$ vi ~/var-mcuxpresso/freertos-variscite/boards/dart_mx8mm/demo_apps/hello_world/.vscode/launch.json
{
   "configurations": [
   {
     "ipAddress": "<J-Link IP Address>"
   ...

Disable LMEM caches to debug demos mapped in DDR

Note: to debug applications mapped in DDR, is mandatory to deactivate the LMEM caches
$ cd ~/var-mcuxpresso/freertos-variscite
$ git apply patches/0001-iMX8M-MINI-deactivated-the-LMEM-caches-to-debug-in-e.patch

Please visit the SEGGER forum to additional information
https://forum.segger.com/index.php/Thread/2948-SOLVED-DEBUGGING-doesn-t-work-in-external-RAM-but-in-internal-RAM/?postID=11144&highlight=LMEM#post11144

Open a Demo in VS Code

For this example, we will use the hello_world demo mapped in TCM. However, the process is the same for all demos. From a terminal, launch VS Code and open the hello_world demo directory:

$ code ~/var-mcuxpresso/freertos-variscite/boards/dart_mx8mm/demo_apps/hello_world

VS Code should open and look similiar too:

Vscode mcuxpresso.png

Build Demo using VS Code

Vscode mcuxpresso run build task.png

If the build task completes successfully, the following output files will be generated:

~/var-mcuxpresso/freertos-variscite/boards/dart_mx8mm/demo_apps/hello_world/armgcc/debug/hello_world.bin  (for TCM target, load in U-Boot)
~/var-mcuxpresso/freertos-variscite/boards/dart_mx8mm/demo_apps/hello_world/armgcc/debug/hello_world.elf  (for TCM target, load using debugger or remoteproc)
~/var-mcuxpresso/freertos-variscite/boards/dart_mx8mm/demo_apps/hello_world/armgcc/ddr_debug/hello_world.bin  (for DDR target, load in U-Boot)
~/var-mcuxpresso/freertos-variscite/boards/dart_mx8mm/demo_apps/hello_world/armgcc/ddr_debug/hello_world.elf  (for DDR target, load using debugger or remoteproc)

Please visit Variscite's MCUXpresso Guide for instructions to run the demo using U-Boot or the Linux Remote Processor Framework.

Debugging with VS Code

Test Enviroment

Hardware

JTAG Debbugger: J-Link PLUS: https://www.segger.com/products/debug-probes/j-link/models/j-link-plus/
ARM-JTAG-20-10 adapter: https://www.digikey.it/it/products/detail/olimex-ltd/ARM-JTAG-20-10/3471401
Variscite Board: VAR-DT8MCustomBoard

Software
You can see the Yocto release details at link:

https://variwiki.com/index.php?title=DART-MX8M-MINI_Release_Notes&release=RELEASE_HARDKNOTT_V1.1_DART-MX8M-MINI

Connect Hardware

Connect J-Link PLUS to JTAG connector of Variscite board
Connect J-Link PLUS to Development PC via USB cable

Load dedicated device tree

Please visit Variscite's MCUXpresso Guide for instructions to load a dedicated device tree.

For this example we will use imx8mm-var-dart-dt8mcustomboard-m4.dtb:


From U-Boot

 => setenv fdt_file imx8mm-var-dart-dt8mcustomboard-m4.dtb 
 => saveenv
 Saving Environment to MMC... Writing to MMC(1)... OK
 Power off / Power on the board

Or, from Linux

 $ fw_setenv fdt_file imx8mm-var-dart-dt8mcustomboard-m4.dtb 
 $ reboot

Start Debugging

Open source code and add a breakpoint

Vscode MCUXpresso SettingBreakPoint.png

Start Debugging

Vscode MCUXpresso StartDebugging.png

if everything worked well the program will stop at the configured breakpoint

Vscode MCUXpresso StoppedAtBreakPoint.png

Debug RPMSG demos

The RPMSG demos can be debugged only starting from U-Boot.
You need even to change M4 Kernel Device Tree enabling rpmsg node and disabling cortex-m node.

Change M4 Kernel Device Tree

Edit arch/arm64/boot/dts/freescale/imx8mm-var-dart-dt8mcustomboard-m4.dtsi

imx8mm-cm4 {
    ...
    ...
    status = "disabled";
};

&rpmsg {
    ...
    ...
    status = "okay";
};

Save the changes.
Compile the device tree and update the SD card/eMMC.

Note: If rpmsg node is missing in the arch/arm64/boot/dts/freescale/imx8mm-var-dart-dt8mcustomboard-m4.dtsi file discard the Change M4 Kernel Device Tree section above

For this example, we will debug pingpong demo mapped in DDR.

$ cd ~/var-mcuxpresso/freertos-variscite
$ git apply patches/0001-iMX8M-MINI-deactivated-the-LMEM-caches-to-debug-in-e.patch
$ ./var_add_vscode_support.sh -b dart_mx8mm -e boards/dart_mx8mm/multicore_examples/rpmsg_lite_pingpong_rtos/linux_remote -t ddr -d /opt/SEGGER/JLink
$ code ~/var-mcuxpresso/freertos-variscite/boards/dart_mx8mm/multicore_examples/rpmsg_lite_pingpong_rtos/linux_remote/
Note: Debugging applications mapped in the DDR, the use of SDK_DelayAtLeastUs function is not recommended because it produces a long delay time.

You can use vTaskDelay() instead.

Vscode MCUXpresso SDK DelayAtLeastUs Replaced.png

Build application following the guide at the Build Demo using VS Code section above:

Power on the Board and interrupt the boot in the U-Boot prompt.
From Visual Studio Code start Debugging.
From U-Boot prompt:

=> boot

Waiting for completed boot kernel
From Userspace prompt:

$ sysctl kernel.printk=7
$ modprobe imx_rpmsg_pingpong

If everything worked well the program will stop at the configured breakpoint:

Vscode MCUXpresso RPMSG StoppedAtBreakPoint.png


Note: Debugging RPMSG demos be careful to set breakpoint or debug step by step because when the M core is stopped even A core is blocked