HardFault_Handler error when building after increasing RAM memory size

Comments

14 comments

  • Avatar
    Jon Elliott

    The RAM segment at 0x10000000 on the LPC1788 is 0x10000 bytes in size so increasing the size in the memory map will cause the program to use memory that does not exist - hence the hard fault.

    There is a second "AHBSRAM" RAM segment on the LPC1788 at 0x20000000 that can be used - the section placement file can be modified to move program sections from the RAM segment to the AHBSRAM segment.

    To modify the section placement file:                                                                                    

    • Right click on the project in the project explorer and select Import Section Placement
    • Right click on the project in the project explorer and select Edit Section Placement
    0
    Comment actions Permalink
  • Avatar
    Anthony Meng-Lim

    Hi Jon,

    What can I increase the AHBSRAM RAM segment to in order to support the .bss section? I tried to move the .bss section to the AHBSRAM memory segment but it gave me a new error of ".bss is too large to fit in AHBSRAM memory segment", so I increased it to something like 0x20000 and my project built but it still hit that HardFault handler.

    0
    Comment actions Permalink
  • Avatar
    Jon Elliott

    The memory map specifies the actual size of the memory available on the device so it cannot be increased and the program still work.

    It sounds like you need to find out why the .bss section is so large - you can use the symbol browser window to find out how the memory is used.

    0
    Comment actions Permalink
  • Avatar
    Anthony Meng-Lim

    Hi Jon,

    Using the Symbol  Browser and increasing the AHBSRAM RAM segment (so that my project can build with no errors and I can view the .bss in the symbol browser), it says that .bss size is 76,744 which is quite big. It seems like two variables are causing the size to be excessively large but these variables are only used/called 17 times in my project so I'm not sure why it would cause the section to be so big.

    I am currently referencing another project (a very big code base) that has 16 MB of SDRAM Memory Segment, so the .bss section (this projects .bss size is 5,561,248) did not give any problems. Is there a way to get more memory for my project? How do I get SDRAM Memory Segment like the other project? Do I have to create a whole new project and choose a different setting for the LPC1788 board?

    0
    Comment actions Permalink
  • Avatar
    Jon Elliott

    The SDRAM configuration is board specific. The "Embedded Artists LPC1788 OEM" and "IAR LPC1788 KickStart" board support packages contain project templates and example projects that configure the SDRAM on these boards. What board are you using and which project template did you use to create the project?

    0
    Comment actions Permalink
  • Avatar
    Anthony Meng-Lim

    Hi Jon, 

    My board is from NXP and I believe I chose Embedded Artists "An executable for Embedded Artists LPC1788 OEM" project template. 

    Do I need to create a new project with a specific NXP project template instead? Again, I am referencing another project that communicates with the same board but I do not know which project template they chose. I tried copying the project settings the best I could but I have been having issues trying to program my board. 

    0
    Comment actions Permalink
  • Avatar
    Jon Elliott

    Hi Anthony,

    If you have used the "An executable for Embedded Artists LPC1788 OEM" project template, then the "RAM2" segment in the section placement file is the SDRAM segment. By default, .data2 and .bss2 sections are placed in this segment.

    So you can either place the large .bss symbols into the .bss2 section instead of the .bss section (see https://rowley.zendesk.com/hc/en-us/community/posts/205386963--place-code-and-data-into-different-sections for more information on how you do this) or you can modify the section placement file to place .bss into the "RAM2" segment rather than the "RAM" segment.

    The other issue is the configuration of the SDRAM. If the board/SDRAM you are using is different to the Embedded Artists LPC1788 OEM board, then you may need to modify the SDRAM configuration - the configuration of the SDRAM is done in the configure_sdram() function in the EMCInit.c module which can be found in the project's "System Files" folder.

    If you have another working project for this board, another approach could be to just take a copy of that project and then modify that as you require rather than creating a new one from scratch.

     

    0
    Comment actions Permalink
  • Avatar
    Anthony Meng-Lim

    Hi Jon, 

    Okay, I just made some progress with the information you just provided me. I moved the .bss section from the RAM segment and placed it into the RAM2 segment. After building my project, I saw a new slot of 32 MB of SDRAM under "Memory Usage" like you said which means I most likely did use "An executable for Embedded Artists LPC1788 OEM". 

    When I try to program my board with the J-Link debugger, it is not hitting the HardFault Handler right away which is good. However, it is now hitting the HardFault Handler at another point in the code. I believe this has to do with what you described in the EMCInit.c file. What exactly do I need to configure in the configure_sdram() function for it to program correctly? The other project has a BootLoader project that contains the EMCInit.c file. I compared the EMCInit.c file in both my project and the BootLoader project and there are many things different. There isn't a configure_sdram() function in the other project.

    Also, the other project only builds in CrossWorks version 2.2. I think it has to do with how the HZP file is setup in 2.2 compared to the newer version 4.1 because there were drastic changes when comparing those files. I decided to start from scratch and get it working with the latest version of CrossWorks but it has been difficult. If things don't work out in version 4.1 then I can try version 2.2 and import all my existing files from my current project but I feel like I am close to being able to program my board and displaying my GUI on the LCD screen. 

    I just want to say, I appreciate your help so far with the issues I've been having. This is my first time working with this IDE and I felt very lost initially with no one to help me but you have been extremely resourceful. 

    0
    Comment actions Permalink
  • Avatar
    Jon Elliott

    The actual function that is called to configure the external memory is EMCInit() in EMCInit.c - if you have the same function in your working project then it is possible the "Embedded Artists LPC1788 OEM" version of  EMCInit.c can be replaced with this version.

    What errors are you getting when you compile your existing project in version 4?

    0
    Comment actions Permalink
  • Avatar
    Anthony Meng-Lim

    Hi Jon,

    I was finally able to program my board with my app by switching to the old project in CrossWorks version 2.2 and importing my files. 

    I am now trying to switch from one screen to another screen on button click by using this Transition function in a switch case:  TRANSITION(Next, RedScreen(0,0), ptrStartButton); 

    This was done many times in the old working project so I am referencing that, but for some reason I am getting this error: expected ',' or ';' before '(' token

    Do you know why this is?

    0
    Comment actions Permalink
  • Avatar
    Jon Elliott

    I am now trying to switch from one screen to another screen on button click by using this Transition function in a switch case:  TRANSITION(Next, RedScreen(0,0), ptrStartButton); 

    This was done many times in the old working project so I am referencing that, but for some reason I am getting this error: expected ',' or ';' before '(' token

    There is not really enough information to go on there - how have TRANSITION and RedScreen been defined and which of the '(' characters is the error message referring to?

    0
    Comment actions Permalink
  • Avatar
    Jon Elliott

    The classname parameter in your example looks suspicious - it would expand to:

    Screen_T *Screen = new RedScreen(0,0)();
    0
    Comment actions Permalink
  • Avatar
    Anthony Meng-Lim

    Hi Jon,

    I have made good progress and I am done with creating the GUI and displaying it on the LCD board.

    The final step is to stop using the J-Link debugger to program my board and instead flash the Micro SD card which is in the LPC1788 with my app. Is there an easy way to flash the micro SD card with my app so that when the board turns on, my program is the first thing that is displayed? 

    There is a "BootLoader" for the existing project which creates these .bin files and they are used for starting up their program. Their BootLoader code will not work for my project because I only have one of many components that they use for their project. Additionally, they have a batch file that they run to create these .bin files. I tried to copy the "App.bin" and "Startup.bin" files to the micro SD card, but it does not run my program when the board is powered up. I believe it is looking for other .bin files that are not generated for some reason. 

    I was wondering if you could give me more insight on how to approach this next step and if there is an easy way in CrossWorks to export my project to a micro SD card. 

    Here is the batch file that they run: 

    : **********************************************************************
    : This batch file performs a complete rebuild of the GUI project and
    : generates the BIN files "App.bin" and "Startup.bin"
    : **********************************************************************

    echo off

    :: Set up variables

    set SoftwareDir=C:\LCDTestBuild\LCDScreenTest\Software
    set ProjectSource=Source\FirepHOxGUI
    set BuildConfig=THUMB RAM Release
    set HexFile="%SoftwareDir%\%ProjectSource%\%BuildConfig%\LCDScreenTest.hex"
    set AppBinFile=App.bin
    set StartupBinFile=Startup.bin

    :: 64-bit computer
    set CrossWorksBinDir="C:\Program Files (x86)\Rowley Associates Limited\CrossWorks for ARM 2.2\bin"

    :: 32-bit computer
    :: set CrossWorksBinDir="C:\Program Files\Rowley Associates Limited\CrossWorks for ARM 2.2\bin"

    set BuildNumber=974
    set USB=D:

    echo on

    del %StartupBinFile%
    del %AppBinFile%

    %CrossWorksBinDir%\crossbuild.exe -rebuild -config "%BuildConfig%" "%SoftwareDir%\%ProjectSource%\LCDScreenTest.hzp"

    : Generate BIN file(s) from the .Hex file.
    hexPrep.exe %BuildNumber% %HexFile% %CD%\%StartupBinFile% %CD%\%AppBinFile%

    : Copy BIN file(s) to USB drive
    copy %StartupBinFile% %USB%
    copy %AppBinFile% %USB%
    copy %ControlBinFile% %USB%

    0
    Comment actions Permalink
  • Avatar
    Anthony Meng-Lim

    Hi Jon,

    Based on my comment above, is there a straight forward way to flash the micro SD card with my CrossWorks program? Is there an export option in CrossWorks to generate files that I have to put into the Micro SD card?

    0
    Comment actions Permalink

Please sign in to leave a comment.