Skip to main content
Graduate
October 21, 2025
Question

VSCode: RtosProxy error with big thread stack on ThreadX

  • October 21, 2025
  • 13 replies
  • 1157 views

During a debugging session, when `tx_thread_create` is called with a "big" stack size (1024*10 for example) and the "serverRtos" is enabled, the debugger is disconnected with an error: "Remote communication error. Target disconnected: No error."

 

Here the debug console logs (full log attached):

 

Spoiler
To client: {"seq":0,"type":"event","event":"output","body":{"category":"proxy","output":"RTOS proxy: Lost connection to GDB Server\r\n"}}
RTOS proxy: Lost connection to GDB Server
To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":"{\"label\":\"\",\"value\":[{\"label\":\"Driver\",\"value\":\"ThreadX\"},{\"label\":\"Kernel state\",\"value\":\"Not started\"}]}\n"}}
{"label":"","value":[{"label":"Driver","value":"ThreadX"},{"label":"Kernel state","value":"Not started"}]}
GDB result: 36 done
To client: {"seq":0,"type":"response","request_seq":25,"command":"cdt-gdb-tests/executeCommand","success":true,"body":{"status":"Ok","result":{},"console":["monitor rtos -m state\n","{\"label\":\"\",\"value\":[{\"label\":\"Driver\",\"value\":\"ThreadX\"},{\"label\":\"Kernel state\",\"value\":\"Not started\"}]}\n"]}}
To client: {"seq":0,"type":"event","event":"output","body":{"category":"proxy","output":"RTOS proxy: Proxy stopped.\r\n"}}
RTOS proxy: Proxy stopped.
GDB notify async: thread-exited,id="1",group-id="i1"
GDB notify async: thread-group-exited,id="i1"
GDB result: 37 error,msg="Remote communication error. Target disconnected: No error."

And the very basic code used:

/* USER CODE BEGIN Header */
/**
 ******************************************************************************
 * @file app_threadx.c
 * @author MCD Application Team
 * @brief ThreadX applicative file
 ******************************************************************************
 * @attention
 *
 * Copyright (c) 2025 STMicroelectronics.
 * All rights reserved.
 *
 * This software is licensed under terms that can be found in the LICENSE file
 * in the root directory of this software component.
 * If no LICENSE file comes with this software, it is provided AS-IS.
 *
 ******************************************************************************
 */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "app_threadx.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
TX_THREAD tx_app_thread;
/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
VOID th_main(ULONG thread_input)
{
 while (1)
 {
 tx_thread_sleep(1);
 }
}
TX_THREAD p_thMain;
#define MAIN_THREAD_STACK_SIZE (1024*10)
CHAR thMain_stack[MAIN_THREAD_STACK_SIZE];
/* USER CODE END PFP */

/**
 * @brief Application ThreadX Initialization.
 * memory_ptr: memory pointer
 * @retval int
 */
UINT App_ThreadX_Init(VOID *memory_ptr)
{
 UINT ret = TX_SUCCESS;
 TX_BYTE_POOL *byte_pool = (TX_BYTE_POOL*)memory_ptr;

 /* USER CODE BEGIN App_ThreadX_MEM_POOL */
 /* USER CODE END App_ThreadX_MEM_POOL */
 CHAR *pointer;

 /* Allocate the stack for tx app thread */
 if (tx_byte_allocate(byte_pool, (VOID**) &pointer,
 TX_APP_STACK_SIZE, TX_NO_WAIT) != TX_SUCCESS)
 {
 return TX_POOL_ERROR;
 }
 /* Create tx app thread. */
 if (tx_thread_create(&tx_app_thread, "tx app thread", tx_app_thread_entry, 0, pointer,
 TX_APP_STACK_SIZE, TX_APP_THREAD_PRIO, TX_APP_THREAD_PREEMPTION_THRESHOLD,
 TX_APP_THREAD_TIME_SLICE, TX_APP_THREAD_AUTO_START) != TX_SUCCESS)
 {
 return TX_THREAD_ERROR;
 }

 /* USER CODE BEGIN App_ThreadX_Init */
 tx_thread_create(&p_thMain, "Main Thread", th_main, 0, thMain_stack,
 MAIN_THREAD_STACK_SIZE, TX_APP_THREAD_PRIO, TX_APP_THREAD_PREEMPTION_THRESHOLD,
 TX_APP_THREAD_TIME_SLICE, TX_APP_THREAD_AUTO_START);

 /* USER CODE END App_ThreadX_Init */

 return ret;
}
/**
 * @brief Function implementing the tx_app_thread_entry thread.
 * thread_input: Hardcoded to 0.
 * @retval None
 */
void tx_app_thread_entry(ULONG thread_input)
{
 /* USER CODE BEGIN tx_app_thread_entry */
 while (1)
 {
 tx_thread_sleep(100);
 }
 /* USER CODE END tx_app_thread_entry */
}

 /**
 * @brief Function that implements the kernel's initialization.
 * None
 * @retval None
 */
void MX_ThreadX_Init(void)
{
 /* USER CODE BEGIN Before_Kernel_Start */

 /* USER CODE END Before_Kernel_Start */

 tx_kernel_enter();

 /* USER CODE BEGIN Kernel_Start_Error */

 /* USER CODE END Kernel_Start_Error */
}

/**
 * @brief App_ThreadX_LowPower_Timer_Setup
 * count : TX timer count
 * @retval None
 */
void App_ThreadX_LowPower_Timer_Setup(ULONG count)
{
 /* USER CODE BEGIN App_ThreadX_LowPower_Timer_Setup */

 /* USER CODE END App_ThreadX_LowPower_Timer_Setup */
}

/**
 * @brief App_ThreadX_LowPower_Enter
 * None
 * @retval None
 */
void App_ThreadX_LowPower_Enter(void)
{
 /* USER CODE BEGIN App_ThreadX_LowPower_Enter */

 /* USER CODE END App_ThreadX_LowPower_Enter */
}

/**
 * @brief App_ThreadX_LowPower_Exit
 * None
 * @retval None
 */
void App_ThreadX_LowPower_Exit(void)
{
 /* USER CODE BEGIN App_ThreadX_LowPower_Exit */

 /* USER CODE END App_ThreadX_LowPower_Exit */
}

/**
 * @brief App_ThreadX_LowPower_Timer_Adjust
 * None
 * @retval Amount of time (in ticks)
 */
ULONG App_ThreadX_LowPower_Timer_Adjust(void)
{
 /* USER CODE BEGIN App_ThreadX_LowPower_Timer_Adjust */
 return 0;
 /* USER CODE END App_ThreadX_LowPower_Timer_Adjust */
}

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

 

    This topic has been closed for replies.

    13 replies

    PierreBAuthor
    Graduate
    October 28, 2025

    Thank you for taking the time to help me.

    I tried implementing your suggestion, but unfortunately it doesn't work any better. The issue persists even after allocating the stack from the ThreadX byte pool as you described.

    I have the impression that the problem is elsewhere because it works correctly on STM32CubeIDE.

    Technical Moderator
    October 28, 2025

    could you try this project

    PierreBAuthor
    Graduate
    October 28, 2025

    It doesn't crash because the thMain_stack failed to allocate so the thread is not created.

    You must extend the TX_APP_MEM_POOL_SIZE

    PierreBAuthor
    Graduate
    November 19, 2025

    Hello,

    I'm following up on the debugger disconnection issue when using ThreadX with "serverRtos" enabled.

    I've managed to isolate the problem and create a minimal reproduction case:

    Hardware: STM32U5A5AJH6Q

    Steps to reproduce:

    1. Create a new project with STM32CubeMX
    2. In the Pinout tab:
      • System Core → SYS: Timebase Source = TIM6
      • System Core → ICACHE: Mode = 1-way
      • Power and Thermal → Low Power: Enable Power Saving mode
      • Power and Thermal → Power Saving: Power Regulator = SMPS
      • Middleware → THREADX: Enable Core
      • Middleware → THREADX: Enable "Generate App Init Code"
      • Middleware → THREADX: ThreadX Application Thread Stack Size = 1024*10
      • Middleware → THREADX: ThreadX Memory Pool Size = 1024*20
    3. In Project Manager:
      • Toolchain/IDE = CMake
      • Minimum Heap Size = 0x20000
      • Minimum Stack Size = 0x40000
    4. Generate code
    5. In launch.json, enable "serverRtos"
    6. Start debug session

    Result: The debugger disconnects with the error "Remote communication error. Target disconnected: No error."

    Important observation: When I generate the exact same project with STM32CubeIDE (instead of CMake) and enable "serverRtos", everything works correctly.

    Attached to this post you will find an archive where you just need to regenerate the solution. I only kept the app_threadx file because I added the following code in the tx_app_thread_entry thread:

     
    void tx_app_thread_entry(ULONG thread_input)
    {
     /* USER CODE BEGIN tx_app_thread_entry */
     while (1)
     {
     tx_thread_sleep(100);
     }
     /* USER CODE END tx_app_thread_entry */
    }