You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The call to esp_netif_transmit_wrap transitively just calls esp_wifi_internal_tx. I believe we don't have access to that code.
Note the comment on top of the low_level_output function:
* @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to
* strange results. You might consider waiting for space in the DMA queue
* to become available since the stack doesn't retry to send a packet
* dropped because of memory failure (except for the TCP timers).
*/
I added debug-prints, and the amount of data is always 303 bytes. Given that the OOM message states that there is at least 12K free, it looks like the ERR_MEM isn't for "normal" memory, but for the DMA queue.
It looks like running a scan makes the WiFi driver think that the driver isn't started. It's probably safe to continue to the esp_wifi_stop, although it's not clear if we could run into a race condition where the scan stops, reactivates the wifi and the esp_wifi_stop is then failing.
Example
I didn't manage to have both errors at the same time in my example.
Run this code without Jaguar active (as it will keep the network active).
import ble
import monitor
import net
import net.wifi
import net.udp
import expect show *
import .test
main:
run-test: test
scan:
channels := ByteArray 14: it + 1
ap-list := wifi.scan channels --period-per-channel-ms=120
ssids := ap-list.map: | ap/wifi.AccessPoint | ap.ssid
print ssids
spawn-udp:
spawn::
// Now try the same thing while the network is open
// and broadcasting UDP packets.
network := net.open
payload := "scan-test".to-byte-array
broadcast-address := net.IpAddress.parse "255.255.255.255"
test-port := 54541
test-address := net.SocketAddress broadcast-address test-port
datagram ::= udp.Datagram payload test-address
socket := network.udp-open
try:
socket.broadcast = true
start := Time.now
while start.to-now < (Duration --s=100):
socket.send datagram
sleep --ms=200
finally:
print_ "closing down"
socket.close
network.close
spawn-network-close:
spawn::
network := net.open
sleep --ms=8_000
network.close
test:
// Try to do a scan without any distractions.
scan
spawn-udp // <================ OOM error.
// spawn-network-close // <================= native crash.
adapter := ble.Adapter
peripheral := adapter.peripheral
advertisement := ble.Advertisement
--name="scan-test"
scan-response := ble.Advertisement
--manufacturer-specific="testing"
peripheral.start-advertise
advertisement
--scan-response=scan-response
--interval=(Duration --ms=160)
--connection-mode=ble.BLE-CONNECT-MODE-UNDIRECTIONAL
sleep --ms=200 // Give the spawned process time to start broadcasting.
start := Time.now
while start.to-now < (Duration --s=50):
scan
peripheral.close
adapter.close
The text was updated successfully, but these errors were encountered:
The Provision example currently crashes (with pretty high probability):
https://github.com/toitware/toit-provision/blob/53b6c211e3ea34de6ca090c3533e95cf164a3cc6/examples/ble-provision.toit
Use https://play.google.com/store/apps/details?id=com.espressif.provble on Android to test with that example.
I haven't yet been able to build a minimal example, but there seem to be two reasons for the crash:
esp_wifi_disconnect
fails, but is guarded withFATAL_IF_NOT_ESP_OK
.OOM
This happens only if the BLE stack is active.
Jaguar runs into an OOM during
udp-send
(primitive 3:4).I have traced it down to
low_level_output
returning an ERR_MEM: https://github.com/toitware/esp-idf/blob/262239be8bef8d90f2430d13533d789cd3f14a3b/components/esp_netif/lwip/netif/wlanif.c#L109The call to esp_netif_transmit_wrap transitively just calls
esp_wifi_internal_tx
. I believe we don't have access to that code.Note the comment on top of the
low_level_output
function:I added debug-prints, and the amount of data is always 303 bytes. Given that the OOM message states that there is at least 12K free, it looks like the ERR_MEM isn't for "normal" memory, but for the DMA queue.
Crash
The crash is in the destructor of the WifiEvents:
toit/src/resources/wifi_esp32.cc
Line 169 in ad90af0
The error code is 0x3002
ESP_ERR_WIFI_NOT_STARTED
It looks like running a
scan
makes the WiFi driver think that the driver isn't started. It's probably safe to continue to theesp_wifi_stop
, although it's not clear if we could run into a race condition where the scan stops, reactivates the wifi and theesp_wifi_stop
is then failing.Example
I didn't manage to have both errors at the same time in my example.
Run this code without Jaguar active (as it will keep the network active).
The text was updated successfully, but these errors were encountered: