cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to assign an address to a pointer!

PMach.1
Senior

Hi,

I am trying to assign an address to a pointer the following way:

#define FM_P_ADDR 0x0807F800

uint64_t * addr = ((uint64_t *)FM_P_ADDR);

However, running the line will direct the execution to the Hard Fault Handler routine.

What is happening? What am I doing wrong?

Thanks in advance.

Kind regards,

Pedro Machado

4 REPLIES 4
KnarfB
Principal III

You need to give more context where that happened. The hard fault is not caused by the above lines. At least not on my Nuclo G431RB when using STM32CubeIDE. The assignment compiles into two instructions:

ldr     r3, [pc, #4]
str     r3, [r7, #4]

Nothing wrong with that.

Look SPECIFICALLY at the assembler code and processor registers at the fault, you'll be able to make a determination about what is being objected too.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
PMach.1
Senior

Hello,

I have never been introduced to ARM assembly before (only MIPS, and that was some years ago), so I don't really understand the instructions that follow:

ldr   r3, [pc, #124]

str   r3, [r7, #108] 

After some really quick search, I suppose the first instruction loads into register 3 what the program counter points, with an offset of 124 (Bytes?). The second stores in register 3 108 Bytes (?) starting from the address stored in register 7.

Obviously, it is an offset issue.

Also, any tips on material that might help me learn ARM assembly and architecture in more detail?

KnarfB
Principal III

Constants like 0x0807F800 are stored past the end of the function using it. Therefore the load is relative to PC.

Local variables are allocated withinin a so called frame on the stack. Register r7 is used as frame pointer. Therefore, the store is relative to register r7.

If the fault occurs during str, this might indicate a stack overflow.