Flashdownload with Linkserver: connect to target under reset required

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Flashdownload with Linkserver: connect to target under reset required

Jump to solution
111 Views
m_p
Contributor I
Hello,
 
we are using the MCU-Link debug adapter and a Kinetis K22 microcontroller.
For automation purposes we want to use Linkserver to download an image into the flash.
If the target controller is empty this works without a problem. 
But now we have an application, where we reassign the SWD debug pins after the application starts running.
Once the application has started the debug pins are used for a different purpose and it is not possible to connect to the controller via SWD.
This means that it is necessary to hold the hardware reset line while connecting to the target.
This exact process is working under Keil uvision IDE with the MCU-Link selected as a CMSIS-DAP debugger. There the setting is called "connect under reset", with "HW reset" selected.
Now we want to be able to do the same with the Linkserver tool. 
But I cannot find this option for the flash command.
I have already experimented with a script to first issue a reset with "wiretimedreset" and then start linkserver, but this is not fast enough. The application is already running when the MCU-Link tries to connect.
I also tried to make a script that holds the reset line with "wireholdreset" but it seems like the linkserver is removing the reset early on and then it cannot connect.
I also know about the connect scripts, but the failure actually happens before this script is called:
 
linkserver output:
INFO: Selected device MK22FN512xxx12:TWR-K22F120M
INFO: Getting available probes
INFO: Selecting probe by index
INFO: Selected probe #1 12Z1C04R3SI0T (MCU-LINK (r0FF) CMSIS-DAP V2.263)
INFO: MCU-Link firmware update `check`: not supported on probe ([12Z1C04R3SI0T] [MCU-LINK (r0FF) CMSIS-DAP V2.263]). Only probes running firmware V3.122 or later can be updated automatically
Firmware update `check`: not supported - the update cannot be performed
Ns: LinkServer RedlinkMulti Driver v25.3 (Mar 25 2025 18:34:18 - crt_emu_cm_redlink.exe build 945)
Pc: ( 0) Reading remote configuration
Wc(03). No cache support.
Nc: Found generic directory XML file in <redacted>
Pc: ( 5) Remote configuration complete
Nc: Reconnected to existing LinkServer process.
Nc: Connecting to probe 1 core 0 (using server started externally) reports:
'Ee(42). Could not connect to core.'
Nc: Retrying...
Nc: Reconnected to existing LinkServer process.
Nc: Server OK but no connection to probe 1 core 0 (after 3 attempts) - Ee(42). Could not connect to core.
Wc: ============= SCRIPT: kinetisconnect.scp =============
Wc: Kinetis Connect Script
Wc: Connecting to Probe Index = 1
Wc: Error: Probe not connected
Wc: Error: Wire Ack Fault - target connected?
Wc: Assert NRESET
Wc: Reset pin state: 00
Wc: Error: Wire not connected
Wc: Power up Debug
Wc: Error: Wire not connected
Wc: Error: Wire not connected
Wc: No Debug Power
Wc: ============= END SCRIPT =============================
 
So what we need is an option for linkserver to hold the reset line until it takes control of the microcontroller and writes the flash algorithm.
I think this option would also be very helpful in other cases, where the microcontroller is in an unpredictable state.
So is there a way to do this with linkserver?
 
Thank you for any help.
Tags (2)
0 Kudos
Reply
1 Solution
60 Views
m_p
Contributor I

Hello Diego,

thank you for your comment.

I have found a solution, but it is not in the reset scripts. 

As far as I understand the reset scripts are called after the flash download is finished. But this is not what I needed.

Just to state the problem again. what I need is that the reset line is activated before the debug connection is established.

I want to use the Linkserver as a standalone tool to program boards. So I am running it from a batch file in a command line window.

But your post made me look at the preconnect scripts.

In the command line you can call the linkserver.exe with a .json configuration file. This configuration file determines which scripts are called. In all the examples I have looked at there was no preconnect script.

The schema file "LinkServer_XXXX\devices\devices.schema.json" shows how to add the script into the configuration file.

However the documentation on this is not very clear.

For reference here is the modified configuration file:

{
  "copyright": "Copyright 2023 NXP",
  "license": "SPDX-License-Identifier: BSD-3-Clause",
  "version": "1.0.0",
  "vendor": "NXP",
  "devices": [
    {
      "board": "TWR-K22F120M",
      "device": {
        "name": "MK22FN512xxx12",
        "family": "K2x",
        "memory": [
          {
            "location": "0x00000000",
            "size": "0x00080000",
            "type": "Flash",
            "flash-driver": "FTFA_2K.cfx"
          },
          {
            "location": "0x20000000",
            "size": "0x00010000",
            "type": "RAM"
          },
          {
            "location": "0x1fff0000",
            "size": "0x00010000",
            "type": "RAM"
          }
        ],
        "cores": [
          {
            "type": "cm4",
            "name": "cm4"
          }
        ]
      },
      "debug": {
        "protocol": "swd",
        "swo": true,
        "preconnect-script": "preconnect_HOLD_RESET.scp",
        "connect-script": "kinetisconnect.scp",
        "masserase-script": "kinetismasserase.scp"
      }
    }
  ]
}

Here is the preconnect script that i wrote:

1	Print "Preonnect Script"
10  REM check for debug probes
20  PROBELIST
30  REM open connection to debug probe
40  PROBEOPENBYINDEX a%
50  REM set the reset line
60  WIREHOLDRESET a% 0

Missing fact: the preconnect scripts have to be located in the folder "Linkserver_XXXX\binaries\ToolScripts\". If they are in the "Scripts"-Folder they are not found. Also there is no error message that the script is not found.

Also the print statement in the .scp file is not showing up in the command line output.

Now, everytime I run linkserver.exe with this configuration, I can connect to the microcontroller without a problem.

View solution in original post

Tags (2)
3 Replies
85 Views
diego_charles
NXP TechSupport
NXP TechSupport

Hi @m_p 

Thank you for reaching out!

I think that we could test using a custom reset script. By looking the MCUXpresso IDE documentation, we can see that there are some ways to handle how debugger manages reset, appart from connect.

diego_charles_0-1744645730955.png

You could try these options but there is the option for  reset script.

diego_charles_1-1744645781857.png

This is further described here:

diego_charles_2-1744646044418.png

 

I did not find a Kinetis reset script, on  particular, but in the linksersver there are some reset scripts for other MCUs, they may help as referece , example path is C:\nxp\LinkServer_1.5.30\binaries\Scripts

Please let me know if this helps, or any other related question you may have.

Diego

 

0 Kudos
Reply
61 Views
m_p
Contributor I

Hello Diego,

thank you for your comment.

I have found a solution, but it is not in the reset scripts. 

As far as I understand the reset scripts are called after the flash download is finished. But this is not what I needed.

Just to state the problem again. what I need is that the reset line is activated before the debug connection is established.

I want to use the Linkserver as a standalone tool to program boards. So I am running it from a batch file in a command line window.

But your post made me look at the preconnect scripts.

In the command line you can call the linkserver.exe with a .json configuration file. This configuration file determines which scripts are called. In all the examples I have looked at there was no preconnect script.

The schema file "LinkServer_XXXX\devices\devices.schema.json" shows how to add the script into the configuration file.

However the documentation on this is not very clear.

For reference here is the modified configuration file:

{
  "copyright": "Copyright 2023 NXP",
  "license": "SPDX-License-Identifier: BSD-3-Clause",
  "version": "1.0.0",
  "vendor": "NXP",
  "devices": [
    {
      "board": "TWR-K22F120M",
      "device": {
        "name": "MK22FN512xxx12",
        "family": "K2x",
        "memory": [
          {
            "location": "0x00000000",
            "size": "0x00080000",
            "type": "Flash",
            "flash-driver": "FTFA_2K.cfx"
          },
          {
            "location": "0x20000000",
            "size": "0x00010000",
            "type": "RAM"
          },
          {
            "location": "0x1fff0000",
            "size": "0x00010000",
            "type": "RAM"
          }
        ],
        "cores": [
          {
            "type": "cm4",
            "name": "cm4"
          }
        ]
      },
      "debug": {
        "protocol": "swd",
        "swo": true,
        "preconnect-script": "preconnect_HOLD_RESET.scp",
        "connect-script": "kinetisconnect.scp",
        "masserase-script": "kinetismasserase.scp"
      }
    }
  ]
}

Here is the preconnect script that i wrote:

1	Print "Preonnect Script"
10  REM check for debug probes
20  PROBELIST
30  REM open connection to debug probe
40  PROBEOPENBYINDEX a%
50  REM set the reset line
60  WIREHOLDRESET a% 0

Missing fact: the preconnect scripts have to be located in the folder "Linkserver_XXXX\binaries\ToolScripts\". If they are in the "Scripts"-Folder they are not found. Also there is no error message that the script is not found.

Also the print statement in the .scp file is not showing up in the command line output.

Now, everytime I run linkserver.exe with this configuration, I can connect to the microcontroller without a problem.

Tags (2)
55 Views
diego_charles
NXP TechSupport
NXP TechSupport

Hi @m_p 

Thank you very much, I am glad  that you  shared the solution you have found, it may help other users too ! My apologies, yes, it makes more sense to use preconnect script as it prepares the MCU for initial debug. 

Diego

0 Kudos
Reply