Jump to content

crash initializing µGFX (UC1610 driver)


MAX23

Recommended Posts

I had trouble initializing µGFX on my PIC32.

 

issue:

The function gdisp_lld_init(GDisplay *g)  in gdisp_lld_UC1610.c allocates memory, but it is used uninitialized.

On the first call of gdisp_lld_flush(GDisplay* g) during init my device crashed, because y1 = PRIV(g)->y1; contained some invalid data (a high negative value).

Since the ram-pointer is calculated using y1, a invalid pointer is calculated. My solution is to memset the allocated ram-area for the driver before using it. This solves the crash My understanding of the driver and µGFX is not good enough, to be certain this is really a bug, or if I have some other issue. It may be worth looking into.

My setup:

- Device: PIC32MX470, XC32 v1.44 compiler, MPLABX, bare metal

Link to comment
Share on other sites

Hi,

the related memory isn't in the gDisplay-Structure, but the memory allocated by the driver. This memory is allocated in "gdisp_lld_init(GDisplay *g)":
    // The private area is the display surface + flush window structure.
    g->priv = gfxAlloc(sizeof(UC1610_Window) + GDISP_SCREEN_WIDTH * GDISP_SCREEN_HEIGHT / UC1610_PAGE_HEIGHT);

After that line, the first 4 Bytes of the memory pointed to by g->priv read as 0xA0001404 on my target.
This area seems to be used to store some coordinates. As far as I can see, the y-coordinates stored here are never written before flushing the display the first time.  And this leads to an invalid pointer calculated in gdisp_lld_flush():

        x1 = PRIV(g)->x1; 
        y1 = PRIV(g)->y1;   // reads as "0xA000" which is far outside of the display area

....

        // write each page segment from RAM(g) to display RAM
        for (c = RAM(g) + xyaddr(x1, y1) ; y1 <= y2 ; c += GDISP_SCREEN_WIDTH, y1 += UC1610_PAGE_HEIGHT) {
            write_data(g, c, cx);   //exception is thrown in this function because "c" is invalid
        }

Clearing the memory in g->priv solves the problem for me. Aside from this problem, the display is working now :-)

Link to comment
Share on other sites

  • 4 weeks later...

Hi,

i'm not sure but as i understand, the problem comes at the driver side when GFX_OS_HEAP_SIZE == 0 then gfxAlloc() return malloc() and PRIV(g) contained data are not initialized to 0 before the first flush. 

Conversely when GFX_OS_HEAP_SIZE is defined, the heap where gfxAlloc() allocates PRIV(g) is  declared in gos_x_heap.c as static char  which appears in .bss ram segment, so data are initialized to 0 and gfxInit does not crash.

Maybe it is necessary to force PRIV(g) data initialisation, just after memory allocation :

g->priv = gfxAlloc(sizeof(UC1610_Window) + GDISP_SCREEN_WIDTH * GDISP_SCREEN_HEIGHT / UC1610_PAGE_HEIGHT);
PRIV(g)->x1 = GDISP_SCREEN_WIDTH;
PRIV(g)->y1 = GDISP_SCREEN_HEIGHT;
PRIV(g)->x2 = -1;
PRIV(g)->y2 = -1;

Link to comment
Share on other sites

  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...