cancel
Showing results for 
Search instead for 
Did you mean: 

What happens when an main program finishes

wwwsinsh
Associate II

my program goto busfault handler, but I do not know the reason

3 REPLIES 3
Sarra.S
ST Employee

Hello @wwwsinsh​,

Please give us more details on your issue so you can have the most effective support!

A bus fault is a type of exception that is triggered when there is an error in memory access or a bus-related error.

for example, if you're trying to access an invalid memory location or an unaligned memory address, it can trigger this bus fault..

You need to debug and step through your code and identify the location where the bus fault occurs.

Here are some highlights on how to do so :

  1. Check the LR register content (in CPU registers) : LR register gives you details on which mode/ configuration was active when entering the exception( main stack, handler or process stack)
  2. if main stack for example, copy the @ in the main stack register and paste it in the memory view 
  3. You should read the content as follows: R0, R1,R2, R3, R12, LR, PC, xPSR.
  4. Copy the PC content and paste it in the disassembly viewer and see the instruction that cause the bus fault 

Hope that helps!

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Pavel A.
Evangelist III

This depends on the used compiler and its runtime library (Keil, IAR, GCC and so on).

The short answer: your main() function simply should not return.

>>but I do not know the reason

Because it to returns to where it was called, and drops off the edge of the known universe..

It is not expected to return.

That's why most of the examples have an infinite loop.

There's no where to send the return code too.

Code called from startup.s or equivalent. You could put an infinite loop in there too.

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