简体   繁体   中英

Hard_fault on STM32 on second write to byte array - why?

I'm missing something obvious here. I get hardfault error on STM32 (CubeIDE) when trying to put working code in function... This one works:

uint8_t framebuffer[SUBFBUF_XYMAX*SUBFBUF_XYMAX*BPP];  //24 bpp framebuffer
...
          ii = rand() % SUBFBUF_XYMAX;
          jj = rand() % SUBFBUF_XYMAX;

          DrawPoint (ii,jj,framebuffer[0], 255, 255,255);
          framebuffer[ii*BPP+jj*SUBFBUF_XYMAX*BPP] =  255;
          framebuffer[ii*BPP+jj*SUBFBUF_XYMAX*BPP+1] =  255;
          framebuffer[ii*BPP+jj*SUBFBUF_XYMAX*BPP+2] = 255;

but when I try to put this into function (in another file, shown below) I get HardFault on second write to framebuffer. There must be logical explanation on what is wrong... This one doesn't work:

  DrawPoint (ii,jj,framebuffer[0], 255, 255,255);

and then function's definition

void DrawPoint(int x0, int y0, uint8_t framebuf[], uint8_t red, uint8_t green,uint8_t blue) {
    int temp=x0*BPP+y0*SUBFBUF_XYMAX*BPP;

    framebuf[x0*BPP+y0*SUBFBUF_XYMAX*BPP] = (uint8_t)blue;
    framebuf[x0*BPP+y0*SUBFBUF_XYMAX*BPP+1] = (uint8_t)green;
    framebuf[x0*BPP+y0*SUBFBUF_XYMAX*BPP+2] = (uint8_t)red;

}

Thanks in advance, regards, R.

When calling DrawPoint() , use framebuffer or &framebuffer[0] instead of framebuffer[0] . The function expects a pointer, not a value.

Also, inside the definition of DrawPoint() you did not use temp , which would speed up your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM