Hello! Does anybody use Simulink Real-Time Workshop Embedded Coder to generate c-code for AVR32 linux application? My program was successfully compiled but give NaN output instead of double value after some correct iterations on NGW100 board, while it successfully run on host maschine under Ubuntu 8.04 (compiled with gcc in eclipse) and under WinXP. I use avr32-linux-gcc compiler generated with Buildroot 2.2.0-rc6. Maybe there are key factors in c-code generator setup specially for AVR32 target? Thanks!

## C-code generation with Simulink for AVR32

Update to buildroot 2.2.0 stable, there was a fix which for almost exactly what you say. I thought that fix was in -rc6 but I can't be sure..

-S.

I thought that latest Buildroot is 2.2.0-rc6. I confused with Buildroot versions.. Tell me please what is 2.2.0 stable and what rc6 means? I heard about NaN fix in latest Buildroot but I can't find any information about this problem on web. Atmel's support answered me with suggestion to debug program with gdb server but there are no words about avr32-linux-compiler version.

And what You mean saying about Buildroot update? Is it only avr32 compiler version update actual for me? Or I need new linux rootfs and kernel update? Thanks!

RC6 - Release Candidate 6 (this is from 20080918) while the stable version is from 20080925.

eaanon01, thanks for explanation!

**squidgit wrote:**

Update to buildroot 2.2.0 stable, there was a fix which for almost exactly what you say. I thought that fix was in -rc6 but I can't be sure..-S.

squidgit, I compiled my project with avr32-linux-gcc generated with Buildroot 2.2.0 stable and 2.2.0-rc6 both but there is still NaN error.

Can you reduce the failing code to a small test case? Hard to debug this without any code.

I found the source of NaN problem. The code is:

eml_N_sum = sqrt(eml_N_hor_sp * eml_N_hor_sp + eml_N_ver_sp * eml_N_ver_sp); rtb_Gam_sp = asin(eml_N_hor_sp * sqrt(eml_N_sum * eml_N_sum - eml_N_ver_sp * eml_N_ver_sp) / eml_N_sum);

When eml_N_hor_sp == 0 && eml_N_ver_sp != 0, then Sqrt counts eml_N_sum incorrectly, so after first sqrt

(eml_N_sum < eml_N_ver_sp)

(in WinXP host machine they are equal and there is no error!). Next command try to take sqrt from negative number and gives NaN.

I tried implementing this example in avr32studio(XP) but I got a strange error(strange for me at least).

#include... { double start=4; sqrt(4); sqrt(start); ...

Then I get the following error:

undefined reference to `sqrt' Test01 main.c

But only on the sqrt with a variable as input?

Did you link with "-lm"?

Can You tell me is the function sqrt for AVR32 of double type? I can't understand where is the problem why sqrt of host machine works good but not on AVR32? Is it only architecture difference or math.h incompatibility?

From libm/w_sqrt.c:

double sqrt(double x)

Implemented in the libm/e_sqrt.c file, and it is a general implementation done in C, not architecture specific.

Thanks! I had some doubts about double/float types of sqrt..

Now I've tested next code on AMD Athlon PC and AVR32:

while ( i < 10000) { a = sqrt((double) i); b = sqrt((double) i); c = a * b; d = (double) i - c; fprintf(prntout, "%d; %.16f; %.16f; %.16f; %.16f; \n", i, a, b, c, d); printf("%d; %.16f; %.16f; %.16f; %.16f; \n", i, a, b, c, d); i = i + 1; }

Inaccuracy "d" on AMD is about +-2e-12 (plus minus) and on AVR32 is about +4e-6 (only plus). Is it correct test? Can anybody check this?