Developing Toolchain for Cortex-M4 in Visual Studio Code

Hi,
I am using Verdin iMX8M with Dahlia Carrier Board and I’m trying to do a bare metal development for the Cortex-M4 Chip. I am using VSCode on Windows 11 for this purpose with all the recommended extensions installed from this guide. My goal is to be able to deploy and debug the code on the M-Chip over ARM-USB-OCD-H connector and OpenOCD. When I open one of the examples from the MCUXpresso SDK, the build is successfull using the build scripts provided (e.g. build_all.bat).
But when I try building through the VSCode I get the following error:

[main] Configuring folder: int_loopback_transfer
[driver] Removing c:/workspace/int_loopback_transfer/build/CMakeCache.txt
[driver] Removing c:\workspace\int_loopback_transfer\build\CMakeFiles
[proc] Executing command: "C:/Program Files/CMake/bin/cmake.exe" --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug "-DCMAKE_C_COMPILER:FILEPATH=C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.10\bin\arm-none-eabi-gcc.exe" "-DCMAKE_CXX_COMPILER:FILEPATH=C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.10\bin\arm-none-eabi-g++.exe" -Sc:/workspace/int_loopback_transfer/armgcc -Bc:/workspace/int_loopback_transfer/build -G "MinGW Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The ASM compiler identification is GNU
[cmake] -- Found assembler: C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin/arm-none-eabi-gcc.exe
[cmake] -- The C compiler identification is GNU 10.3.1
[cmake] -- The CXX compiler identification is GNU 10.3.1
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - failed
[cmake] -- Check for working C compiler: C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin/arm-none-eabi-gcc.exe
[cmake] -- Check for working C compiler: C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin/arm-none-eabi-gcc.exe - broken
[cmake] CMake Error at C:/Program Files/CMake/share/cmake-3.23/Modules/CMakeTestCCompiler.cmake:69 (message):
[cmake]   The C compiler
[cmake]
[cmake]     "C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin/arm-none-eabi-gcc.exe"
[cmake]
[cmake]   is not able to compile a simple test program.
[cmake]
[cmake]   It fails with the following output:
[cmake]
[cmake]     Change Dir: C:/workspace/int_loopback_transfer/build/CMakeFiles/CMakeTmp
[cmake]
[cmake]     Run Build Command(s):C:/MinGW/bin/mingw32-make.exe -f Makefile cmTC_9a74a/fast && C:/MinGW/bin/mingw32-make.exe  -f CMakeFiles\cmTC_9a74a.dir\build.make CMakeFiles/cmTC_9a74a.dir/build
[cmake]     mingw32-make.exe[1]: Entering directory 'C:/workspace/int_loopback_transfer/build/CMakeFiles/CMakeTmp'
[cmake]     Building C object CMakeFiles/cmTC_9a74a.dir/testCCompiler.c.obj
[cmake]     C:\PROGRA~2\GNUARM~1\102021~1.10\bin\AR19DD~1.EXE    -o CMakeFiles\cmTC_9a74a.dir\testCCompiler.c.obj -c C:\workspace\int_loopback_transfer\build\CMakeFiles\CMakeTmp\testCCompiler.c
[cmake]     C:\PROGRA~2\GNUARM~1\102021~1.10\bin\AR19DD~1.EXE CMakeFiles/cmTC_9a74a.dir/testCCompiler.c.obj -o cmTC_9a74a
[cmake]     c:/progra~2/gnuarm~1/102021~1.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: c:/progra~2/gnuarm~1/102021~1.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/lib\libc.a(lib_a-exit.o): in function exit':
[cmake]     exit.c:(.text.exit+0x2c): undefined reference to _exit'
[cmake]     collect2.exe: error: ld returned 1 exit status
[cmake]     CMakeFiles\cmTC_9a74a.dir\build.make:97: recipe for target 'cmTC_9a74a' failed
[cmake]     mingw32-make.exe[1]: *** [cmTC_9a74a] Error 1
[cmake]     mingw32-make.exe[1]: Leaving directory 'C:/workspace/int_loopback_transfer/build/CMakeFiles/CMakeTmp'
[cmake]     Makefile:126: recipe for target 'cmTC_9a74a/fast' failed
[cmake]     mingw32-make.exe: *** [cmTC_9a74a/fast] Error 2
[cmake]
[cmake]
[cmake]
[cmake]
[cmake]
[cmake]   CMake will not be able to correctly generate this project.
[cmake] Call Stack (most recent call first):
[cmake]   CMakeLists.txt:25 (project)
[cmake]
[cmake]
[cmake] -- Configuring incomplete, errors occurred!



When I open the project inside the VSCode, CMake extensions asks for a location of the CMakeLists.txt file, which I provide and it can be seen inside the settings.json:

"cmake.sourceDirectory": "\${workspaceFolder}/armgcc"


Other than that I made no changes the settings.
I found here that this problem is usually solved with a flag:

--specs=nosys.specs


But as much as I can see flags.cmake already contains this flag.
I am inexperienced with such complicated makefile as the template project provide. Is there anyone who had similiar problems that could share their VSCode settings?
Thanks!

Hi @swiss,

Thanks for reporting this. I’ll have to try this here on my side and I’ll reply to you as soon as I have something.

Best Regards,
Hiago.

Hi @swiss,

Sorry for the delay. I tried this on my side and I could get it working because CMake isn’t able to find the right toolchain. That’s the problem you’re having. When we run ./build_all through the terminal, we need to export a variable for this script which tells where it needs to look for the toolchain. In Linux OS, the command is:

export ARMGCC_DIR=/path/to/toolchain


VSCode doesn’t know where the right toolchain is located. I’ll still try here on my side and I’ll let you know if I found something.

Despite of that, I would like to recommend you a different IDE, since you’re using Windows, there is one IDE called IAR. If you look into the Getting Started with MCUXpresso SDK for EVK-MIMX8MM document (should be with your SDK), there is one topic called 4 Run a demo application using IAR, there you’ll see NXP recommending this software for Windows users. Also, you’ll see how to compile you’re binary with CMake and debug the Cortex-M with this IDE. If you want to take a look into that, perhaps you’ll find it easier to use.

Anyway, for now, the only way to build the code with VSCode is using the Windows terminal inside VSCode and running ./build_all.bat.

Regarding the debugging part, were you able to debug your M4 with OpenOCD?
I could debug it here on my side without problems, but I used JLink from Segger and GDB Server.

Best Regards,
Hiago.

Hi @hfranco.tx,
I actually wasn’t able to run the OpenOCD.
To be honest I am not pleased that IAR and JLink are the only combo that works, compared to VSCode and OpenOCD. Both the IAR and JLink are much more expensive approaches. Thank you for your answer nontheless.
I will open a new topic concering the OpenOCD debugger issues.

1 Like

Hi @swiss,

You are right, JLink and IAR is a more expensive approach. Compared to OpenOCD, it’s easier to set up everything and get it working. OpenOCD requires a specific code to set up everything through FTDI, which we, unfortunately, don’t have at the moment.

I have a preliminary code that I’ve been working and it’s not working yet.
I’ve also opened an NXP ticket here: https://community.nxp.com/t5/i-MX-Processors/iMX8M-Cortex-M4-debug-with-FTDI-and-OpenOCD/m-p/1497425#M193171
I will send it to you when I have something that is working.
This code is working to debug Cortex-A, but not Cortex-M yet.

Sure! We can discuss better about it in a new topic. Thank you!

Kind regards,
Hiago.

1 Like

Yes I am also stuck at the JTAG-DP STICKY ERROR. Also I am much more interested in M core debug than the A core. I’m currently simply running the code automatically on boot (as we discussed here) but I have no way to debug it which is frustrating to say the least.
Thank you for your answer anyway, and please keep me posted if you manage to run the debugger somehow.

Hi @swiss,

I know that is frustrating, I feel the same. I will get you posted on any updates that I might have here.

Kind regards,
Hiago.

1 Like

Hi @swiss,

As I said in this thread, now we have a guide on how to use the VSCode with the JLink device here: Cortex-M Development Using VSCode | Toradex Developer Center. I’m still looking into the OpenOCD mailing lists to get help with the Cortex-M4.

I’ll be closing this thread for now and I’ll let you know when I have some updates on the OpenOCD code.

Best Regards,
Hiago.

1 Like