Photon hangs - never exits xQueueGenericReceive

This is something I have experienced multiple times before - photons light control is no longer working (The LED is a static cyan or not on at all) and the user application is not executing nor is there any cloud connection with the device.

Debug information from JTAG:

#0  xQueueGenericReceive (xQueue=0x856f78f8, pvBuffer=pvBuffer@entry=0x0, xTicksToWait=xTicksToWait@entry=1, xJustPeeking=xJustPeeking@entry=0) at WICED/RTOS/FreeRTOS/ver7.5.2/Source/queue.c:1165
#1  0x0803138e in sys_sem_new (sem=sem@entry=0x20005bdc <memp_memory_NETCONN_base+828>, count=count@entry=0 '\000') at WICED/network/LwIP/WWD/FreeRTOS/sys_arch.c:239
#2  0x080267e2 in netconn_alloc (t=<optimized out>, callback=callback@entry=0x0) at WICED/network/LwIP/ver1.4.0.rc1/src/api/api_msg.c:598
#3  0x08025eac in netconn_new_with_proto_and_callback (t=t@entry=NETCONN_TCP, proto=proto@entry=0 '\000', callback=callback@entry=0x0) at WICED/network/LwIP/ver1.4.0.rc1/src/api/api_lib.c:73
#4  0x0802d822 in wiced_tcp_create_socket (socket=0x0, interface=<optimized out>) at WICED/network/LwIP/WICED/tcpip.c:295
#5  0x080401ac in socket_create (family=<optimized out>, type=<optimized out>, protocol=<optimized out>, port=<optimized out>, nif=0) at src/photon/socket_hal.cpp:960
#6  0x0804597c in Spark_Connect () at src/system_cloud_internal.cpp:856
#7  0x08044f14 in establish_cloud_connection () at src/system_task.cpp:215
#8  0x08045174 in manage_cloud_connection (force_events=<optimized out>) at src/system_task.cpp:302
#9  0x080451ae in Spark_Idle_Events (force_events=<optimized out>) at src/system_task.cpp:335
#10 0x08044000 in ActiveObjectBase::run (this=0x200096b8 <SystemThread>) at src/active_object.cpp:49
#11 0x08044020 in ActiveObjectBase::run_active_object (object=<optimized out>) at src/active_object.cpp:92
#12 0x08043968 in std::invoke_thread (ptr=0x2000c498) at src/system_threading.cpp:85
#13 0x00000000 in ?? ()
(gdb) fin 
Run till exit from #0  xQueueGenericReceive (xQueue=0x856f78f8, pvBuffer=pvBuffer@entry=0x0, xTicksToWait=xTicksToWait@entry=1, xJustPeeking=xJustPeeking@entry=0) at WICED/RTOS/FreeRTOS/ver7.5.2/Source/queue.c:1165

Any ideas on what could possibly cause this?

wiced is the Broadcom base software layer, including the network. It looks like a deadlock from the symptoms you are describing. Could you please post an issue on GitHub with those details so this issue can be investigated and followed up?

Are you using I2C? There are known issues in 0.4.7 that were resolved in 0.4.9 relating to I2C and lockups.

No, I’m only using SPI and some digital pins. After upgrading to 0.4.9 things are working fine, only things that caused a problem on 0.4.9 were calls to ‘Serial.print’ methods during interrupts, which called some ‘String’ class methods which lead to malloc calls which caused hanging due to some thread locking mechanisms (I don’t remember the exact trace right now tough).

I hope I don’t need to tell you that you shouldn’t be doing memory allocation on an interrupt. :smile:

The interrupt may happen at the point the previously executing thread acquired the memory allocation lock, and then it will attempt to acquire the same lock, blocking indefinitely, since the lock can only be freed by the original thread, which only runs when the interrupt returns.

2 Likes