cancel
Showing results for 
Search instead for 
Did you mean: 

Stuck in xQueueSemaphoreTake()

debug
Associate III

Hi,

I would like to setup a system with a telnet server and I'm trying to follow this guide: https://controllerstech.com/stm32-ethernet-4-tcp-server/ but unfortunately, upon launch, the system gets stuck at line1438 in queue.c:

/* Cannot block if the scheduler is suspended. */

#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )

{

configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );

}

#endif

it's a bit odd because it appears like when I don't change the MEM_SIZE variable but leave it its default (1600) it appears to not be stuck after creation of the config but once I change it to 10*1024 (as it's shown in the link above) I do not seem to be able to undo it anymore but it keeps getting stuck on call to MX_LWIP_Init(). Why is this I'm wondering and how can I fix it?

5 REPLIES 5
Bob S
Principal

The code gets 'stuck" in queue.c because some function is waiting for a queue (or mutex) with a non-zero "wait" param BEFORE the FreeRTOS scheduler has started (osKernelStart() called).  That is not allowed - as the comment says, tasks cannot be suspended if the scheduler is not (yet) running.

Where in MX_LWIP_Init() is the code getting "stuck"?  Use the debugging tools, trace/step through the function.

If you are using dynamic allocation for your tasks, mutexes, queues, etc. then you definitely need to set MEM_SIZE much larger than the default 1600.  I don't know what you mean by "do not seem to be able to undo it anymore".

debug
Associate III

Hm? I've set MEM_SIZE to 10240 B now, would that be sufficient? 
My application is empty at the moment, I just configured the empty framework in CubeIDE. I haven't modifed anything in the init sequence and my StartDefaultTask() function only looks like this:

void StartDefaultTask(void const * argument)

{

/* init code for LWIP */

MX_LWIP_Init();

/* USER CODE BEGIN 5 */

/* Infinite loop */

for(;;)

{

osDelay(1);

}

/* USER CODE END 5 */

}

the init sequence is:

  1. HAL_Init()
  2. SystemClock_Config();
  3. MX_GPIO_Init();
  4. osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);

    defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);

  5. osKernelStart(); 

and the call stack when it hangs looks like this:

debug_0-1712753485428.png

What I see is happening is:

  1. MX_LWIP_Init() calls
  2. netif_add() calls
  3. init(netif) calls
  4. low_level_init(netif) calls
  5. HAL_ETH_Start_IT(&heth) calls
  6. ETH_UpdateDescriptor(heth) calls
  7. HAL_ETH_RxAllocateCallback(&buff) calls
  8. LWIP_MEMPOOL_ALLOC(RX_POOL) calls
  9. do_memp_malloc_pool(desc) calls
  10. SYS_ARCH_PROTECT(old_level) calls
  11. osMutexWait(lwip_sys_mutex, osWaitForever) calls<-- problem is invoked from here
  12. if (xSemaphoreTake(mutex_id, ticks) != pdTRUE) calls
  13. configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) ) HANGS

any hints on how I can fix this? I've attacghed the empty project as *.7z file

Do you call osKernelInitialize()?

debug
Associate III

Do you call osKernelInitialize()?

No, I don't see it being called anywhere but when I look at the implementation in cmis_os.c on line 141, it just shows the prototype without any content in the function:

/*********************** Kernel Control Functions *****************************/

/**

* @brief Initialize the RTOS Kernel for creating objects.

* @retval status code that indicates the execution status of the function.

* @note MUST REMAIN UNCHANGED: \b osKernelInitialize shall be consistent in every CMSIS-RTOS.

*/

osStatus osKernelInitialize (void);

not sure abou this, looks like it might have been kept for backwards compatibility or something?

Are you using CMSIS ver 1 or ver 2?  In cmsis_os2.c that function is defined and initializes the RTOS heap regions and sets the kernel state (which is needed by osKernelStart()).  I can't speak to CMSIS ver 1, never used it.