Skip to main content
Explorer II
February 11, 2025
Solved

N6 VS Code launch.json for debugging

  • February 11, 2025
  • 5 replies
  • 3938 views

I'm having some difficulty getting debugging working in VSCode for the N6 series.  Does anyone have a sample one that actually works?  I'm obviously using the `stlink` server backend for `cortex-debug`, and I have tried using CubeIDE to get the exact gdb-server arguments used when it launches a debug session.  However even when I do that, I still end up with a corrupted stack pointer or missing sources?   The symptom is that the debug session says something to the effect of "??@<hex>  Unknown Source".  It also seems to have problems halting the core at startup.

Here's something representative of the config I'm using right now:

 

 

{
 "version": "0.2.0",
 "configurations": [
 {
 "cwd": "${workspaceFolder}",
 "executable": "${workspaceFolder}/FSBL/build/<my_project_name>.elf",
 "name": "Debug with ST-Link",
 "request": "launch",
 "type": "cortex-debug",
 "runToEntryPoint": "main",
 "showDevDebugOutput": "none",
 "servertype": "stlink",
 "serverArgs": [
 "-l", "1", "-s", "-m", "1", "-k",
 ],
 },
 ]
}

 

I've tried using a lot more arguments spelling out all the possible source locations, post-launch commands, etc, but so far it's been to no avail. Any help is appreciated!

 

    This topic has been closed for replies.
    Best answer by alister

    https://github.com/Marus/cortex-debug/issues/1104 lists a working VS Code launch.json (debug configuration) and includes a plausible STM32N6-specific explanation for it.

    5 replies

    ST Employee
    February 11, 2025

    Hello @JNT

    This issue is spotted and under investigation for STM32N6 product, the launch.json file is created with default STLink configuration  (Not specific to N6), so not able to start a debug session (Internal ticket number: 197953), I will keep you updated! 

     

    alisterAnswer
    Explorer
    April 9, 2025

    https://github.com/Marus/cortex-debug/issues/1104 lists a working VS Code launch.json (debug configuration) and includes a plausible STM32N6-specific explanation for it.

    Visitor II
    February 27, 2025

    @JNT  were you able to resolve this issue? I am struggling with the same issue currently, I cannot debug a program using the VSCode plugin.

     

    Additionally, there seems to be no way to debug a non-secure application in STM32CubeIDE, have you encountered that issue as well?

    JNTAuthor
    Explorer II
    March 10, 2025

    I haven't tried debugging a non-secure application yet, and I still haven't solved the debugging in VSCode problem unfortunately.  Hoping ST sorts this out so that we can actually get some real work in on this platform.  At the moment there are a lot of rough edges (RIF is another bane of my existence right now).

    Explorer II
    March 29, 2025

    I'm also unable to build and run for the STM32N6 Discovery board (STM32N6570-DK) with VSCode.

    The VSCode extension creates two launch.json profiles, which do not work for me:

    • Build & Debug Microcontroller - ST-Link
    • Attach to Microcontroller - ST-Link

    Given some of the comments above, it seemed possible the VSCode extension was not updated for the STM32N6 board.

    Unfortunately, I cannot find the source code for that extension to verify this.In an attempt to workaround this, I inspected the launch.json for STM32H5. This module uses TrustZone and generates the 6 launch.json profiles as expected:

    1. Build & Debug Secure Microcontroller - ST-Link
    2. Attach to Secure Microcontroller - ST-Link
    3. Build & Debug NonSecure Microcontroller - ST-Link
    4. Attach to NonSecure Microcontroller - ST-Link
    5. Build & Debug Microcontroller Secure and NonSecure - ST-Link
    6. Attach to Secure and NonSecure Microcontroller - ST-Link

    I modified VSCode launch.json + tasks.json to match the STM32H5 example, updating module references to STM32N6 as needed. I had to replace all "${command:STM32VSCodeExtension.trustZoneNonSecureTarget}" references in these files as VSCode extension was not populating these. Again, without extension source code access this is difficult to debug so I hardcoded for now.

    This made some "progress", however I now see an error upon flashing:

    * Executing task: STM32_Programmer_CLI --connect port=swd --download /Users/bradylaw/code/bitcam-bringup/bitcam/AppliNonSecure/build/bitcam_AppliNonSecure.elf -hardRst -rst --start
    
    -------------------------------------------------------------------
    STM32CubeProgrammer v2.19.0
    -------------------------------------------------------------------
    
    ST-LINK SN : 003800393333511831363730
    ST-LINK FW : V3J16M7
    Board : STM32N6570-DK
    Voltage : 3.27V
    SWD freq : 8000 KHz
    Connect mode: Normal
    Reset mode : Software reset
    Device ID : 0x486
    Revision ID : Rev B
    Device name : STM32N6xx
    Device type : MCU
    Device CPU : Cortex-M55
    BL Version : --
    
    Opening and parsing file: bitcam_AppliNonSecure.elf
    
    
    Memory Programming ...
    File : bitcam_AppliNonSecure.elf
    Size : 3.01 KB
    Address : 0x24100000
    
    
    
    Erasing memory corresponding to sector 0:
    Download in Progress:
    [==================================================] 100%
    
    File download complete
    Time elapsed during download operation: 00:00:00.006
    
    Hard reset is performed
    
    MCU Reset
    Error: Unable to run MCU!
    Error: Error code: 32

     The screen goes black but there is some kind of issue during the flashing step. Perhaps related to the FSBL with STM32N6 but I need to read up on that more.

    Could you point us towards the documented way to flash the discovery board using STM32_Programmer_CLI?

    Explorer II
    March 29, 2025

    Looking a bit closer, perhaps bootstrapping a project using STM32CubeN6 instead of STM32CubeMX is the way to go right now. It seems there are a lot of discovery kit specific instructions.

    https://github.com/STMicroelectronics/STM32CubeN6/blob/main/Projects/STM32N6570-DK/Templates/Template/README.md#how-to-use-it-

    https://www.st.com/resource/en/user_manual/um3249-getting-started-with-stm32cuben6-for-stm32n6-series-stmicroelectronics.pdf 

    There are probably ways to adapt those README instructions to some VSCode launch.json+tasks.json configuration, but those will depend upon the template you select.

    ST Employee
    May 6, 2025

    Hello everyone, 

    It should work with the port selection to access port 1 on N6

    Please add this line in your launch.json "serverApID": "1" in your stlink section.