시아오밍 공유 | 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가 사용되며 메모리 쿼리/함수가 포함되어 있지만 결과적으로 스택 변화가 계속 정지되어 있습니다.)
// FreeRTOS API 
/*—————————————————————freertos ———————————————————————————*/
#include "freertos/FreeRTOS.h"
printf("xPortGetFreeHeapSize = %d\r
"
, xPortGetFreeHeapSize()); printf("xPortGetMinimumEverFreeHeapSize = %d\r
"
,xPortGetMinimumEverFreeHeapSize()); #include "freertos/task.h" printf("the min free stack size is %d \r
"
,(int32_t)uxTaskGetStackHighWaterMark(NULL));

후 조회, 최종 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를 사용하여 모방하고 메모리 공간 검측을 추가하여 실물이 장시간 운행한 후에 메모리가 넘치거나 디스플레이가 이상하게 되는 것을 방지하고 최종 검측이 틀리지 않은 후에 상판에서 운행하는 것을 권장합니다.

좋은 웹페이지 즐겨찾기