Following up on my earlier question, which I had not resolved yet, and its haunting me now.
I get these SPI transfer freezes now and then, and since I could not locate it, I radically simplified the code to a debug project: It intializes LVGL in setup(), there’ an animated widget, the main thread only calls lv_timer_handler() to drive the display update.
I send the data using the DMA transfer function. As in the last post, Periodically, it just does not return.
I noticed that this happens during WiFi connect. I tried setting SYSTEM_MODE(MANUAL); - et voila - it does not hang. When going back to AUTOMATIC, it usually hangs. If I have a tight animation loop (and thus basically constantly transfer data over SPI) at the time the WiFi connects, it is almost guaranteed to hang.
I can reproduce with the following snippet:
/*
* Project myProject
* Author: Your Name
* Date:
* For comprehensive documentation and examples, please visit:
* https://docs.particle.io/firmware/best-practices/firmware-template/
*/
// Include Particle Device OS APIs
#include "Particle.h"
// Let Device OS manage the connection to the Particle Cloud
SYSTEM_MODE(AUTOMATIC);
// Run the application and system concurrently in separate threads
SYSTEM_THREAD(ENABLED);
// Show system, cloud connectivity, and application logs over USB
// View logs with CLI using 'particle serial monitor --follow'
SerialLogHandler logHandler(LOG_LEVEL_INFO);
char buffer[15360];
void setup()
{
waitFor(Serial.isConnected, 5000);
SPI1.begin();
}
int loop_count = 0;
system_tick_t time_next_log = 0;
void loop()
{
loop_count++;
auto now = millis();
if (now > time_next_log)
{
Log.info("Main Heartbeat %d loops per second",
loop_count);
time_next_log = ((now / 1000) + 1) * 1000;
loop_count = 0;
}
SPI1.beginTransaction(SPISettings(40 * MHZ, MSBFIRST, SPI_MODE0));
SPI1.transfer(buffer, nullptr, sizeof(buffer), nullptr);
SPI1.endTransaction();
}
which produces the following logs - as you can see, the main loop just gets stuck.
0000004232 [app] INFO: Main Heartbeat 1 loops per second
0000005001 [app] INFO: Main Heartbeat 150 loops per second
0000006003 [app] INFO: Main Heartbeat 196 loops per second
0000006011 [ncp.rltk.client] INFO: Try to connect to ssid: schneipfer (70:3a:cb:6b:b1:8d)
0000007004 [app] INFO: Main Heartbeat 196 loops per second
0000008001 [app] INFO: Main Heartbeat 195 loops per second
0000009002 [app] INFO: Main Heartbeat 196 loops per second
0000010466 [app] INFO: Main Heartbeat 152 loops per second
0000010598 [ncp.rltk.client] WARN: Disconnect linkError=00000100 reason=001e: assoc stage, assoc reject (assoc rsp status > 0)
0000011001 [app] INFO: Main Heartbeat 102 loops per second
0000011101 [ncp.rltk.client] INFO: Try to connect to ssid: schneipfer (70:3a:cb:6b:b1:8d)
0000012001 [app] INFO: Main Heartbeat 194 loops per second
0000013004 [app] INFO: Main Heartbeat 196 loops per second
0000014002 [app] INFO: Main Heartbeat 195 loops per second
0000015001 [app] INFO: Main Heartbeat 195 loops per second
0000015093 [net.ifapi] INFO: Netif wl3 link UP, profile=schneipfer
0000015103 [system.nm] INFO: State changed: IFACE_UP -> IFACE_LINK_UP
0000015140 [hal] INFO: DNS server list changed
0000015143 [system.nm] INFO: State changed: IFACE_LINK_UP -> IP_CONFIGURED
0000015168 [system] INFO: Cloud: connecting
0000015189 [system] INFO: Read Server Address = type:1,domain:$id.udp.particle.io
0000015223 [system] INFO: Loaded cloud server address and port from session data
0000015258 [system] INFO: Cloud socket=0, connecting to 3.222.143.118#5684 using if 4
0000015297 [system] INFO: Bound cloud socket to lwip if 4 ("wl3")
0000015323 [system] INFO: Cloud socket connected
0000015344 [system] INFO: Starting handshake: presense_announce=0
0000015374 [comm.protocol.handshake] INFO: Establish secure connection
0000015409 [comm.dtls] INFO: session has 0 uses
0000015437 [comm.dtls] INFO: (CMPL,RENEG,NO_SESS,ERR) restoreStatus=0
0000015465 [comm.dtls] INFO: out_ctr 0,1,0,0,0,0,1,61, next_coap_id=133
0000015494 [comm.dtls] INFO: restored session from persisted session data. next_msg_id=307
0000015528 [comm.dtls] INFO: session cmd (CLS,DIS,MOV,LOD,SAV): 2
0000016636 [comm.dtls] INFO: session cmd (CLS,DIS,MOV,LOD,SAV): 4
0000016668 [comm.dtls] INFO: session cmd (CLS,DIS,MOV,LOD,SAV): 3
0000016695 [comm.protocol.handshake] INFO: Sending HELLO message
0000036207 [net.ifapi] INFO: Netif wl3 link DOWN, profile=NONE
0000036209 [system.nm] INFO: State changed: IP_CONFIGURED -> IFACE_LINK_UP
When setting SYSTEM_MODE(MANUAL); it goes on forever.
I suspect that some DeviceOS internals conflict with a open SPI transaction? I’m using 6.3.3 on a Photon 2.
Thanks,
MikeS