lpcware

Hardfault handler - pointer pointing to an address

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by jonotree on Mon Oct 27 10:02:49 MST 2014
I've got some strange problems..

I am using an LPC1778, and running into the hard fault handler when I run though my program in debug mode, but not if I step through it. I'm using keil uvision v4)

If the program is run, the hard fault handler gets entered during this function (I can see from the 'call stack + locals' window):

/*Moves string pointer to next occurence of token */
UINT8 bytesUntilNext(UINT8_PTR ptr, char token, UINT8_PTR bufferStart)
{
UINT8 bytesToNextWantedChar = 0;
UINT8_PTR original = ptr;
while((*ptr != token) && (bytesToNextWantedChar < 100))
{
ptr = goThruCircleBuffer(bufferStart, ptr, 1);
bytesToNextWantedChar++;
        }
  }

Due to the argument ptr, coming in pointing to the address 0x1100 0044.
As far as I understand, this is most likely causing the hard fault error because that address is in the 'reserved' sector of memory according to the device user manual (UM10470, pg 879 figure 171 'Map of Lower Memory').
so its not really allowed to use a pointer pointing to it. 

As stated before, this doesn't happen when I step through the program rather than running it. If the program is stepped through, when I reach this function, the address to which ptr points is 
0x1000 4416, the correct starting address of the buffer I want to point to, and in the local static ram section of memory instead (see previously mentioned diagram).

Can anyone advise me on any or all of the following things?
1.why there's this difference of behaviour between debug running and stepping
2. why the address to which the pointer points is being changed to this reserved address without my consent?
3. Is my interpretation of the hard fault error correct?
4. General things/ useful documentation to read - if from reading this post it seems like I'm not entirely sure what I'm talking about you are correct.

Many thanks in advanced

Outcomes