MCUXpresso VSCode extension: Difference between revisions

From Variscite Wiki
(Update 'Open a Demo in VS Code')
(Update 'Build Demo using VS Code')
Line 120: Line 120:
[[File:MCUXpresso-installer-window.png]]
[[File:MCUXpresso-installer-window.png]]


==Open a Demo in VS Code==
=Open a Demo in VS Code=
After the dependencies are installed, close the MCUXpresso Installer and click on ‘Import Software Repositories’:
After the dependencies are installed, close the MCUXpresso Installer and click on ‘Import Software Repositories’:


[[File:MCUXpresso-import-repository-1.png]]
[[File:MCUXpresso-import-repository-1.png]]


Go to the 'Local' tab, browse the previously git-cloned repository and import it:
Go to the 'Local' tab, browse the previously git-cloned repository and import it:
Line 133: Line 132:


[[File:MCUXpresso-import-example-1.png]]
[[File:MCUXpresso-import-example-1.png]]
Select the previously imported repository, the Arm GNU Toolchain (the Toolchain version might differ), the {{#var:HARDWARE_NAME}} board and the hello world demo. Use the previously created 'mcuxpresso-examples' directory for the 'Location':
[[File:MCUXpresso-import-example-2-rc.png]]
Click on 'Explorer' on the left upper corner to open the project source code:
[[File:MCUXpresso-hello-world-1-highlighted-rc.png]]


=Build Demo using VS Code=
=Build Demo using VS Code=
To build the project click on extension icon on the left and on 'Build Selected':
[[File:MCUXpresso-hello-world-2-highlighted-rc.png]]
If the build task completes successfully, a similar output as below should be generated:


[[File:Vscode_mcuxpresso_run_build_task.png]]
[[File:MCUXpresso-hello-world-3-rc.png]]


If the build task completes successfully, the following output files will be generated:
Please visit [https://variwiki.com/index.php?title=MCUXpresso&release={{#var:RELEASE_PARAM}}#Running_a_demo Variscite's MCUXpresso Guide] for instructions to run the demo using U-Boot or the Linux Remote Processor Framework.
{{#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.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.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.


=Debugging with VS Code=
=Debugging with VS Code=


==Test Enviroment==
==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:DEBUG_BOARD}}
Software<br>
You can see the Yocto release details at link:<br>
{{#var:YOCTO_RELEASE_NOTES_LINK}}<br>


==Connect Hardware==
==Connect Hardware==

Revision as of 22:33, 8 May 2024

VAR-SOM-MX8M-NANO - MCUXpresso 2.15.0 Development using MCUXpresso for VS Code extension

Overview

This guide demonstrates how to develop, cross compile and debug applications for the VAR-SOM-MX8M-NANO Cortex-m7 co-processor using NXP’s MCUXpresso for Visual Code extension.

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.

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: Symphony

Host Computer Environment Setup

Follow the steps below to prepare a fresh Ubuntu 22.04 installation for using the extension.

Note: cmake 3.20.5 is the required minimum version supported by MCUXpresso for VS Code extension and it is not supported by older Ubuntu versions.

Install Dependencies

$ sudo apt-get -y update
$ sudo apt-get -y install pip git

In order to access serial debugging ports your user must be in the ‘dialout’ group. To check this type:

$ groups

The above command will print all group memberships of the current user. If ‘dialout’ it is not printed, add your user to it:

$ sudo usermod -a -G dialout $USER

and restart your computer.

Download MCUXpresso SDK for the SOM:

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

Install VS Code

$ sudo snap install --classic code

Install MCUXpresso for VS Code Extension

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 MCUXpresso for VS Code extension:

MCUXpresso-extension.png

Install MCUXpresso Dependencies

In the extension ‘Welcome' tab, click on ‘Check Tool Dependencies’, ‘Open Installer’ and then, on the bottom right notification, 'Download’:

MCUXpresso-installer-download-highlight.png

Once the download finishes, the MCUXpresso Installer window will be displayed, showing multiple tools to install. For this guide we will install the following:

  • MCUXpresso SDK Developer;
  • SEGGER J-Link;
  • Arm GNU Toolchain;
  • Standalone Toolchain Add-ons.

MCUXpresso-installer-window.png

Open a Demo in VS Code

After the dependencies are installed, close the MCUXpresso Installer and click on ‘Import Software Repositories’:

MCUXpresso-import-repository-1.png

Go to the 'Local' tab, browse the previously git-cloned repository and import it:

MCUXpresso-import-repository-2.png

Click on ‘Import Example from Repository’:

MCUXpresso-import-example-1.png

Select the previously imported repository, the Arm GNU Toolchain (the Toolchain version might differ), the VAR-SOM-MX8M-NANO board and the hello world demo. Use the previously created 'mcuxpresso-examples' directory for the 'Location':

MCUXpresso-import-example-2-rc.png

Click on 'Explorer' on the left upper corner to open the project source code:

MCUXpresso-hello-world-1-highlighted-rc.png

Build Demo using VS Code

To build the project click on extension icon on the left and on 'Build Selected':

MCUXpresso-hello-world-2-highlighted-rc.png

If the build task completes successfully, a similar output as below should be generated:

MCUXpresso-hello-world-3-rc.png

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

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 imx8mn-var-som-symphony-m7.dtb:


From U-Boot

 => setenv fdt_file imx8mn-var-som-symphony-m7.dtb 
 => saveenv
 Saving Environment to MMC... Writing to MMC(1)... OK
 Power off / Power on the board

Or, from Linux

 $ fw_setenv fdt_file imx8mn-var-som-symphony-m7.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/imx8mn-var-som-symphony-m7.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/imx8mn-var-som-symphony-m7.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
$ ./var_add_vscode_support.sh -b som_mx8mn -e boards/som_mx8mn/multicore_examples/rpmsg_lite_pingpong_rtos/linux_remote -t ddr -d /opt/SEGGER/JLink
$ code ~/var-mcuxpresso/freertos-variscite/boards/som_mx8mn/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