Hello,
I am currently working on device K70FN1M0M15 with MQX OS.
FPU : fpv4-sp-d16
I have a function which takes an enumerate and a float as parameters and the problem is that sometimes the function’s float parameter takes the value 0 instead of the given value.
Here is an example of the function call, then the source code of the function:
MRTimer_SetValue(mTimerRefBracketAlarm1, 3.0);
void MRTimer_SetValue(tTimersRef TimerRef, float setTimerValue)
{
uint16_t *pDestValue = NULL;
uint16_t rawValue = 0;
test = setTimerValue;
if(setTimerValue == 0)
test++;
if ((TimerRef >= MRTIMER_10MS_FIRSTREF) && (TimerRef <= MRTIMER_10MS_LASTREF))
{
rawValue = (uint16_t) (setTimerValue * 100.0);
pDestValue = &timers10ms[TimerRef - MRTIMER_10MS_FIRSTREF];
}
else if (TimerRef >= MRTIMER_100MS_FIRSTREF && TimerRef <= MRTIMER_100MS_LASTREF)
{
rawValue = (uint16_t) (setTimerValue * 10.0);
pDestValue = &timers100ms[TimerRef - MRTIMER_100MS_FIRSTREF];
}
else if (TimerRef >= MRTIMER_1000MS_FIRSTREF && TimerRef <= MRTIMER_1000MS_LASTREF)
{
rawValue = (uint16_t) (setTimerValue * 1.0);
pDestValue = &timers1000ms[TimerRef - MRTIMER_1000MS_FIRSTREF];
}
else
{
return;
}
if(rawValue >65530 || rawValue < 3 || pDestValue == NULL)
{
tmpdebug_ref = TimerRef;
tmpdebug_valeur = rawValue;
test++;
}
else
{
*pDestValue = rawValue;
}
return;
}
As you can see, I give 3.0 as parameter but when the bug occurs « setTimerValue » in the function take the value 0 instead of 3.0.
The call of the function uses this assembler code:
577 MRTimer_SetValue(mTimerRefBracketAlarm2, 3);
0001fd08: ldr r3, [r7, #4]
0001fd0a: ldrh r3, [r3, #6]
0001fd0c: addw r3, r3, #287 ; 0x11f
0001fd10: uxth r3, r3
0001fd12: mov r0, r3
0001fd14: vmov.f32 s0, #8
0001fd18: bl 0x2bae8 <MRTimer_SetValue>
In my opinion, the value of the parameter is stored in the register s0 (red line).
Then when I enter in the function, I have this assembler code:
MRTimer_SetValue:
0002bae8: push {r7, lr}
0002baea: sub sp, #16
0002baec: add r7, sp, #0
0002baee: mov r3, r0
0002baf0: vstr s0, [r7]
0002baf4: strh r3, [r7, #6]
The instruction” 0002baf0: vstr s0, [r7]” is supposed to store the content of an extension register(S0) to memory (address given by r7).
When the bug occurs, after this instruction the value in the memory is 0.
For your information, it’s not possible to watch S0 in KDS 3.0.
Do you have any clue about this odd behavior ?