This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Mysterious crashes

I'm working on a uVision4 project for the Atmel SAM3S4B, and have been observing strange crashes in my code.
The issue comes and goes after editing and recompiling code for no apparent reason, but it's repeatable when it does occur.

The following snippets are examples of the kind of problems that I've been seeing.

In one instance, the following code (in one particular function) resulted in consistent crashes at power-on:

uint8_t i;

for(i=0; i<16; i++)
{
...
}

Note: i is not used between its declaration and assignment in the for-loop.

Running this through debug showed that execution ended up in the Hard Fault handler with the FORCED bit set in the Hard Fault Status Register.

The code had been working before I made changes to unrelated code in another module.
I found that the following change resolved the problem, though after making edits elsewhere, I went back and reverted this to the code above and the micro did not crash:

uint8_t i=0;

for(i=0; i<16; i++)
{
...
}

I also encountered a situation where the micro would immediately crash after I'd made changes to parts of the code that aren't even executed at power-on.

I've discovered that I can usually resolve each problem as it arises by toggling the state of the ‘One ELF Section per Function’ checkbox on the C/C++ tab of the target options in my project, but this isn't a permanent solution because new problems continue to appear as I work on the code.

My project uses the ‘libchip’ library (libchip_sam3s4_mdk_rel.lib) contained in the ‘SAM3S Softpack 2.1’ provided by Atmel.
I've turned off optimization in both my code and the library.

I know the description of the problem is rather vague, but I would like to know if anyone else has encountered similar strange behaviour, and what the cause might be.

Thanks.

IDE-Version:
µVision V4.71.2.0
Copyright (C) 2013 ARM Ltd and ARM Germany GmbH. All rights reserved.

Tool Version Numbers:
Toolchain:        MDK-ARM Standard  Version: 4.71.0.0
Toolchain Path:    C:\Keil\ARM\ARMCC\bin\ 
C Compiler:         Armcc.Exe       V5.03.0.69
Assembler:          Armasm.Exe      V5.03.0.69
Linker/Locator:     ArmLink.Exe     V5.03.0.69
Librarian:          ArmAr.Exe       V5.03.0.69
Hex Converter:      FromElf.Exe     V5.03.0.69
CPU DLL:            SARMCM3.DLL     V4.71.0.0
Dialog DLL:         DCM.DLL         V1.10.0.0
Target DLL:         UL2CM3.DLL      V1.150.9.0
Dialog DLL:         TCM.DLL         V1.14.1.0

0