Semihosting with LinkServer in VS Code

For an university research project, I need to write some console output and the same time write a file with data from the embedded board to the host. A logical choice for this is using semihosting.

Semihosting with LinkServer in VS Code
Semihosting with LinkServer in VS Code

Outline

Semihosting is a technology from ARM. Using semihosting, the debugger can exchange data with the host and the application. For example writing messages to a console, or read/write files on the host. This makes it ideal for many embedded applications which lack file support or do not have a hardware connection for a terminal. The downside is that it requires an active debug session.

Many vendor libraries provide semihosting with their standard libraries. But it is easier and more efficient to directly use the semihosting calls from the application, see Using Semihosting the directĀ Way.

This article shows how to use semihosting with the NXP LinkServer in VS Code, using the NXP VS Code extension.

I use semihosting here to write console messages. Additionally I need to write a binary file from a memory address to a file. The binary file contains the assembly code and instructions of the special EZH co-processor from NXP.

Launch Configuration launch.json

To enable semihosting, I have to enable it using a postLaunchCommand:

      "postLaunchCommands": [
"mon semihosting ena"
],

Additionally, I have to pass the port to be used to the GDB for the debug probe:

          "gdbServerExtraArgs": [
"--semihost-port=4445"
]

Below is the launch.json I’m using:

{
"configurations": [
{
"type": "mcuxpresso-debug",
"name": "MCUXpresso-debug",
"request": "launch",
"cwd": "${workspaceFolder}",
"executable": {
"elf": ""
},
"stopAtSymbol": "main",
"probeSerialNumber": "",
"isAttach": false,
"skipBuildBeforeDebug": false,
"gdbInitCommands": [
"set remotetimeout 600",
"set debug-file-directory",
"set non-stop off"
],
"postLaunchCommands": [
"mon semihosting ena"
],
"gdbServerConfigs": {
"linkserver": {
"gdbServerCwd": "${workspaceFolder}",
"gdbServerExtraArgs": [
"--semihost-port=4445"
]
},
"segger": {},
"pemicro": {}
},
"showDevDebugOutput": "none",
}
]
}

Terminal

For the terminal output, I can use the ‘Serial Monitor‘ extension from Microsoft.

Configure it for:

  • Monitor mode: TCP
  • View Mode: Text
  • Host: localhost
  • Port: 4445 (or whatever you have specified in the launch.json)
Semihosting output in Serial Monitor
Semihosting output in Serial Monitor

Alternatively, I can use any TCP console application for this too.

Summary

Semihosting is a versatile way to write console messages to the host or even doing file I/O operations on the host. In my case I use it for output messages plus writing binary data from the embedded target as file on the host.

To enable semihosting with VS Code and NXP LinkServer, I can configure it in the launch.json file. From then on, I can read/write files on the host or send console messages.

Happy hosting šŸ™‚

Links

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.