MCUXpresso VSCode: Difference between revisions
No edit summary |
|||
Line 1: | Line 1: | ||
{{#vardefine:RELEASE_PARAM|{{#urlget:release}}}} <!-- | |||
--> {{#vardefine:RELEASE_PARAM|{{#var:RELEASE_PARAM|MCUXPRESSO_2.10.0_V1.0_DART-MX8M-MINI}}}} <!-- | |||
--> {{#vardefine:RELEASE_PARAM|{{#var:RELEASE_PARAM|MCUXPRESSO_2. | |||
--> {{#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}} <!-- | ||
--> {{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 = | |||
This guide demonstrates how to develop and cross compile applications for the {{#var:HARDWARE_NAME}} Cortex-{{#var:CORTEX_M_TYPE_UC}} co-processor using Microsoft Visual Studio Code. | This guide demonstrates how to develop and cross compile applications for the {{#var:HARDWARE_NAME}} Cortex-{{#var:CORTEX_M_TYPE_UC}} co-processor using Microsoft Visual Studio Code. | ||
Please visit Variscite's {{Varlink|MCUXpresso|{{#var:RELEASE_LINK}}|MCUXpresso Guide}} for additional information about manually building demos, integration with Yocto, running applications from U-Boot and Linux, and JTAG debugging. | Please visit Variscite's {{Varlink|MCUXpresso|{{#var:RELEASE_LINK}}|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= | |||
= Setup Host Computer Environment = | |||
Follow the steps below to prepare a fresh Ubuntu 20.04 installation for VS Code debugging: | Follow the steps below to prepare a fresh Ubuntu 20.04 installation for VS Code debugging: | ||
==Install Dependencies== | |||
== Install Dependencies == | |||
$ sudo apt-get -y update | $ sudo apt-get -y update | ||
$ sudo apt-get -y install build-essential gdb gdb-multiarch git cmake | $ sudo apt-get -y install build-essential gdb gdb-multiarch git cmake | ||
==Install VS Code== | |||
== Install VS Code == | |||
$ sudo snap install --classic code | $ sudo snap install --classic code | ||
==Install VS Code Extensions== | |||
== Install VS Code Extensions == | |||
VS Code has a graphical interface for installing and managing extensions. To learn more, please see [https://code.visualstudio.com/docs/introvideos/extend Using extensions in Visual Studio Code] | VS Code has a graphical interface for installing and managing extensions. To learn more, please see [https://code.visualstudio.com/docs/introvideos/extend Using extensions in Visual Studio Code] | ||
For this guide, we will install the required extensions using the command line: | For this guide, we will install the required extensions using the command line: | ||
$ code --install-extension ms-vscode.cpptools | $ code --install-extension ms-vscode.cpptools | ||
$ code --install-extension marus25.cortex-debug | |||
$ code --install-extension dan-c-underwood.arm | |||
== Install MCUXpresso Toolchain and SDK == | ==Install Segger JLink== | ||
$ Download JLink_Linux_V760b_x86_64.deb from https://www.segger.com/downloads/jlink/ | |||
$ 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: | Download and install GNU-ARM bare-metal toolchain: | ||
$ mkdir {{#var:SDK_PATH}} | $ mkdir {{#var:SDK_PATH}} | ||
$ cd {{#var:SDK_PATH}} | $ cd {{#var:SDK_PATH}} | ||
$ 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= | |||
= | ==Available Demos== | ||
== Available Demos == | |||
All of the Variscite examples are located under the following folder. | All of the Variscite examples are located under the following folder. | ||
{{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}} | {{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}} | ||
{{#if: {{#var:BOARD_FOLDER1}} | | {{#if: {{#var:BOARD_FOLDER1}} | | ||
{{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER1}} | |||
}} | }} | ||
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 {{#var:BOARD_SDK}} -e {{#var:BOARD_FOLDER}}/demo_apps/hello_world -t tcm -d /opt/SEGGER/JLink (for TCM target) | |||
$ ./var_add_vscode_support.sh -b {{#var:BOARD_SDK}} -e {{#var:BOARD_FOLDER}}/demo_apps/hello_world -t ddr -d /opt/SEGGER/JLink (for DDR target) | |||
==Configure all Projects== | |||
$ ./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) | |||
== | ==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> | |||
$ cd ~/var-mcuxpresso/freertos-variscite | |||
$ git apply patches/{{#var:DEACTIVATE_LMEM_CACHE_PATCH}} | |||
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/?postIDEQUAL11144&highlightEQUALLMEM#post11144 | |||
}} | |||
==Open a Demo in VS Code== | |||
For this example, we will use the hello_world demo. However, the process is the same for all demos. | For this example, we will use the hello_world demo. 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/ | $ 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: | ||
[[File:Vscode_mcuxpresso.png]] | [[File:Vscode_mcuxpresso.png]] | ||
== | =Build Demo using VS Code= | ||
[[File:Vscode_mcuxpresso_run_build_task.png]] | |||
If the build task completes successfully, the following output files will be generated: | |||
{{#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= | |||
==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-DT8MCutomBoard | |||
Software | |||
Hardknott (kernel 5.4.127) | |||
==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 {{Varlink|MCUXpresso#Prerequisites|{{#var:RELEASE_LINK}}|MCUXpresso Guide}} for instructions to load a dedicated device tree. | |||
For this example we will use {{#var:DTB_DEBUG}}: | |||
From U-Boot | |||
u-boot> setenv fdt_file imx8mm-var-dart-dt8mcustomboard-m4.dtb | |||
u-boot> saveenv | |||
Saving Environment to MMC... Writing to MMC(1)... OK | |||
Power off / Power on the board | |||
From Linux | |||
$ fw_setenv fdt_file imx8mm-var-dart-dt8mcustomboard-m4.dtb | |||
$ reboot | |||
==Start Debugging== | |||
Open source code and add a breakpoint | |||
[[File: | [[File:Vscode_MCUXpresso_SettingBreakPoint.png]] | ||
Start Debugging | |||
[[File:Vscode_MCUXpresso_StartDebugging.png]] | |||
if everything worked well the program will stop at the configured breakpoint | |||
[[File:Vscode_MCUXpresso_StoppedAtBreakPoint.png]] | |||
==Debug RPMSG demos== | |||
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> | |||
Edit arch/arm64/boot/dts/freescale/imx8mm-var-dart-dt8mcustomboard-m4.dtsi.<br> | |||
<pre> | |||
imx8mm-cm4 { | |||
.... | |||
.... | |||
status = "disabled"; | |||
}; | |||
&rpmsg { | |||
.... | |||
.... | |||
status = "okay"; | |||
}; | |||
</pre> | |||
Save the changes.<br> | |||
Compile the device tree and update the SD-Card/eMMC.<br> | |||
For this example, we will debug pingpong demo mapped in DDR. | |||
$ cd ~/var-mcuxpresso/freertos-variscite | |||
$ 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 | |||
$ 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> | |||
You can use vTaskDelay() instead.<br> | |||
}} | |||
[[File:Vscode_MCUXpresso_SDK_DelayAtLeastUs_Replaced.png]] | |||
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<> | |||
From Visual Studio Code start Debugging<br> | |||
From U-Boot prompt<br> | |||
$ u-boot=> boot | |||
Waiting for completed boot kernel<br> | |||
From Userspace prompt<br> | |||
$ sysctl kernel.printk=7 | |||
$ modprobe imx_rpmsg_pingpong | |||
if everything worked well the program will stop at the configured breakpoint<br> | |||
[[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}} |
Revision as of 19:24, 10 January 2022
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/ $ 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)
Disable LMEM caches to debug demos mapped in DDR
$ 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/?postIDEQUAL11144&highlightEQUALLMEM#post11144
Open a Demo in VS Code
For this example, we will use the hello_world demo. 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:
Build Demo using VS Code
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-DT8MCutomBoard
Software
Hardknott (kernel 5.4.127)
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 :
From U-Boot
u-boot> setenv fdt_file imx8mm-var-dart-dt8mcustomboard-m4.dtb u-boot> saveenv Saving Environment to MMC... Writing to MMC(1)... OK Power off / Power on the board
From Linux
$ fw_setenv fdt_file imx8mm-var-dart-dt8mcustomboard-m4.dtb $ reboot
Start Debugging
Open source code and add a breakpoint
Start Debugging
if everything worked well the program will stop at the configured breakpoint
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 and disabling imx8mm-cm4
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.
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/
because it produces a long delay time.
You can use vTaskDelay() instead.
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
$ u-boot=> 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