Skip to main content
Associate III
April 9, 2024
Question

Stuck in xQueueSemaphoreTake()

  • April 9, 2024
  • 2 replies
  • 4573 views

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?

    2 replies

    Bob S
    Super User
    April 9, 2024

    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".

    debugAuthor
    Associate III
    April 10, 2024

    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

    Bob S
    Super User
    April 10, 2024

    Do you call osKernelInitialize()?

    Associate
    October 9, 2024

    Please check the stack size of the thread . .