Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SAM9261-EK Problem with double Values

7 views
Skip to first unread message

Martin D.

unread,
Apr 13, 2010, 9:42:01 AM4/13/10
to
Hi,
We are using a clone of the MF4.0 SAM9261-EK Solution and experiencing a lot
of troubles when using double types on our Hardware.

On a fresh built SAM9261 Port and a new .NetMF Hello World Project we want
to run the following code:
public static void Main()
{
Double dblvar = 3.3d;
float fltvar = 4.4f;
while (true)
{
Debug.Print("Double: " + dblvar.ToString() + ", Float: " +
fltvar.ToString());
Thread.Sleep(1000);
}
}

and get the following result on the debug console:
Double: 3.63395408954883248e-313, Float: 4.400000096

The code runs fine on the emulator so the problem has to be in the port. Has
anyone else encountered this problem?
We could also use float values but for some reason there is no float.Parse
function.
Where could we look for clues on how to solve this issue?

greetings, Martin

Lorenzo Tessiore

unread,
Apr 13, 2010, 3:51:01 PM4/13/10
to
Hello Martin,

we had a similar problem in the past and it had to do with un-aligned stack
access.
Align the StackTop and StackBottom global variables in your scatterfile (xml
file under the solutions directory) to the 8 bytes boundary.

Regards
Lorenzo

Martin D.

unread,
Apr 14, 2010, 8:48:01 AM4/14/10
to
Hello Lorenzo,

thanks for the quick reply!
Stack_Bottom and Stack_Top are defined as:
<Set Name="Stack_Bottom" Value="0x00326000"/>
<Set Name="Stack_Top" Value="0x00327FF8"/>

the size of the Stack is defined further down as Size="%Stack_Top -
Stack_Bottom% + 4"/>

I´ve changed the Top to 0x0023 8000 and played around with the size by
adding zero or 8.

but none of these changes helped me. i´ve tried some debug messages in
tinybooter and they print out okay, i guess the same goes for tinyCLR but
haven´t testet a output of doubles there.

Martin D.

unread,
Apr 14, 2010, 9:00:03 AM4/14/10
to
just saw a small type error: i´ve changed Stack_Top to 0x0032 8000.

Armand R.

unread,
Apr 15, 2010, 2:31:01 PM4/15/10
to
Martin,

We had a similar issue with .net Longs and aligning the TinyCLR stack to an
8 byte boundry as Lorenzo suggested did fix it.

-Armand

Martin D.

unread,
Apr 16, 2010, 6:49:01 AM4/16/10
to
Hi, Armand

I´ve tried to change the base adress of Stack_Top to 0x0032 8000 which looks
pretty byte aligned to me.
i´ve also added the Align option in the ExecRegion definition altough i´m
not sure if this will change anything:
<ExecRegion Name="ER_STACK_BOTTOM" Align="0x08" Base="%Stack_Bottom%">
<FileMapping Name="*" Options="(SectionForStackBottom)" />
</ExecRegion>
<ExecRegion Name="ER_STACK_TOP" Align="0x08" Base="%Stack_Top%">
<FileMapping Name="*" Options="(SectionForStackTop)" />
</ExecRegion>

am i missing something here?

Ant

unread,
Apr 27, 2010, 6:25:01 AM4/27/10
to
Martin,
I had an issue with double too and it turned out to be a GCC compiler
optimization issue in clr\include\TinyCLR_Runtime__Heapblock.h

operator double() const
{
/*
* These loops
were added to defeat a compiler
* optimization
in GCC 4.2 in the '-O2' or higher
* optimization
mode. It was not properly copying
* the data to
the returned value.
*/
double ret_val;
char* tmp = (char*)&ret_val;
char* src =
(char*)&_L;

for(int i = 0; i
< 4; i++)
{
tmp
[i] = src[i];
}
src = (char*)&_H;
for(int i = 0; i
< 4; i++)
{
tmp
[i+4] = src[i];
}
return ret_val;
}

...

R8& operator=( const double num )
{
/* See comments
for double() operator */
char* src =
(char*)&num;
char* tmp =
(char*)&_L;

for(int i = 0; i
< 4; i++)
{
tmp
[i] = src[i];
}
tmp = (char*)&_H;
for(int i = 0; i
< 4; i++)
{
tmp
[i] = src[i+4];
}
return *this;
}

This solved the problems for me. Hope it helps you as well.
Andreas, AUG Elektronik GmbH

Martin D.

unread,
Apr 27, 2010, 7:23:01 AM4/27/10
to
Thanks a lot! problem solved.
0 new messages