Crash if an unused variable is commented out???

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

Crash if an unused variable is commented out???

715 Views
dave408
Senior Contributor II

This is unlike anything I've experienced before, so I was hoping that some of the ARM experts here could chime in and offer their perspective on my situation.

 

I have an application running on a MK22FN128VLL10.  I have a class A that has a uint32_t member variable.  I have another unrelated class B that pulls data in from the UART.  The problem I'm seeing is that if I comment out the uint32_t in class A, a method in class B literally causes a hard fault.  If I replace the uint32_t with a uint8_t, it also crashes.  However, if I use a uint8_t[4], then it runs just fine.  So it seems like a memory alignment issue; I did a hail mary and added the -mno-unaligned-access compiler flag, but that didn't fix the problem.

 

Can anyone suggest what's going on, or throw some potential search terms at me that will get me on the right track towards fixing this problem?

 

Thanks!

Labels (1)
0 Kudos
4 Replies

468 Views
scottm
Senior Contributor II

When I see something like this and it's not a memory alignment issue, my first suspicion is a stack overflow or bad pointer somewhere.  Could be a value is getting trashed regardless but it's only something that causes a crash when you remove that one member.

Something else that's given me headaches is a packing mismatch.  In one case I was running FatFS and in one part of the code the ff.h header was picking up a #pragma pack from another header that failed to reset the packing to default, and in the FatFS module itself ff.h didn't get that pack directive.  The result was that somewhere in the middle of the struct, the two pieces of code diverged in their ideas about where the next field was.  A long filename buffer was offset by one byte and caused horrible crashes.

If you know where the crash is happening, go through in instruction stepping mode and see if you can catch what it's doing.

Scott

0 Kudos

468 Views
Carlos_Mendoza
NXP Employee
NXP Employee

Hi Dave,

Can you share your project so we can reproduce the issue?

Thanks in advance!

Best Regards,

Carlos Mendoza

Technical Support Engineer

0 Kudos

468 Views
dave408
Senior Contributor II

Hi Carlos,  I can email you the project (cannot post here), but I do not think you will be able to reproduce the issue unless you have our hardware as well.  Do you still want to take a look at it?  If so, please send me a message with your NXP email address, or instructions for whatever process you prefer to use.  Thanks!

0 Kudos

468 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi dave,

Carlos is on vacation this week.

from my experience, it's hard to root the problem without reproduction.

can you please develop a demo code that we can use to produce the problem on demo board?


Have a great day,
Jennie Zhang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos