小明分享|LVGL调试日志
LVGL仿真調(diào)試日志-內(nèi)存溢出
錯(cuò)誤日志:
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())從打印信息可以看出某個(gè)地方一直在分配內(nèi)存,導(dǎo)致LVGL仿真時(shí)崩潰,自動(dòng)停止。
(PS:當(dāng)初上板時(shí),由于LVGL打印錯(cuò)誤信息使用的是封裝好的打印函數(shù),并沒(méi)有重定位輸出串口,導(dǎo)致沒(méi)有打印出對(duì)應(yīng)的錯(cuò)誤信息,后來(lái)使用Visaul Studio仿真時(shí),才發(fā)現(xiàn)是內(nèi)存溢出。)
這時(shí)候我們只要找到哪個(gè)地方一直在不斷偷偷的分配內(nèi)存就行了,需要注意的是:LVGL是整體預(yù)先分配了個(gè)獨(dú)立內(nèi)存空間,如果你使用的是帶操作系統(tǒng)的程序,是不能使用操作系統(tǒng)自帶的內(nèi)存檢測(cè)函數(shù)去找到內(nèi)存溢出的地方。
(PS:開(kāi)始檢測(cè)軟件運(yùn)行使用的是FreeRTOS,自帶了對(duì)應(yīng)的內(nèi)存查詢/函數(shù),但結(jié)果是堆棧變化一直保持靜止?fàn)顟B(tài)。)
后經(jīng)查詢,最終在lv_mem.h中找到了LVGL官方定義的內(nèi)存空間查詢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;/*** 定義一個(gè)lv_mem_monitor_t結(jié)構(gòu)體變量,再使用lv_mem_monitor()調(diào)用,最終內(nèi)存使用情況將會(huì)記錄在mem_monitor變量當(dāng)中。*/ lv_mem_monitor_t mem_monitor; lv_mem_monitor(mem_monitor);其中的total_size為堆總空間,free_size為堆剩余空間,兩者相減就是當(dāng)前堆-也就是用戶分配使用空間的情況。
通過(guò)以上API最終定位到問(wèn)題所在:聲明為全局的lv_style_t變量,在函數(shù)中循環(huán)調(diào)用lv_style_init()時(shí),會(huì)導(dǎo)致在堆中不斷的新建空間,最終導(dǎo)致lvgl內(nèi)存空間溢出。
總結(jié):在調(diào)試UI時(shí),建議使用LVGL官方提供的Visual Studio進(jìn)行仿真,并加入內(nèi)存空間檢測(cè),防止實(shí)物在長(zhǎng)時(shí)間運(yùn)行后導(dǎo)致內(nèi)存溢出,進(jìn)而導(dǎo)致顯示異常,最終檢測(cè)無(wú)誤后在上板運(yùn)行。
總結(jié)
以上是生活随笔為你收集整理的小明分享|LVGL调试日志的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: esp32 tool指令参数及说明
- 下一篇: 在线GUI编译分享|8ms模拟器的使用