Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connecting to WiFi crashes the app #1

Closed
morphal opened this issue Mar 20, 2024 · 5 comments
Closed

Connecting to WiFi crashes the app #1

morphal opened this issue Mar 20, 2024 · 5 comments

Comments

@morphal
Copy link

morphal commented Mar 20, 2024

Hi!
Thanks for this demo project!
I've tried to modify the code to add some connectivity capabilities and faced the following issue. When connecting to WiFi, the application crashes. I've imported the project to platformio to get the backtrace decoded and here is the error:

Setup done
[  4399][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1

assert failed: block_locate_free heap_tlsf.c:441 (block_size(block) >= size)


Backtrace: 0x40378082:0x3fcf6f00 0x4037dce5:0x3fcf6f20 0x403845fd:0x3fcf6f40 0x40383a9a:0x3fcf7070 0x4038413d:0x3fcf7090 0x4038426c:0x3fcf70b0 0x403785a7:0x3fcf70d0 0x4037866e:0x3fcf7100 0x403782e9:0x3fcf7150 0x4003ecad:0x3fcf7170 |<-CORRUPTED

  #0  0x40378082:0x3fcf6f00 in panic_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/panic.c:408
  #1  0x4037dce5:0x3fcf6f20 in esp_system_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/esp_system.c:137
  #2  0x403845fd:0x3fcf6f40 in __assert_func at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/newlib/assert.c:85
  #3  0x40383a9a:0x3fcf7070 in block_locate_free at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/heap_tlsf.c:441
      (inlined by) tlsf_malloc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/heap_tlsf.c:849
  #4  0x4038413d:0x3fcf7090 in multi_heap_malloc_impl at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/multi_heap.c:187
  #5  0x4038426c:0x3fcf70b0 in multi_heap_malloc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/multi_heap_poisoning.c:234
      (inlined by) multi_heap_malloc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/multi_heap_poisoning.c:223
  #6  0x403785a7:0x3fcf70d0 in heap_caps_malloc_base at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/heap_caps.c:175
      (inlined by) heap_caps_malloc_base at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/heap_caps.c:120
  #7  0x4037866e:0x3fcf7100 in heap_caps_malloc_prefer at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/heap_caps.c:290
  #8  0x403782e9:0x3fcf7150 in wifi_malloc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_wifi/esp32s3/esp_adapter.c:71
  #9  0x4003ecad:0x3fcf7170 in ?? ??:0

Adding WiFi was pretty straightforward:

#include <WiFi.h>
....
const char *ssid = "SSID";     // Change this to your WiFi SSID
const char *password = "PASSWORD"; // Change this to your WiFi password
.....
void setup()
{
...
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    if (WiFi.status() == WL_CONNECT_FAILED)
    {
      // write about connection fail
    }
    delay(500);
  }
.... the original code ....
}

Can you please assist in resolving the LVGL/SquareLine studio conflicts with the WiFi?
I am attaching the project to help reproduce the issue.

odometer-platformio.zip

Thank you

@nikthefix
Copy link
Owner

@morphal

Hi there. I'll try your code later today.
Are you using ESP_Arduino Alpha 3?

nik

@morphal
Copy link
Author

morphal commented Mar 21, 2024

hi @nikthefix
correct, as per readme in the project, I use ESP32 Arduino 3.0.0-alpha3
I've got what you are thinking about and just checked the example after downgrading to esp32 2.0.14
The issue persists with the same error

@nikthefix
Copy link
Owner

@morphal
Thanks for the info. Will try to reproduce here.

nik

@morphal
Copy link
Author

morphal commented Mar 21, 2024

@nikthefix
I seem to have some progress on this. I've updated the display buffer size and added double buffering and it seems to have helped.
I'll leave a code snippet here:

  size_t buffer_size = sizeof(lv_color_t) * screenWidth * screenHeight;

  buf = (lv_color_t *)heap_caps_malloc(buffer_size, MALLOC_CAP_SPIRAM);
  if (buf == NULL) {
    while (1) {
      Serial.println("buf NULL");
      delay(500);
    }
  }

  buf1 = (lv_color_t *)heap_caps_malloc(buffer_size, MALLOC_CAP_SPIRAM);
  if (buf1 == NULL) {
    while (1) {
      Serial.println("buf NULL");
      delay(500);
    }
  }

  lv_disp_draw_buf_init(&draw_buf, buf, buf1, buffer_size);

@nikthefix
Copy link
Owner

nikthefix commented Mar 23, 2024

@morphal

I tried your code and it's working but the original problem was due to an error in my odometer demo sketch:

Line 182: size_t buffer_size = sizeof(lv_color_t) * screenWidth;

should have been...

size_t buffer_size = sizeof(lv_color_t) * screenWidth * screenHeight;

The wrongly sized buffer was corrupting the heap.
No need to double buffer if you don't want to as it should now work without.

It looks like you found the error anyway :)
I'll edit my github repo. Thanks for the heads-up.

nik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants