小明分享|LVGL调试日志
生活随笔
收集整理的這篇文章主要介紹了
小明分享|LVGL调试日志
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
LVGL仿真調試日志-內存溢出
錯誤日志:
Warn: Couldn't allocate memory (lv_mem.c #208 lv_mem_alloc()) Warn: Couldn't allocate memory (lv_mem.c #208 lv_mem_realloc()) Error: _lv_mem_buf_get (lv_mem.c #533 _lv_mem_buf_get()) Error: Out of memory,can't allocate a new buffer (increase your LV_MEM_SIZE/heap size (0x00000000) (lv_debug.c #127 lv_debug_log_error())從打印信息可以看出某個地方一直在分配內存,導致LVGL仿真時崩潰,自動停止。
(PS:當初上板時,由于LVGL打印錯誤信息使用的是封裝好的打印函數,并沒有重定位輸出串口,導致沒有打印出對應的錯誤信息,后來使用Visaul Studio仿真時,才發現是內存溢出。)
這時候我們只要找到哪個地方一直在不斷偷偷的分配內存就行了,需要注意的是:LVGL是整體預先分配了個獨立內存空間,如果你使用的是帶操作系統的程序,是不能使用操作系統自帶的內存檢測函數去找到內存溢出的地方。
(PS:開始檢測軟件運行使用的是FreeRTOS,自帶了對應的內存查詢/函數,但結果是堆棧變化一直保持靜止狀態。)
后經查詢,最終在lv_mem.h中找到了LVGL官方定義的內存空間查詢API:
/*** Give information about the work memory of dynamic allocation* @param mon_p pointer to a dm_mon_p variable,* the result of the analysis will be stored here*/ void lv_mem_monitor(lv_mem_monitor_t * mon_p);/*** Heap information structure.*/ typedef struct {uint32_t total_size; /**< Total heap size */uint32_t free_cnt;uint32_t free_size; /**< Size of available memory */uint32_t free_biggest_size;uint32_t used_cnt;uint32_t max_used; /**< Max size of Heap memory used */uint8_t used_pct; /**< Percentage used */uint8_t frag_pct; /**< Amount of fragmentation */ } lv_mem_monitor_t;/*** 定義一個lv_mem_monitor_t結構體變量,再使用lv_mem_monitor()調用,最終內存使用情況將會記錄在mem_monitor變量當中。*/ lv_mem_monitor_t mem_monitor; lv_mem_monitor(mem_monitor);其中的total_size為堆總空間,free_size為堆剩余空間,兩者相減就是當前堆-也就是用戶分配使用空間的情況。
通過以上API最終定位到問題所在:聲明為全局的lv_style_t變量,在函數中循環調用lv_style_init()時,會導致在堆中不斷的新建空間,最終導致lvgl內存空間溢出。
總結:在調試UI時,建議使用LVGL官方提供的Visual Studio進行仿真,并加入內存空間檢測,防止實物在長時間運行后導致內存溢出,進而導致顯示異常,最終檢測無誤后在上板運行。
總結
以上是生活随笔為你收集整理的小明分享|LVGL调试日志的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: esp32 tool指令参数及说明
- 下一篇: 在线GUI编译分享|8ms模拟器的使用