Getting Hardfault in getdata function for xbf fonts

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Getting Hardfault in getdata function for xbf fonts

    Hi,
    I have created a xbf file through font converter with extended type font.
    I placed a xbf file into a SDcard.

    code snippet for creating xbf file:

    GUI_FONT XBFFont;
    GUI_XBF_DATA XBF_Data;

    int _cbGetData(U32 Off, U16 NumBytes,void * pVoid, void * pBuffer)
    {
    FS_FILE * handle;
    DWORD NumBytesRead;
    char pData[100];
    //*pData1;
    //buff=(char*)pBuffer;
    // pBuffer = (U8 *)pBuffer;
    //pBuffer=pData;

    handle = (FS_FILE *)pVoid;
    if (FS_FSeek(handle, Off, FS_SEEK_SET) == 0xFFFFFFFF) {
    return 0;
    }



    NumBytesRead = FS_Read(handle, pData, NumBytes); //when this statement is executes the system goes to Hardfault
    pBuffer=(void *)pData;
    if( !NumBytesRead )
    return 1;
    if (NumBytesRead != NumBytes) {
    return 1; // Error
    }
    return 0; // Ok
    //return NumBytesRead;

    }
    main()
    {
    FS_FILE *hFile1,


    hFile1 = FS_FOpen("mmc:0:\\\\Arial16.xbf", "rb");
    GUI_XBF_CreateFont(&XBFFont, /* Pointer to GUI_FONT structure in RAM */
    &XBF_Data, /* Pointer to GUI_XBF_DATA structure in RAM */
    GUI_XBF_TYPE_PROP_EXT, /* Font type to be created */
    // GUI_XBF_TYPE_PROP_AA4_EXT,
    _cbGetData, /* Pointer to callback function */
    &hFile1);
    }

    How to read a data from file to void *pBuffer in getdata callback function.
    The system was crashing as soon it hits to execute the FS_read (Handle,pData,Numbytes);


    Regards,
    venkat
  • Hi,
    The getdata function for xbf fonts its different
    int GUI_XBF_GET_DATA_FUNC(U32 Off, U16 NumBytes,
    void * pVoid, void * pBuffer);

    So, from your last reply
    "Getting data with the ...Ex() functions" in the chapter "Displaying bitmap files"
    this only for reading bitmaps and there getdata function is different.

    What i have observed in the getdata function ,the
    NumBytes it always recieve 18bytes. so,what i can think is that fs_open for xbf is not properly working.
    xbf file size is nearly 450KB . So,how come it gives 18 bytes for Numbytes in getdata function.






    REgards,
    Venkat
  • Hello Venkat,

    The function of the GetData()-functions is actually the same for all types. If "NumBytes" is set to 18, the function should read 18 Bytes of data from the beginning of the file + the given offset "Off". For an example GetData()-function, please have a look at the FONT_ShowXBF.c sample, which is included in your emWin shipment.

    Best regards,
    Adrian
  • Hi,
    The Getdata() for the XBF font is different
    GUI_XBF_GET_DATA_FUNC(U32 Off, U16 NumBytes,void * pVoid, void * pBuffer);

    And when i do FS_Read(handle, pData, NumBytes) Its getting into Hard Fault.


    code snippet for the getdata()
    is
    int _cbGetData(U32 Off, U16 NumBytes,void * pVoid, void * pBuffer)
    {
    FS_FILE * handle;
    DWORD NumBytesRead;
    char pData[100];
    //*pData1;
    //buff=(char*)pBuffer;
    // pBuffer = (U8 *)pBuffer;
    //pBuffer=pData;
    handle = (FS_FILE *)pVoid;
    if (FS_FSeek(handle, Off, FS_SEEK_SET) == -1)
    {
    return 0;
    }
    NumBytesRead = FS_Read(handle, pBuffer, NumBytes); //Executing this statement system goes into Hardfault
    if( !NumBytesRead )
    return 1;
    if (NumBytesRead != NumBytes) {
    return 1; // Error
    }
    return 0; // Ok
    }


    Regards,
    Venkat