problem with float variable

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

problem with float variable

602件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by JoeE on Fri Aug 08 12:03:54 MST 2014
Hello,
I am working with lpc4370 processor (FPv4-SP Soft ABI) and have a strange issue with a floating point variable. Every time when I am asigning a global integer to the local float variable a hard fault error occors.
Does anybody have an explanation for that.
Here is the example code:

//global variable
volatile int32_t g = 200;

void myfunction(void)
{
int32_t a, b;
float r, t;

r = 1.5;
b = 100;

//example 1 (works)
t= r;
a = (int32_t) t;

//example 2 (works)
t = b;
a = (int32_t) t;

//example 3 (not working – ending in hard fault handler)

t= g; // error occurs here
a = (int32_t) t;
}
0 件の賞賛
返信
1 返信

570件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Pacman on Tue Sep 09 20:53:39 MST 2014
Did you find out what caused this ?

The difference is most likely that the code was optimized, so that none of the assignments you made were actually in the final binary, since they were unused variables.

Try building the code again.
Questions:
1: Which compiler do you use, GCC ?
2: Try turning optimizing off: -O0
3: Try disassembling your code. For instance if using a GNU toolchain: objdump -D file.elf
4: Try putting 'volatile" in front of all your local variables as well (yes, you can do that, and it will work - but it's only a good idea to do when making tests).
5: If using OpenOCD, you can halt the processor when it reaches the HardFault handler, then you can see the old value of PC and LR; they will point to the return-address, so you can disassemble using 'arm disassemble <address> <length>' and see where it failed.
6: Did you build your libraries for the Cortex-M4 with soft floating point support ? -if not, the HardFault is probably on a 32-bit ARM instruction, which was generated in the hope that the microcontroller would be able to run it. ;)
0 件の賞賛
返信