emWin with external SRAM error

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

  • emWin with external SRAM error

    Hi,
    I got to the point where I am forced to use emWin with the external SRAM. When I run the code with emWin in SRAM of the MCU, everything is fine. When I run the very same code with external SRAM, execution of the code ends on the first creation of the GUI widget, in the function GUI_ALLOC_UnlockH, with the HardFault handler.
    I have searched the forum posts and verified following suggested solutions
    • external SRAM is writable/readable, full range of the memory allocated to emWin is accessible
    • external SRAM supports 8, 16 and 32-bit access

    My configuration is: MCU is SAM3S4C, Keil compiler, emWin 5.16d as lib.
    I would be grateful for any suggestions.
    Best Regards
    Petr
  • Hi Petr,

    did you made sure that the memory used by emWin is located in the external SRAM?

    In your GUIConf.c you need to place 'aMemory' into a section, defined in the linker file, which is located in the external SRAM.
    Maybe like this (of course this depends on the compiler you are using):

    C Source Code

    1. #define GUI_NUMBYTES (1024 * 1024)
    2. static U32 aMemory[GUI_NUMBYTES / 4] __attribute__ ((section ("GUI_RAM"), zero_init));
    3. /*********************************************************************
    4. *
    5. * GUI_X_Config
    6. *
    7. * Purpose:
    8. * Called during the initialization process in order to set up the
    9. * available memory for the GUI.
    10. */
    11. void GUI_X_Config(void) {
    12. //
    13. // Assign memory to emWin
    14. //
    15. GUI_ALLOC_AssignMemory(aMemory, GUI_NUMBYTES);
    16. }
    Display All

    could anybody with the access to the source code please paste code of the GUI_ALLOC_UnlockH function?
    Please do not share any internal code of emWin or any other SEGGER products.

    Regards,
    Sven
  • Hi Sven,
    the memory is located in the external SRAM. It is defined similarly to your suggestion

    C Source Code

    1. #define GUI_NUMBYTES (1024 * 1024)
    2. #define GUI_BLOCKSIZE 128
    3. static U32 aMemory[GUI_NUMBYTES / 4] __attribute__((at(0x63000000UL)));
    4. void GUI_X_Config(void)
    5. {
    6. // // Assign memory to emWin //
    7. GUI_ALLOC_AssignMemory(aMemory, GUI_NUMBYTES);
    8. GUI_ALLOC_SetAvBlockSize(GUI_BLOCKSIZE);
    9. }
    Display All


    I can read/write all bytes of the array, so it is accessible without any problems. But when emWin tries to use it, it causes HardFault handler. So code of the function which is causing it might be very helpful in searching of the source of the issues. If you do not want to share it publicly, would it be possible to send it to me as PM?

    Thank you
    Petr
  • Hi kvleonhardt,
    thank you for interesting tip, but unfortunately this was not my case. I have Cortex M3, where the SRAM is located on the 0x6X000000 address, listed as normal memory. I also tested various unaligned memory accesses, and it seems to be working fine.

    C Source Code

    1. #define GUI_NUMBYTES (1024 * 1024)
    2. static U32 aMemory[GUI_NUMBYTES/4] __attribute__((at(0x63000000UL)));
    3. void GUI_X_Config(void) {
    4. U32 val,i;
    5. U32 * unal_mem = (U32*)(((U8*)aMemory)+1);
    6. for ( i = 0; i < GUI_NUMBYTES / 4; i++ )
    7. {
    8. unal_mem[i] = i*5;
    9. unal_mem[i] -= 20;
    10. }
    11. // // Assign memory to emWin //
    12. GUI_ALLOC_AssignMemory(aMemory, GUI_NUMBYTES);
    13. GUI_SetDefaultFont(GUI_FONT_6X8);
    14. }
    Display All


    I did some research about the hard fault, but is does not make any sense to me, CFSR register is 0x00008200, which is bus fault with valid address in the BFAR, but bus fault address register BFAR content points somewhere in the system addresses ( FFE69CE8 ).

    Thanks
    Entik