esp32s2关于同时使用wifi和lvgl出错重启是什么原因

20岁开始秃头
Posts: 4
Joined: Sat Mar 05, 2022 2:17 am

esp32s2关于同时使用wifi和lvgl出错重启是什么原因

Postby 20岁开始秃头 » Sat Mar 05, 2022 3:42 am

我尝试在用lvgl做一组wifi扫描连接界面,但加入wifi扫描后,esp32s2就不断重启,使用的版本是release4.4,vscode c开发。具体我也去查过,也有人遇到这个问题,他用的是arduino,说是lvgl调用的系统计时和freertos任务调用wifi时起了冲突,但说的很笼统,不太熟悉freertos,头秃搞不明白,有什么办法能解决吗。代码和出错信息如下:



  1. /*****界面任务*****/
  2. static void gui_task(void *arg)
  3. {
  4.     xGuiSemaphore = xSemaphoreCreateMutex();
  5.     lv_init();          //lvgl内核初始化
  6.     lvgl_driver_init(); //lvgl显示接口初始化
  7.  
  8.     static lv_disp_draw_buf_t draw_buf;
  9.     lv_color_t *buf1 = heap_caps_malloc(LV_HOR_RES_MAX * LV_VER_RES_MAX * sizeof(lv_color_t), MALLOC_CAP_DMA);
  10.     lv_color_t *buf2 = heap_caps_malloc(LV_HOR_RES_MAX * LV_VER_RES_MAX * sizeof(lv_color_t), MALLOC_CAP_DMA);
  11.     lv_disp_draw_buf_init(&draw_buf, buf1, buf2, LV_HOR_RES_MAX * LV_VER_RES_MAX); /*Initialize the display buffer*/
  12.  
  13.     static lv_disp_drv_t disp_drv;         /*A variable to hold the drivers. Must be static or global.*/
  14.     lv_disp_drv_init(&disp_drv);           /*Basic initialization*/
  15.     disp_drv.draw_buf = &draw_buf;         /*Set an initialized buffer*/
  16.     disp_drv.flush_cb = disp_driver_flush; /*Set a flush callback to draw to the display*/
  17.     disp_drv.hor_res = 240;                /*Set the horizontal resolution in pixels*/
  18.     disp_drv.ver_res = 240;                /*Set the vertical resolution in pixels*/
  19.     lv_disp_drv_register(&disp_drv);       /*Register the driver and save the created display objects*/
  20.     esp_register_freertos_tick_hook(lv_tick_task);
  21.  
  22.     lvgl_test();
  23.     uint32_t count = 0;
  24.     while (1)
  25.     {
  26.         /* Delay 1 tick (assumes FreeRTOS tick is 10ms */
  27.         vTaskDelay(pdMS_TO_TICKS(10));
  28.         count++;
  29.         if(count == 300){
  30.             testExit();
  31.             lvgl1_test();
  32.         }else if(count == 600){
  33.             count = 0;
  34.             testExit();
  35.             lvgl_test();
  36.         }
  37.         /* Try to take the semaphore, call lvgl related function on success */
  38.         if (pdTRUE == xSemaphoreTake(xGuiSemaphore, portMAX_DELAY))
  39.         {
  40.             lv_timer_handler();
  41.             xSemaphoreGive(xGuiSemaphore);
  42.         }
  43.     }
  44.  
  45. /******WIFI任务********/
  46. void wifi_task(void *arg)
  47. {
  48.     ESP_LOGI(TAG, "APP Start......");
  49.     esp_err_t ret = nvs_flash_init();
  50.     if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
  51.         ESP_ERROR_CHECK(nvs_flash_erase());
  52.         ret = nvs_flash_init();
  53.     }
  54.     ESP_ERROR_CHECK( ret );
  55.  
  56.     while(1){
  57.         wifi_scan();
  58.         vTaskDelay(20000 / portTICK_RATE_MS);
  59.     }
  60.     vTaskDelete(NULL);
  61.  
  62. }
  63.  
  64. /*****主函数*****/
  65. void app_main(void)
  66. {
  67.     xTaskCreatePinnedToCore(gui_task, "gui task", 1024 * 3, NULL, 0, NULL, 0);
  68.     xTaskCreatePinnedToCore(wifi_task, "wifi_task", 1024 * 4, NULL, 2, NULL, 0);
  69.     while(1){
  70.         vTaskDelay(1);
  71.     }
  72. }




错误信息:
  1. Guru Meditation Error: Core  0 panic'ed (StoreProhibited). Exception was unhandled.
  2.  
  3. Core  0 register dump:
  4. PC      : 0x40112304  PS      : 0x00060530  A0      : 0x80096c1c  A1      : 0x3ffd4430  
  5. 0x40112304: lv_color_fill at /home/esp32/esp-idf/esp32_lvgl/blink/build/../components/lvgl/src/misc/lv_color.c:50
  6.  
  7. A2      : 0x00000000  A3      : 0x00000000  A4      : 0x000000f0  A5      : 0x0000000f  
  8. A6      : 0x00000000  A7      : 0x00000000  A8      : 0x00000000  A9      : 0x00000010  
  9. A10     : 0x00000000  A11     : 0x3ffcbbc0  A12     : 0x3ffcb040  A13     : 0x00000000  
  10. A14     : 0x00000000  A15     : 0x00000000  SAR     : 0x0000001a  EXCCAUSE: 0x0000001d  
  11. EXCVADDR: 0x00000000  LBEG    : 0x3ffcb040  LEND    : 0x00000000  LCOUNT  : 0x4002477d  
  12. 0x4002477d: _xt_user_exc at /home/esp32/esp-idf/components/freertos/port/xtensa/xtensa_vectors.S:633
  13.  
  14.  
  15.  
  16. Backtrace:0x40112301:0x3ffd44300x40096c19:0x3ffd4450 0x400980d5:0x3ffd44f0 0x40097f62:0x3ffd4540 0x4009a885:0x3ffd4570 0x4009b4da:0x3ffd4610 0x40112003:0x3ffd4630 0x4008839f:0x3ffd4650 0x40088dfe:0x3ffd4700 0x4011176d:0x3ffd4730 0x40087cba:0x3ffd4750 0x40087d99:0x3ffd4770 0x4008e00e:0x3ffd47b0 0x4008e0d1:0x3ffd47f0 0x4008e282:0x3ffd4810 0x4008e404:0x3ffd4880 0x4008e4fd:0x3ffd48c0 0x4008e69c:0x3ffd48e0 0x40093c15:0x3ffd4910 0x40093cc6:0x3ffd4930 0x40086bd7:0x3ffd4950 0x4002d7a1:0x3ffd4970
  17. 0x40112301: lv_color_fill at /home/esp32/esp-idf/esp32_lvgl/blink/build/../components/lvgl/src/misc/lv_color.c:49
  18.  
  19. 0x40096c19: fill_normal at /home/esp32/esp-idf/esp32_lvgl/blink/build/../components/lvgl/src/draw/sw/lv_draw_sw_blend.c:229 (discriminator 3)
  20.  
  21. 0x400980d5: lv_draw_sw_blend_basic at /home/esp32/esp-idf/esp32_lvgl/blink/build/../components/lvgl/src/draw/sw/lv_draw_sw_blend.c:159
  22.  
  23. 0x40097f62: lv_draw_sw_blend at /home/esp32/esp-idf/esp32_lvgl/blink/build/../components/lvgl/src/draw/sw/lv_draw_sw_blend.c:105
  24.  
  25. 0x4009a885: draw_bg at /home/esp32/esp-idf/esp32_lvgl/blink/build/../components/lvgl/src/draw/sw/lv_draw_sw_rect.c:132
  26.  
  27. 0x4009b4da: lv_draw_sw_rect at /home/esp32/esp-idf/esp32_lvgl/blink/build/../components/lvgl/src/draw/sw/lv_draw_sw_rect.c:75
  28.  
  29. 0x40112003: lv_draw_rect at /home/esp32/esp-idf/esp32_lvgl/blink/build/../components/lvgl/src/draw/lv_draw_rect.c:66
  30.  
  31. 0x4008839f: lv_obj_draw at /home/esp32/esp-idf/esp32_lvgl/blink/build/../components/lvgl/src/core/lv_obj.c:544
  32.  
  33. 0x40088dfe: lv_obj_event at /home/esp32/esp-idf/esp32_lvgl/blink/build/../components/lvgl/src/core/lv_obj.c:854
  34.  
  35. 0x4011176d: lv_obj_event_base at /home/esp32/esp-idf/esp32_lvgl/blink/build/../components/lvgl/src/core/lv_event.c:98
  36.  
  37. 0x40087cba: event_send_core at /home/esp32/esp-idf/esp32_lvgl/blink/build/../components/lvgl/src/core/lv_event.c:458
  38.  
  39. 0x40087d99: lv_event_send at /home/esp32/esp-idf/esp32_lvgl/blink/build/../components/lvgl/src/core/lv_event.c:75
  40.  
  41. 0x4008e00e: lv_refr_obj at /home/esp32/esp-idf/esp32_lvgl/blink/build/../components/lvgl/src/core/lv_refr.c:148
  42.  
  43. 0x4008e0d1: lv_refr_obj_and_children at /home/esp32/esp-idf/esp32_lvgl/blink/build/../components/lvgl/src/core/lv_refr.c:738
  44.  
  45. 0x4008e282: lv_refr_area_part at /home/esp32/esp-idf/esp32_lvgl/blink/build/../components/lvgl/src/core/lv_refr.c:670
  46.  
  47. 0x4008e404: lv_refr_area at /home/esp32/esp-idf/esp32_lvgl/blink/build/../components/lvgl/src/core/lv_refr.c:589 (discriminator 2)
  48.  
  49. 0x4008e4fd: lv_refr_areas at /home/esp32/esp-idf/esp32_lvgl/blink/build/../components/lvgl/src/core/lv_refr.c:529
  50.  
  51. 0x4008e69c: _lv_disp_refr_timer at /home/esp32/esp-idf/esp32_lvgl/blink/build/../components/lvgl/src/core/lv_refr.c:324
  52.  
  53. 0x40093c15: lv_timer_exec at /home/esp32/esp-idf/esp32_lvgl/blink/build/../components/lvgl/src/misc/lv_timer.c:313 (discriminator 2)
  54.  
  55. 0x40093cc6: lv_timer_handler at /home/esp32/esp-idf/esp32_lvgl/blink/build/../components/lvgl/src/misc/lv_timer.c:109
  56.  
  57. 0x40086bd7: gui_task at /home/esp32/esp-idf/esp32_lvgl/blink/build/../main/iDutMain.c:70
  58.  
  59. 0x4002d7a1: vPortTaskWrapper at /home/esp32/esp-idf/components/freertos/port/xtensa/port.c:131
  60.  
  61.  
  62.  
  63.  
  64.  
  65. ELF file SHA256: 3d57903203e8cb7e
  66.  
  67. Rebooting...
  68. ESP-ROM:esp32s2-rc4-20191025
  69. Build:Oct 25 2019
  70. rst:0x3 (RTC_SW_SYS_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
  71. Saved PC:0x40023435
  72. 0x40023435: esp_restart_noos_dig at /home/esp32/esp-idf/components/esp_system/esp_system.c:44 (discriminator 1)

ESP_morris
Posts: 290
Joined: Wed Sep 05, 2018 6:23 am

Re: esp32s2关于同时使用wifi和lvgl出错重启是什么原因

Postby ESP_morris » Tue Mar 08, 2022 3:32 am

试试把tick task放到 esp_timer 中,而不是放到 freertos tick hook中,可以参考这个example对lvgl的移植
https://github.com/espressif/esp-idf/bl ... ple_main.c

20岁开始秃头
Posts: 4
Joined: Sat Mar 05, 2022 2:17 am

Re: esp32s2关于同时使用wifi和lvgl出错重启是什么原因

Postby 20岁开始秃头 » Tue Mar 08, 2022 3:42 am

感谢,我之前想到了这个,尝试将tick_task放到esp_timer_handle中,可问题仍然未能解决,代码部分如下:
  1. static void gui_task(void *arg)
  2. {
  3.     xGuiSemaphore = xSemaphoreCreateMutex();
  4.     lv_init();          //lvgl内核初始化
  5.     lvgl_driver_init(); //lvgl显示接口初始化
  6.  
  7.     static lv_disp_draw_buf_t draw_buf;
  8.     lv_color_t *buf1 = heap_caps_malloc(LV_HOR_RES_MAX * LV_VER_RES_MAX * sizeof(lv_color_t), MALLOC_CAP_DMA);
  9.     lv_color_t *buf2 = heap_caps_malloc(LV_HOR_RES_MAX * LV_VER_RES_MAX * sizeof(lv_color_t), MALLOC_CAP_DMA);
  10.     lv_disp_draw_buf_init(&draw_buf, buf1, buf2, LV_HOR_RES_MAX * LV_VER_RES_MAX); /*Initialize the display buffer*/
  11.  
  12.     static lv_disp_drv_t disp_drv;         /*A variable to hold the drivers. Must be static or global.*/
  13.     lv_disp_drv_init(&disp_drv);           /*Basic initialization*/
  14.     disp_drv.draw_buf = &draw_buf;         /*Set an initialized buffer*/
  15.     disp_drv.flush_cb = disp_driver_flush; /*Set a flush callback to draw to the display*/
  16.     disp_drv.hor_res = 240;                /*Set the horizontal resolution in pixels*/
  17.     disp_drv.ver_res = 240;                /*Set the vertical resolution in pixels*/
  18.     lv_disp_drv_register(&disp_drv);       /*Register the driver and save the created display objects*/
  19.     // esp_register_freertos_tick_hook(lv_tick_task);
  20.      const esp_timer_create_args_t periodic_timer_args = {
  21.         .callback = &lv_tick_task,
  22.         .name = "periodic_gui"
  23.     };
  24.     esp_timer_handle_t periodic_timer;
  25.     ESP_ERROR_CHECK(esp_timer_create(&periodic_timer_args, &periodic_timer));
  26.     ESP_ERROR_CHECK(esp_timer_start_periodic(periodic_timer, LV_TICK_PERIOD_MS * 1000));
  27.     // wifi_ap_sta_test();
  28.     lvgl1_test();
  29.    
  30.     uint32_t count = 0;
  31.     while (1)
  32.     {
  33.         /* Delay 1 tick (assumes FreeRTOS tick is 10ms */
  34.         vTaskDelay(pdMS_TO_TICKS(10));
  35.         // delay();
  36.         // count++;
  37.         // if(count == 500){
  38.         //     testExit();
  39.         //     lvgl1_test();
  40.         // }else if(count == 1000){
  41.         //     count = 0;
  42.         //     testExit();
  43.         //     lvgl_test();
  44.         // }
  45.        
  46.        
  47.         // }else if(count == 1500){
  48.         //     testExit();
  49.         //     lvgl2_test();
  50.         // }else if(count == 2000){
  51.         //     count = 0;
  52.         //     testExit();
  53.         //     lvgl3_test();
  54.         // }
  55.         /* Try to take the semaphore, call lvgl related function on success */
  56.         if (pdTRUE == xSemaphoreTake(xGuiSemaphore, portMAX_DELAY))
  57.         {
  58.             lv_timer_handler();
  59.             xSemaphoreGive(xGuiSemaphore);
  60.         }
  61.     }
  62.     free(buf1);
  63.     free(buf2);
  64.     vTaskDelete(NULL);
  65. }

netmark
Posts: 12
Joined: Tue Apr 20, 2021 2:04 am

Re: esp32s2关于同时使用wifi和lvgl出错重启是什么原因

Postby netmark » Wed Mar 09, 2022 12:55 pm

你这很有可能是多线程引起的问题,操作UI部分,增加互斥看看,我也在用lvgl 不过我是S3芯片

20岁开始秃头
Posts: 4
Joined: Sat Mar 05, 2022 2:17 am

Re: esp32s2关于同时使用wifi和lvgl出错重启是什么原因

Postby 20岁开始秃头 » Tue Mar 29, 2022 1:55 am

感谢,我尝试一下,不过在之前我添加了关键变量的互斥锁,也没起效果

a2409931477
Posts: 1
Joined: Mon Apr 18, 2022 11:45 am

Re: esp32s2关于同时使用wifi和lvgl出错重启是什么原因

Postby a2409931477 » Mon Apr 18, 2022 12:23 pm

哥,你找到原因了吗

justQin
Posts: 1
Joined: Sat May 07, 2022 2:03 am

Re: esp32s2关于同时使用wifi和lvgl出错重启是什么原因

Postby justQin » Sat May 07, 2022 2:07 am

我也遇到这个问题了,我不是用的s2,反正不用wifi都正常。
然后我用的spi驱动st7789,我分析代码,感觉是死锁了,一边一直在判断是否在flushing,而这个始终无法被置位,看样子驱动部分得自己写才行了

Who is online

Users browsing this forum: No registered users and 116 guests