"Text Area" Cause Stm32 Into Hardfault

Description

it is normal when i use other obj. but when I create a ta(text area) obj, The Stm32 is died(into hardfault)

What MCU/Processor/Board and compiler are you using?

stm32f746

What do you want to achieve?

What have you tried so far?

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

#define LV_MEM_SIZE    (64U * 1024U)
#define LV_HOR_RES_MAX          (1024)
#define LV_VER_RES_MAX          (600)

void lv_test_kb_1(void)
{

    lv_obj_t * ta = lv_ta_create(lv_disp_get_scr_act(NULL), NULL); // program died here
    lv_obj_align(ta, NULL, LV_ALIGN_IN_TOP_MID, 0, 30);

    /* Default object*/
    lv_obj_t * kb1 = lv_kb_create(lv_disp_get_scr_act(NULL), NULL);
    lv_obj_align(kb1, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
    lv_kb_set_ta(kb1, ta);
}

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

Your display is 1024x600? maybe memory allocation problems. Also do you use RTOS?
Try to just run lvgl with nothing displayed or try to comment out each line everytime to see which triggers the hardfault because I see nothing wrong.

The SDL simulator is doing the same. Somehow memset_00 gets a null pointer.

My guess would then be that allocation is failing somewhere and not being error-checked appropriately. I’ll take a look.

Well I am running the widgets demo from dev-7.0 and rework-7. It happens when I click OK in the message box.

Unfortunately, I can’t see the issue in the simulator. :frowning:

Could you tell exactly in which function does it fail?

I find the problem. it is happen when function lv_area_copy run.
i simulate, i find the func(lv_area_copy) just have a function (memcpy) ,and i check, the all params is legal(src addr dst addr len),But program will died if run the function.
i attempt to use my_mem_cpy function to replace the memcpy func ,last the program is work Okay.
it is a very strange problem.

inline static void lv_area_copy(lv_area_t * dest, const lv_area_t * src)
{
//    memcpy(dest, src, sizeof(lv_area_t));
       mem_cpy((void*)dest, (void*)src, sizeof(lv_area_t));
}

void *mem_cpy(void *dest, void *src, int num)
{
    if((dest == 0) ||(src == 0))
    {
        return 0;
    }

    char *pdest;
    char *psrc;
    pdest =(char *)dest;
    psrc =(char *)src;

    while(num --)
    {
        *pdest++ = *psrc++;
    }

    return dest;
}

thx , i use other methods to make it work Okay.

Can you tell me what values the parameters had? If they’re unaligned the built-in memory functions on STM32 have often caused issues for me. In that case, this will no longer be an issue in 7.0 as we use our own memory functions now.

dst addr = 0x20033794
src addr = 0x20005FA2
len = sizeof(lv_area_t)

these are legal address int STM32F746( 0x20000000 ~ 0x20050000 - 1)

The source address is not aligned, as I suspected. That’s interesting. I’ll have to try this on my board and see if I can reproduce it. Can you get a backtrace in the debugger at this point?

@FreeChase
Please use the

```
code
```

markup for syntax highlighting. I’ve added it to your previous post.

@embeddedt I doubt that it’s an alignment issue because @FreeChase used char* to copy.

Probably it’s only ignorance (or I’m paranoid :smiley: ), but I try to avoid things like this *pdest++ = *psrc++;.
Instead I usually write:

(*pdest) = (*psrc);
pdest++;
psrc++;

So are you sure it’s okay as it is now?

1 Like

pic2
Yeah,I insert breakpoint in here.
the program is died when i run the function

ok, i just dont know how to use the signal.
i will take care of my codeing style, thx your advice.

char* is used in @FreeChase’s custom mem_cpy function. The crash only happens when the built-in memcpy function from Newlib is used (which, in my experience, frequently fails to handle unaligned addresses).

What is the value of ext on that line?

Uh, I mixed it up. Sorry for the confusion.

So, I’d think that the source area should be aligned by the compiler, as it’s a struct. However, we have already seen similar issues with -Os optimization. In this case, the compiler might pack the structs “as close as possible” resulting in unaligned structs. Do you use -Os optimization?

I use either -Os or -Og in my projects, depending on whether I’m trying to debug something or not. I’ve never seen GCC choose to pack structs based on optimization before, though. That seems like it would break a lot of code.

I’m suspicious that whatever heap is in use is returning an unaligned pointer when the ext structure gets allocated. This then means that everything in the structure is also going to be unaligned.

We had an issue due to size optimization earlier and as a workaround, we introduced LV_ATTRIBUTE_MEM_ALIGN config option which is added to images in some other places too.

lv_mem_alloc returns aligned memories and I’d be really surprised if normal malloc wouldn’t do the same especially on an embedded system. But we will see what’s going on when @FreeChase tells the address of ext the optimization level.

1 Like

ext just other variable, It is not related with the function