When I change a floating-point value to an integer inside a function, the program doesn't execute

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

When I change a floating-point value to an integer inside a function, the program doesn't execute

2,637 次查看
TanTianLong
Contributor I
When I used S32DS.ARM.2.2 software to compile the project, I had a problem. When I changed an integer value to a floating-point type inside a function, such as 20 to 20.0, the compiled map file had some more link content, and the program ran normally, but when I changed 20.0 to 20, it did not run normally. The program did not enter initialization.
Products:FS32K144HAT0MLLT
 
When I changed 20 to 20.0, the program ran normally, but the program could not enter the initialization with the value 20, and the app would stop at DefaultISR (in debug mode) after jumping from bootloader to this appWhen I changed 20 to 20.0, the program ran normally, but the program could not enter the initialization with the value 20, and the app would stop at DefaultISR (in debug mode) after jumping from bootloader to this appWhen I change 20 to 20.0, the map file has a few more library linksWhen I change 20 to 20.0, the map file has a few more library linksbootloader jumps to app and enters DefaultISRbootloader jumps to app and enters DefaultISR
0 项奖励
回复
8 回复数

2,503 次查看
jiri_kral
NXP Employee
NXP Employee

Hi, 

which types are bat1 and bat3? They are float? If So, it is nonsense use abs function. abs() accepts integers and return integer as well. Also is nonsense compare floats like if (bat1 == 0) - if bat1 is float. 

0 项奖励
回复

2,427 次查看
TanTianLong
Contributor I

Hi, @jiri_kral 

TanTianLong_0-1736391670119.png

Did you see my response?

0 项奖励
回复

2,407 次查看
jiri_kral
NXP Employee
NXP Employee

Hi, 

I tried reproduce it on my side, but no success. Do you know which exact instruction in disassembly invoke the exception? Because it doesn't make sense at all. 

I'm suspecting that if you put float instead of int, the comparison between int and float makes that the function return 0 (I'm not sure if the return 0 is the correct or return 1 is the correct. Typically return 0 means no error. 

You can also implement fault handler to figure out what exactly happens - https://community.nxp.com/t5/S32K-Knowledge-Base/Fault-handling-on-S32K14x/ta-p/1114447 

0 项奖励
回复

2,392 次查看
TanTianLong
Contributor I

Do you mean the “Disassembly”?

defaultISRProblem1.png

0 项奖励
回复

2,361 次查看
jiri_kral
NXP Employee
NXP Employee

Hi, 

in Debug session you can switch into single instruction mode

jiri_kral_0-1736512480660.png


and you can step by one instruction in disassembly window (the window appears when single instruction step is enabled) to find out which exact instruction invoke the exception: 

jiri_kral_1-1736512559106.png

 




0 项奖励
回复

2,316 次查看
TanTianLong
Contributor I

The failed program cannot be debugged single-step, and once you enter the program, you enter DefaultISR

0 项奖励
回复

2,500 次查看
TanTianLong
Contributor I
No,they are uint16_t
0 项奖励
回复

2,519 次查看
TanTianLong
Contributor I

The problem I've found so far is the 64-bit arithmetic. I defined 64-bit local variables inside a function and did all the arithmetic, including division. When I changed the variable to 32 bits, the program worked. This is where another problem I found earlier is to comment out the 64-bit arithmetic inside the function. So far, the accuracy of the algorithm has dropped, but the program is working. But I don't know why that decimal point makes this 64-bit operation work.

defaultISRProblem1.png

I targeted this 64-bit operation because: I mentioned in the previous diagram that the program doesn't run, it stops at DefaultISR, WDOG_EWM_IRQHandler is displayed, and on the next line is __aeabi_uldivmod, which is a function (presumably added by the compiler) that performs division and modulo on long unsigned integers, with only one place in the program where 64-bit arithmetic is used. So I've targeted the problem here. In practice, this action does have an effect on the program. I couldn't find a good explanation for the effect of floating-point on 64-bit operations

0 项奖励
回复