AN14120
AN14120
Debugging Cortex-M with VS Code on i.MX 8M, i.MX 8ULP, and i.MX 93
Rev. 2.0 — 13 March 2024 Application note
Document information
Information Content
Keywords AN14120, i.MX 8M, i.MX 93, Cortex-M, i.MX 8MN, i.MX 8MP, i.MX 8MM, VS Code, MCUXSDK,
MCUXpresso SDK, J-Link, SEGGER, Cortex-M debug
Abstract This document describes cross-compiling, deploying, and debugging an application for the i.MX
8M Family, i.MX 8ULP, and i.MX 93 Cortex-M processor using Microsoft Visual Studio Code.
NXP Semiconductors
AN14120
Debugging Cortex-M with VS Code on i.MX 8M, i.MX 8ULP, and i.MX 93
1 Introduction
This document describes cross-compiling, deploying, and debugging an application for the i.MX 8M Family,
i.MX 8ULP, and i.MX 93 Cortex-M processor using Microsoft Visual Studio Code.
Note: Check your card reader partition and replace sd<x> with your corresponding partition.
2 Prerequisites
Before starting to debug, several prerequisites must be met to have a properly configured debug environment.
AN14120 All information provided in this document is subject to legal disclaimers. © 2024 NXP B.V. All rights reserved.
1. Connect the i.MX board to the host PC via the DEBUG USB-UART and PC USB connector using a USB
cable. The Windows OS finds the serial devices automatically.
2. In Device Manager, under Ports (COM & LPT) find two or four connected USB Serial Ports (COM
<port_number>). One of the ports is used for the debug messages generated by the Cortex-A core, and the
other is for the Cortex-M core.
Before determining the right port needed, remember:
• [i.MX 8MP, i.MX 8ULP, i.MX 93]: There are four ports available in the Device Manger. The last port is for
Cortex-M debug and the second to last port is for Cortex-A debug, counting debug ports in ascending
order.
• [i.MX 8MM, i.MX 8MN]: There are two ports available in Device Manager. The first port is for Cortex-M
debug and the second port is for Cortex-A debug, counting debug ports in ascending order.
3. Open the right debug port using your preferred serial terminal emulator (for example PuTTY) by setting the
following parameters:
• Speed to 115200 bps
• 8 data bits
• 1 stop bit (115200, 8N1)
• No parity
4. Connect the SEGGER debug probe USB to the host, then connect the SEGGER JTAG connector to i.MX
board JTAG interface.
If the i.MX board JTAG interface has no guided connector, the orientation is determined by aligning the red wire
to the pin 1, as in Figure 1.
AN14120 All information provided in this document is subject to legal disclaimers. © 2024 NXP B.V. All rights reserved.
1. Download and install the latest version of Microsoft Visual Studio Code from the official website. If using
Windows as the host OS, choose the "Download for Windows" button from the Visual Studio Code main
page.
AN14120 All information provided in this document is subject to legal disclaimers. © 2024 NXP B.V. All rights reserved.
After all packages are installed, be sure that the J-Link probe is connected to the host PC. Then, check if the
probe is also available in the MCUXpresso extension under the DEBUG PROBES view, as shown in Figure 6.
AN14120 All information provided in this document is subject to legal disclaimers. © 2024 NXP B.V. All rights reserved.
AN14120 All information provided in this document is subject to legal disclaimers. © 2024 NXP B.V. All rights reserved.
1
2
3
AN14120 All information provided in this document is subject to legal disclaimers. © 2024 NXP B.V. All rights reserved.
"debug": {
"linkserver": {},
"pemicro": {},
"segger": {
"device": "MIMX8ML8_M7",
"interface": "JTAG"
},
},
After importing the example application successfully, it must be visible under the PROJECTS view. Also, the
project source files are visible in the Explorer (Ctrl + Shift + E) tab.
AN14120 All information provided in this document is subject to legal disclaimers. © 2024 NXP B.V. All rights reserved.
bluetooth {
compatible = "nxp,88w8987-bt";
};
AN14120 All information provided in this document is subject to legal disclaimers. © 2024 NXP B.V. All rights reserved.
};
Recompile the DTS:
$ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make freescale/imx93-11x11-
evk.dtb
Copy the newly created linux-imx/arch/arm64/boot/dts/freescale/imx93-11x11-evk.dtb
file on the boot partition of the SD card.
Copy the hello_world.elf file (located in the armgcc/debug directory) generated in Section 3 into
the boot partition of the SD card.
Boot the board in Linux. Since boot ROM does not kick off the Cortex-M when Cortex-A boots, the Cortex-
M must be manually started.
root@imx8mm-lpddr4-evk:/lib/firmware# cp /run/media/mmcblk2p1/
hello_world.elf /lib/firmware
root@imx93evk:~# echo hello_world.elf > /sys/class/remoteproc/remoteproc0/
firmware
root@imx93evk:~# echo start > /sys/class/remoteproc/remoteproc0/state
Note: The hello_world.elf file must be placed in the /lib/firmware directory.
2. For i.MX 8M
To support i.MX 8M Plus, the patch for SEGGER J-Link must be installed:
iar_segger_support_patch_imx8mp.zip.
After the download has finished, unzip the archive and copy the Devices directory and the
JLinkDevices.xml file from the JLink directory to C:\Program Files\SEGGER\JLink. If a Linux PC
is used, the target path is /opt/SEGGER/JLink.
• Debugging Cortex-M while Cortex-A is in U-Boot
In this case, nothing special must be done. Boot the board in U-Boot and jump to Section 5.
• Debugging Cortex-M while Cortex-A is in Linux
To run and debug the Cortex-M application in parallel with Linux running on Cortex-A, the specific clock
must be assigned and reserved for Cortex-M. It is done from within U-Boot.
Stop the board in U-Boot and run the below commands:
u-boot=> run prepare_mcore
u-boot=> boot
AN14120 All information provided in this document is subject to legal disclaimers. © 2024 NXP B.V. All rights reserved.
AN14120 All information provided in this document is subject to legal disclaimers. © 2024 NXP B.V. All rights reserved.
AN14120 All information provided in this document is subject to legal disclaimers. © 2024 NXP B.V. All rights reserved.
When a debugging session starts, a dedicated menu is displayed. The debugging menu has buttons for starting
the execution until a breakpoint fires up, pause the execution, step over, step into, step out, restart, and stop.
Also, we can see local variables, register values, watch some expression, and check call stack and breakpoints
in the left-hand navigator. These function regions are under the "Run and Debug" tab, and not in MCUXpresso
for VS Code.
AN14120 All information provided in this document is subject to legal disclaimers. © 2024 NXP B.V. All rights reserved.
AN14120 All information provided in this document is subject to legal disclaimers. © 2024 NXP B.V. All rights reserved.
7 Revision history
Table 1 summarizes the revisions to this document.
AN14120 All information provided in this document is subject to legal disclaimers. © 2024 NXP B.V. All rights reserved.
Legal information
Definitions Terms and conditions of commercial sale — NXP Semiconductors
products are sold subject to the general terms and conditions of commercial
sale, as published at https://www.nxp.com/profile/terms, unless otherwise
Draft — A draft status on a document indicates that the content is still agreed in a valid written individual agreement. In case an individual
under internal review and subject to formal approval, which may result agreement is concluded only the terms and conditions of the respective
in modifications or additions. NXP Semiconductors does not give any agreement shall apply. NXP Semiconductors hereby expressly objects to
representations or warranties as to the accuracy or completeness of applying the customer’s general terms and conditions with regard to the
information included in a draft version of a document and shall have no purchase of NXP Semiconductors products by customer.
liability for the consequences of use of such information.
Export control — This document as well as the item(s) described herein
may be subject to export control regulations. Export might require a prior
Disclaimers authorization from competent authorities.
Limited warranty and liability — Information in this document is believed Suitability for use in non-automotive qualified products — Unless
to be accurate and reliable. However, NXP Semiconductors does not give this document expressly states that this specific NXP Semiconductors
any representations or warranties, expressed or implied, as to the accuracy product is automotive qualified, the product is not suitable for automotive
or completeness of such information and shall have no liability for the use. It is neither qualified nor tested in accordance with automotive testing
consequences of use of such information. NXP Semiconductors takes no or application requirements. NXP Semiconductors accepts no liability for
responsibility for the content in this document if provided by an information inclusion and/or use of non-automotive qualified products in automotive
source outside of NXP Semiconductors. equipment or applications.
In no event shall NXP Semiconductors be liable for any indirect, incidental, In the event that customer uses the product for design-in and use in
punitive, special or consequential damages (including - without limitation - automotive applications to automotive specifications and standards,
lost profits, lost savings, business interruption, costs related to the removal customer (a) shall use the product without NXP Semiconductors’ warranty
or replacement of any products or rework charges) whether or not such of the product for such automotive applications, use and specifications, and
damages are based on tort (including negligence), warranty, breach of (b) whenever customer uses the product for automotive applications beyond
contract or any other legal theory. NXP Semiconductors’ specifications such use shall be solely at customer’s
own risk, and (c) customer fully indemnifies NXP Semiconductors for any
Notwithstanding any damages that customer might incur for any reason
liability, damages or failed product claims resulting from customer design and
whatsoever, NXP Semiconductors’ aggregate and cumulative liability
use of the product for automotive applications beyond NXP Semiconductors’
towards customer for the products described herein shall be limited in
standard warranty and NXP Semiconductors’ product specifications.
accordance with the Terms and conditions of commercial sale of NXP
Semiconductors.
Translations — A non-English (translated) version of a document, including
the legal information in that document, is for reference only. The English
Right to make changes — NXP Semiconductors reserves the right to
version shall prevail in case of any discrepancy between the translated and
make changes to information published in this document, including without
English versions.
limitation specifications and product descriptions, at any time and without
notice. This document supersedes and replaces all information supplied prior
Security — Customer understands that all NXP products may be subject to
to the publication hereof.
unidentified vulnerabilities or may support established security standards or
specifications with known limitations. Customer is responsible for the design
Suitability for use — NXP Semiconductors products are not designed,
and operation of its applications and products throughout their lifecycles
authorized or warranted to be suitable for use in life support, life-critical or
to reduce the effect of these vulnerabilities on customer’s applications
safety-critical systems or equipment, nor in applications where failure or
and products. Customer’s responsibility also extends to other open and/or
malfunction of an NXP Semiconductors product can reasonably be expected
proprietary technologies supported by NXP products for use in customer’s
to result in personal injury, death or severe property or environmental
applications. NXP accepts no liability for any vulnerability. Customer should
damage. NXP Semiconductors and its suppliers accept no liability for
regularly check security updates from NXP and follow up appropriately.
inclusion and/or use of NXP Semiconductors products in such equipment or
applications and therefore such inclusion and/or use is at the customer’s own Customer shall select products with security features that best meet rules,
risk. regulations, and standards of the intended application and make the
ultimate design decisions regarding its products and is solely responsible
for compliance with all legal, regulatory, and security related requirements
Applications — Applications that are described herein for any of these
concerning its products, regardless of any information or support that may be
products are for illustrative purposes only. NXP Semiconductors makes no
provided by NXP.
representation or warranty that such applications will be suitable for the
specified use without further testing or modification. NXP has a Product Security Incident Response Team (PSIRT) (reachable
at PSIRT@nxp.com) that manages the investigation, reporting, and solution
Customers are responsible for the design and operation of their
release to security vulnerabilities of NXP products.
applications and products using NXP Semiconductors products, and NXP
Semiconductors accepts no liability for any assistance with applications or
customer product design. It is customer’s sole responsibility to determine NXP B.V. — NXP B.V. is not an operating company and it does not distribute
whether the NXP Semiconductors product is suitable and fit for the or sell products.
customer’s applications and products planned, as well as for the planned
application and use of customer’s third party customer(s). Customers should
provide appropriate design and operating safeguards to minimize the risks
associated with their applications and products.
Trademarks
NXP Semiconductors does not accept any liability related to any default, Notice: All referenced brands, product names, service names, and
damage, costs or problem which is based on any weakness or default trademarks are the property of their respective owners.
in the customer’s applications or products, or the application or use by
customer’s third party customer(s). Customer is responsible for doing all NXP — wordmark and logo are trademarks of NXP B.V.
necessary testing for the customer’s applications and products using NXP i.MX — is a trademark of NXP B.V.
Semiconductors products in order to avoid a default of the applications
J-Link — is a trademark of SEGGER Microcontroller GmbH.
and the products or of the application or use by customer’s third party
customer(s). NXP does not accept any liability in this respect. Microsoft, Azure, and ThreadX — are trademarks of the Microsoft group of
companies.
AN14120 All information provided in this document is subject to legal disclaimers. © 2024 NXP B.V. All rights reserved.
Contents
1 Introduction ...................................................... 2
1.1 Software environment ........................................2
1.2 Hardware setup and equipment ........................ 2
2 Prerequisites .................................................... 2
2.1 PC Host – i.MX board debug connection ...........2
2.2 VS Code configuration .......................................3
2.3 MCUXpresso extension configuration ................5
2.4 Import MCUXpresso SDK ..................................6
2.5 Import an example application ...........................7
3 Building the application .................................. 8
4 Prepare the board for the debugger .............. 9
5 Running and debugging ............................... 11
6 Note about the source code in the
document ........................................................14
7 Revision history .............................................15
Legal information ...........................................16
Please be aware that important notices concerning this document and the product(s)
described herein, have been included in section 'Legal information'.