[En-Nut-Discussion] Problems using global variables and/or floating point numbers on Nut/Os (using ethernut 5)
Vegard Aaker
vegardaa at stud.ntnu.no
Fri May 18 15:56:55 CEST 2012
Hi,
I have a problem using global variables and/or floating point numbers in
Nut/Os and now I am really hoping that someone might have a clue to what I
have done wrong.
So far I have set up the Nut/Os with;
Click on Menubar: *Edit > Settings*
- Goto Tab: *Build*
- Choose Platform: *arm-gcc*
- Goto Tab: *Samples*
- Choose Programmer: *arm-jom*
- In addition, I have set the option: C runtime(target specific) - file
streams - floating point. This might errorous, but I did not find any other
option for including floating point arithmetics on the board.
(I use the Makefile from the editconf example application if that is of
interest.)
The code I am trying to get working is
#include <dev/board.h>
#include <sys/socket.h>
#include <sys/heap.h>
#include <sys/timer.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <io.h>
int globalD;
int main(void)
{
u_long baud = 115200;
double fpValue = 0.6333;
char stringen[]= "2.122321";
/* Assign stdout to the DEBUG device. */
NutRegisterDevice(&DEV_DEBUG, 0, 0);
freopen(DEV_DEBUG_NAME, "w", stdout);
_ioctl(_fileno(stdout), UART_SETSPEED, &baud);
/* Register Ethernet controller. */
if (NutRegisterDevice(&DEV_ETHER, 0, 0)) {
puts("Registering " DEV_ETHER_NAME " failed.");
}
// Testing
printf("test 1: Global variables \n");
globalD = 5;
printf("globalD = %d \n\n" , globalD);
printf("test 2: floating points \n");
fpValue*=2;
printf("fpValue=0.6333*2 = %f \n\n", fpValue);
printf("test 3: Conversion from text to double: \n");
printf("stringen er %s \n", stringen);
fpValue = atof(stringen);
printf("as floating point number = %f \n\n", fpValue);
for (;;) {
NutSleep(1000);
}
return 0;
}
I experience the following scenarios:
- If I remove test 1, test 2 and 3 is working.
- If I remove test 2 and 3. Test 1 is working
- If all test cases are active, I get wrong output and the program stops
after printing 98288333087859433.
Any thoughts to what I have done wrong?
--
Kind regards
Vegard Aaker
More information about the En-Nut-Discussion
mailing list