cancel
Showing results for 
Search instead for 
Did you mean: 

stemWin GUI_BMP_DrawEx Hardfaults

oe2
Associate III
Posted on December 15, 2015 at 20:15

Hi everyone,

I'm trying to display an image from SD card on a display 800x480px. My image have the same size.

I can read and write files from the SD card, so that part is no problem. I can also use stemWin to display strings and windows cursor etc, so there are nothing wrong with the display driver either.

But when I call GUI_BMP_DrawEx(_GetDataSD, &imageFile, 0, 0); I get an hardfault.

I open my file like this:

  if (f_open(&imageFile, ''0:image.bmp'' , FA_READ) == FR_OK)

    GUI_BMP_DrawEx(_GetDataSD, &imageFile, 0, 0);

  f_close(&imageFile);

I have a global buffer unsigned char _acBuffer[512]; declard

My _GetData looks like this:

int _GetDataSD(void * p, const u8 ** ppData, unsigned NumBytesReq, u32 Off) {

  FIL * phFile;

  UINT NumBytesRead;

  phFile = (FIL *)p;

  // Check buffer size

  if (NumBytesReq > sizeof(_acBuffer)) {

    NumBytesReq = sizeof(_acBuffer);

  }

  // Set file pointer to the required position

  f_lseek(phFile, Off);

  // Read data into buffer

  f_read(phFile, _acBuffer, NumBytesReq, (UINT *)&NumBytesRead);

  // Set data pointer to the beginning of the buffer

  *ppData = _acBuffer;

  // Return number of available bytes

  return NumBytesRead;

} Have anyone experience using GUI_BMP_DrawEx, that may have an input of what I'm doing wrong?

#stemwin-gui_bmp_drawex-hardfault
3 REPLIES 3
Posted on December 15, 2015 at 22:12

Doesn't it pass in a NULL if it just wants you to change the file pointer?

I'm pretty that's to allow for optimizations where it doesn't have to keep having to fseek() for every transaction, which is very expensive.

Failing that instrument the function so you can see what's going on, and use a Hard Fault Handler to pinpoint what code is faulting, and what address access it is objecting too.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
oe2
Associate III
Posted on December 16, 2015 at 11:23

Thanks for the tip clive.

But I don't know what's going on inside stemWin. Here are my findings so far.

If I put a breakpoint in my _GetDataSD function, it will hit that the first time.

stemWin request a red of 54byte, with offset 0. I can se that my buffer _acBuffer contains the first 54 byte of my file. When I exit my GetData function I can single step 2 steps, then I hit a hard fault exception. If I look in the disassembler it looks like stemWin calls a function called GUI_BMP__Init when it hits the hard fault.

oe2
Associate III
Posted on December 16, 2015 at 20:33

I found out that the problem for the hard fault was that I by mistake comment out the GUI_init() for stemWin.

Now it working great!