MCUXpresso VSCode Helper Script: Difference between revisions
No edit summary |
|||
Line 127: | Line 127: | ||
{{#ifeq: {{#var:HARDWARE_NAME}} | VAR-SOM-MX8 | | {{#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> | {{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 cortex-m core id is missing the default is cm_c0 | If the cortex-m core id is missing, the default is cm_c0 | ||
}}}} | }}}} | ||
==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. |
Revision as of 09:19, 18 May 2022
Overview
This guide demonstrates how to develop and cross compile applications for the VAR-SOM-MX8 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/9-2020q2/gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux.tar.bz2 $ tar xvf gcc-arm-none-eabi-9-2020-q2-update-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.9.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/som_mx8qm
Variscite provides a script to simplify the Project Configuration
If the cortex-m core id is missing, the default is cm_c0
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 -e boards/som_mx8qm/demo_apps/hello_world -t tcm -d /opt/SEGGER/JLink (for TCM target) $ ./var_add_vscode_support.sh -b -e boards/som_mx8qm/demo_apps/hello_world -t ddr -d /opt/SEGGER/JLink (for DDR target)
Configure all Projects
$ ./var_add_vscode_support.sh -b -e all -t tcm -d /opt/SEGGER/JLink (for TCM target) $ ./var_add_vscode_support.sh -b -e all -t ddr -d /opt/SEGGER/JLink (for DDR target)
$ vi ~/var-mcuxpresso/freertos-variscite/boards/som_mx8qm/demo_apps/hello_world/.vscode/launch.json { "configurations": [ { "ipAddress": "<J-Link IP Address>" ...
Disable LMEM caches to debug demos mapped in DDR
$ cd ~/var-mcuxpresso/freertos-variscite $ git apply patches/0002-i.MX8QM-CM40-deactivated-the-LMEM-caches-to-debug-in.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/som_mx8qm/demo_apps/hello_world/cm4_core0
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/som_mx8qm/demo_apps/hello_world/cm4_core0/armgcc/debug/hello_world_m40.bin (for TCM target, load in U-Boot) ~/var-mcuxpresso/freertos-variscite/boards/som_mx8qm/demo_apps/hello_world/cm4_core0/armgcc/debug/hello_world_m40.elf (for TCM target, load using debugger or remoteproc) ~/var-mcuxpresso/freertos-variscite/boards/som_mx8qm/demo_apps/hello_world/cm4_core0/armgcc/ddr_debug/hello_world_m40.bin (for DDR target, load in U-Boot) ~/var-mcuxpresso/freertos-variscite/boards/som_mx8qm/demo_apps/hello_world/cm4_core0/armgcc/ddr_debug/hello_world_m40.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: Symphony
Software
You can see the Yocto release details at link:
https://variwiki.com/index.php?title=VAR-SOM-MX8_Release_Notes&release=RELEASE_HARDKNOTT_V1.0_VAR-SOM-MX8
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 imx8qm-var-som-symphony-lvds-m4.dtb:
From U-Boot
=> setenv fdt_file imx8qm-var-som-symphony-lvds-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 imx8qm-var-som-symphony-lvds-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 node and disabling cortex-m node
Change M4 Kernel Device Tree
Edit arch/arm64/boot/dts/freescale/imx8qm-var-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/0002-i.MX8QM-CM40-deactivated-the-LMEM-caches-to-debug-in.patch $ ./var_add_vscode_support.sh -b -e boards/som_mx8qm/multicore_examples/rpmsg_lite_pingpong_rtos/linux_remote -t ddr -d /opt/SEGGER/JLink $ code ~/var-mcuxpresso/freertos-variscite/boards/som_mx8qm/multicore_examples/rpmsg_lite_pingpong_rtos/linux_remote/
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
=> 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