Huangshanpai ported BLE/HID routine with added LVGL UI; encountered invalid memory access crash causing hardware fault after successfully printing characters on PC several times

sp: 0x20021dd0
psr: 0x61000000
r00: 0x00000000
r01: 0x000043f0
r02: 0x20027a74
r03: 0x00000000
r04: 0x00000004
r05: 0x20021b98
r06: 0xdeadbeef
r07: 0xdeadbeef
r08: 0xdeadbeef
r09: 0xdeadbeef
r10: 0xdeadbeef
r11: 0xdeadbeef
r12: 0x00000000
lr: 0x12071961
pc: 0x20006a00
hard fault on thread: tidle

=====================

PSP: 0x20021d3c, MSP: 0x20001fc4

Thread Info

thread pri status sp top stack size max used left tick error


KE_EVT3 10 suspend 0x20030010 0x20030084 0x00000400 35% 0x00000005 000

KE_EVT0 25 suspend 0x2002fbf8 0x2002fc6c 0x00000400 11% 0x00000014 000
KE_EVT2 12 suspend 0x2002f7e0 0x2002f854 0x00001000 23% 0x00000006 000
tpread 10 suspend 0x2001d410 0x2001d494 0x00000400 36% 0x00000003 000
lcd_task 12 suspend 0x2001cfb8 0x2001d094 0x00000800 30% 0x00000009 000
ble_thre 12 suspend 0x20027808 0x2002789c 0x00000c00 26% 0x00000008 000
lvgl_thr 11 suspend 0x20026b70 0x20026be8 0x00001000 47% 0x00000005 000
tshell 20 suspend 0x20025a40 0x20025b34 0x00001000 07% 0x0000000a 000
tidle 31 ready 0x20021d40 0x20021d94 0x00000200 21% 0x00000020 000
timer 4 suspend 0x2001d818 0x2001d894 0x00000400 22% 0x00000009 000
main 10 suspend 0x20023fa8 0x200240b0 0x00000800 33% 0x00000003 000

Mailbox Info

mailbox entry size suspend thread


app 0000 0008 1:ble_thre

MessageQueue Info

msgqueue entry suspend thread


drv_lcd 0000 1:lcd_task�

Mutex Info

mutex owner hold suspend thread


tplck (NULL) 0000 0

ble_flas (NULL) 0000 0
rtc (NULL) 0000 0
ulog loc (NULL) 0000 0
fslock (NULL) 0000 0
i2c_bus_ (NULL) 0000 0
i2c_bus_ (NULL) 0000 0
i2c_bus_ (NULL) 0000 0

Semaphore Info

semaphore v suspend thread


KE 000 1:KE_EVT3

KE 000 1:KE_EVT0
ke_mem_e 001 0
ke_mem_e 001 0
ke_mem_e 001 0
ke_mem_e 001 0
KE 000 1:KE_EVT2
lv_data 001 0
tp_ctrl 001 0
lv_lcd 001 0
sifli 000 0
lcd_msg 000 0
lcd_draw 000 0
drv_lcd 001 0
shrx 000 0
epic 001 0
ft6146 000 1:tpread
aes_drv 001 0
drv_eDma 001 0
gpadc 001 0
i2c4 000 0
i2c2 000 0
i2c1 000 0
heap 001 0
flash2 001 0

Memory Info

total memory: 378188 used memory : 47440 maximum allocated memory: 54812

MemoryHeap Info

memheap pool size max used size available size


mem manage fault:
SCB_CFSR_MFSR:0x82 DACCVIOL SCB->MMAR:DEADBEEF

main.c (27.2 KB)

触控事件处理:

events_init.c (3.9 KB)

It’s not immediately obvious just by looking, but checking the log shows that the data access address has become invalid. You can use your preferred debugging tool to trace how it reaches this point of failure.

One thing to note when using LVGL is that none of its APIs are thread-safe; they do not support multi-threaded calls.

Thread closed: There is a bug in the hid routine; it should be changed to KEY_PRESS_MAX, otherwise it will access invalid memory. The test routine alone won’t have issues, likely because it uses less memory. After adding the UI, out-of-bounds memory access caused errors.

image