How to throw critical exception to test the functionality of exception handlers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to throw critical exception to test the functionality of exception handlers.

1,145 Views
arpityadav
Contributor II

In our project we are using the chip MPC5648G and would like to test the functionality of the exception unit(exception handlers). We would like to throw some critical exceptions to our application and record how they can be handled. We tried the exception : divide by zero but it doesnt work, maybe it is not a critical exception for the processor unit. 

Now we are trying the dummy exception code which is written below to generate a critical exception.

 void Func1_TestException(void);

void Func1_TestException(void) {

 

const uint8_T memory[] = {1,2,3,4};

 

   if (TRUE == activateException)

   {

        pt = (void*) &memory[0] ;

                               pt[0]=2;

                               pt[2] = 34;

                               pt[23] = 34;

                              

                               {

                               char crash_instructions[4];

                               void (*fp) (void);

                              

                               /*

                               * Fill crash_instructions with arbitrary data.

                               */

                               crash_instructions[0] = 0;

                               crash_instructions[1] = 1;

                               crash_instructions[2] = 2;

                               crash_instructions[3] = 3;

                               /*

         * Branch to address of the array crash_instructions[]

                               * (which contains only data, not valid instructions)

                               */

                               fp = (void*)crash_instructions; (*fp)();

                               }

   }

}

Do anyone have any idea or sample code to throw an exception which is critical and how to test if the exception handlers are working correctly or not?

Thanks and Regards

Arpit

7 Replies

926 Views
petervlna
NXP TechSupport
NXP TechSupport

Hello,

This is described in reference manual : Table 59-7. Exceptions and Conditions

pastedImage_1.png

pastedImage_2.png

Here you can see the causing conditions for each exception.

If you want for example call IVOR6:

Call jump to memory location where is no instruction stored: like below

pastedImage_4.png

Executing opcode 0xFFFF - undefined instruction will lead you to IVOR6 exception.

If you follow the table 59-7. you can call other exceptions.

Peter

0 Kudos

926 Views
arpityadav
Contributor II

Dear Peter,

Thanks alot for the answer and sorry for the late reply. I was busy with some other project so tried your solution yesterday only and it worked.

So now I know that my exception handlers are working and next thing which I would like to check is that what will happen if my flash is corrupt.

Scenario "Suppose the data has been written to flash (writing process or erasing process) and suddenly I power off my device, the flash will be in unstable stage and on giving back the power again the exception handler is called. Do you have any idea how to do this or if you can give me some other idea how to check this type of interrupt(corrupt flash or power failure)."I am using the same hardware (chip MPC5648G) and for debugging using Lauterbach debugger. As you seem quite experienced, any suggestion from your side will be highly appreciated.

With best regards

Arpit

0 Kudos

926 Views
petervlna
NXP TechSupport
NXP TechSupport

Hi Arpit,

I was few days on vacation.

I expect that your micro is MPC5748G, not MPC5648G.

On MPC5748G there is already preprogam flash ECC single and double bit error in Utest flash.

You can test reaction on flash errors by reading this address in UTEST flash.

pastedImage_1.png

Peter

926 Views
arpityadav
Contributor II

Hi Peter,

I am now trying to simulate a scenario where at some random time I will power down my target board and expect some exception or error generation. After waiting for some seconds I will power up the board. At this power up point, I expect that some exception handler should be called (machine check handler or any other).

I am using Lauterbach debugger: 

Debugger is set to standby mode and then while running the application, I will plug out the power supply from the target board. I already set the breakpoints at different exception handler. Then I will power up the board and expect that some the execution will stop at any breakpoint (exception handlers).

But I am not able to see any call to exception handlers. If you have any idea or views regarding this, kindly share.

As this project is just for study research, any suggestion would be appreciated.

Regards

Arpit

0 Kudos

926 Views
petervlna
NXP TechSupport
NXP TechSupport

Hi,

What you are testing is not a good test scenario.

1. If you plug of board all micro register content is lost. STCU, FCCU or RGM,etc....

Therefore you wont see any fault after powering it again. Because the registers was not voltage supplied, neither clocked.

2. After reconnecting of power. The micro will starts normal power on sequence. Test Power management unit, load DCF records, initialize flash, etc...

Just common micro power on sequence. Where no previous faults are latched.

If you want to play with voltage, I suggest you to take programmable power supply and insert drops / peaks of voltage in time, just slightly out of spec of datasheet for very shot time.

But to test exception this is not the best way.

Please read e200z4 core reference manual to see the exception details:

pastedImage_1.png

Peter

926 Views
arpityadav
Contributor II

Hi Peter,

thanks for the explanation. Yes what you explained makes sense.

Thanks again :smileyhappy:

Arpit

0 Kudos

926 Views
arpityadav
Contributor II

Hi Peter,

Thanks for the kind reply and i hope you had a good vacation, I will try it and will revert you for more question.

I really appreciate your knowledge and help.

Best regards

Arpit

0 Kudos