Hello,
I'm working on a the Coldfire MCF5329
I need to use floating point in my project so I follow the instruction in EWL C Reference and set this in ansi_prefix.CF.h
....#define _EWL_C99 1...#define _EWL_FLOATING_POINT 1
and built the EWL project (EWL C) as the guideline.
The following piece of code couldn't get compiled (*** function has no prototype) even though the compiler and linker did link to "ColdFire_Support/ewl/lib/"
#include <math.h>....float BUC_output_power = expf(temp_value);
Any help is apprecited,
Hello Daniel,
MCF5329 doesn't implement hardware FPU unit, so floating point operations with float/double is emulated by software functions. I tried to create a CW 10.2 MQX 3.8 project for M5329EVB and included float operations.
In the Project Properties, C compiler options, Processor -> Floating point should be configured to Software. This is the default setting when I created the project using New project wizard.
Then I add 3 float variables a do some computation in C source code:
a = -1.0;
b = 10.0;
c = a*b;
Build goes Ok and in the disassembly I can see the multiplication results in a jump to library fp_coldfire.a:
jsr __f_mul
Then I include <math.h> and try expf. This goes with the same error as in your case. Then I try exp:
c = exp(a);
and this one builds with the warning that double result from exp function is converted to float. By looking into xMAP file I can see the exp function is linked from "libm.a" library.
So it seems it can work with "double" operations. I'm not sure if there exists software emulation <cmath> library for single precision float functions for ColdFire.
Martin
Hello dtran,
What reference did you follow? EWL C reference pdf?
I checked the directory EWL_C , the function expf is not part of the library, it's in sun_math directory. On another hand, program with exp2f is compiled . I assume you have to turn on (define) _EWL_USES_SUN_MATH_LIB.
Regards,
MartinK
Yes, I did follow the EWL C reference pdf. On page 106, I assumed that only an #include <math.h> is sufficient. Also _EWL_USES_SUN_MATH_LIB was on by default in C:\Freescale\CW MCU v10.2\MCU\ColdFire_Support\ewl\EWL_C\include\coldfire\ansi_prefix.CF.h. Somehow I can't attach the file so I copied it as below.
/* EWL * Copyright © 1995-2009 Freescale Corporation. All rights reserved. * * $Date: 2010/01/25 12:54:04 $ * $Revision: 1.4 $ *//* * ansi_prefix.CF.h */#ifndef __ansi_prefix__#define __ansi_prefix__#include <os_enum.h>#define __dest_os __emb_coldfire#define __COLDFIRE_HW_FPU__ ((defined(__MCF547x__) || defined(__MCF548x__)) && !__option(fp_library))#define _EWL_BF_ORDER __attribute__((bitfields(big_endian)))/*********************************************//* OS Specific Configuration Flags *//*********************************************//* bare board provides console I/O */#ifndef _EWL_CONSOLE_SUPPORT #define _EWL_CONSOLE_SUPPORT 1#endif#if _EWL_CONSOLE_SUPPORT #define _EWL_BUFFERED_CONSOLE 0#endif#if !defined(__STDC_WANT_LIB_EXT1__)#define __STDC_WANT_LIB_EXT1__ 1#endif#define _EWL_C99_MATH_LEAK 1/* File IO Support Configuration Flags */#ifndef _EWL_OS_DISK_FILE_SUPPORT #define _EWL_OS_DISK_FILE_SUPPORT 0#endif/* Time Support Configuration Flags */#ifndef _EWL_OS_TIME_SUPPORT #define _EWL_OS_TIME_SUPPORT 0#endif#ifndef _EWL_CLOCK_T_AVAILABLE #define _EWL_CLOCK_T_AVAILABLE 0#endif#ifndef _EWL_TIME_T_AVAILABLE #define _EWL_TIME_T_AVAILABLE 0#endif#if _EWL_OS_TIME_SUPPORT && ((!_EWL_CLOCK_T_AVAILABLE) || (!_EWL_TIME_T_AVAILABLE)) #error _EWL_CLOCK_T_AVAILABLE and _EWL_CLOCK_T_AVAILABLE must match _EWL_OS_TIME_SUPPORT#endif/* Thread Safety Configuration Flags */#ifndef _EWL_THREADSAFE #define _EWL_THREADSAFE 0#endif#ifndef _EWL_PTHREADS #define _EWL_PTHREADS 0#endif#if _EWL_PTHREADS && !_EWL_THREADSAFE #error _EWL_PTHREADS and _EWL_THREADSAFE must match#endif#ifndef _EWL_LOCALDATA_AVAILABLE #define _EWL_LOCALDATA_AVAILABLE 1#endif/* Memory Allocation Flags */#ifndef _EWL_OS_ALLOC_HEAP_SUPPORT #define _EWL_OS_ALLOC_HEAP_SUPPORT 0 #define _EMBEDDED_WARRIOR_MALLOC 1#endif#ifndef _EWL_HEAP_EXTERN_PROTOTYPES #define _EWL_HEAP_EXTERN_PROTOTYPES \ extern far char __heap_addr[]; /* starting address for heap */ \ extern far char __heap_size[]; /* size of the stack (Linker pref panel) */#endif#ifndef _EWL_HEAP_START #define _EWL_HEAP_START __heap_addr#endif#ifndef _EWL_HEAP_SIZE #define _EWL_HEAP_SIZE __heap_size#endif/********************************************//* Additional Portability Flags *//********************************************/#ifndef _EWL_LONGLONG #define _EWL_LONGLONG 1#endif#ifndef _EWL_FLOATING_POINT //#define _EWL_FLOATING_POINT 0 #define _EWL_FLOATING_POINT 1#endif#ifndef _EWL_WIDE_CHAR #define _EWL_WIDE_CHAR 0#endif#ifndef _EWL_USES_SUN_MATH_LIB #define _EWL_USES_SUN_MATH_LIB 1#endif#ifndef _EWL_POSIX #define _EWL_POSIX 0#endif#ifndef _EWL_NEEDS_EXTRAS #define _EWL_NEEDS_EXTRAS 0#endif#ifndef _EWL_ACCURATE_BUT_LARGE_ANSI_FP #define _EWL_ACCURATE_BUT_LARGE_ANSI_FP 0#endif/************************************************//* Flags to reduce code and data size *//************************************************/#ifndef _EMBEDDED_WARRIOR_CTYPE#define _EMBEDDED_WARRIOR_CTYPE 1#endif#ifndef _EWL_STRERROR_KNOWS_ERROR_NAMES #define _EWL_STRERROR_KNOWS_ERROR_NAMES 0#endif#ifndef _EWL_ASSERT_DISPLAYS_FUNC #define _EWL_ASSERT_DISPLAYS_FUNC 0 // Assert will not display function name, non-c99 behavior (7.2.1.1)#endif#ifndef _EWL_C_LOCALE_ONLY #define _EWL_C_LOCALE_ONLY 1#endif#ifndef _EWL_C99 //#define _EWL_C99 0 #define _EWL_C99 1#endif#if !_EWL_C99 && !_EWL_C_LOCALE_ONLY #error _EWL_C_LOCALE_ONLY must be turned on if _EWL_C99 is off#endif#ifndef _EWL_FLOATING_POINT_IO #define _EWL_FLOATING_POINT_IO 0#endif#ifndef _EWL_C99_PRINTF_SCANF #define _EWL_C99_PRINTF_SCANF 0#endif#ifndef _EWL_USES_EXIT_PROCESS #define _EWL_USES_EXIT_PROCESS 1#endif#ifndef _EWL_FLT_EVAL_METHOD #define _EWL_FLT_EVAL_METHOD 0#endif#if defined(__cplusplus) #define _EWL_USING_NAMESPACE#endif#define __ANSI_OVERLOAD__#define _EWL_INTEGRAL_MATH 1#if _lint #define _EWL_MATH_CDECL#elif defined(__cplusplus) #define _EWL_MATH_CDECL#else #define _EWL_MATH_CDECL __declspec(register_abi)#endif/******************************************************************** * Platform Specific Configuration: * * ewl_t.h - Platform specific define of _EWL_INT32_TYPE for _INT32 * ********************************************************************/#if __fourbyteints__ /* work around cmath/FP issue for now */ #define _EWL_INT32_TYPE int#else #define _EWL_INT32_TYPE long#endif/************************************************************************ * Platform Specific Configuration: * * climits - Platform specific define of _SIZEOF_INT and EWL_SIZEOF_INT * ************************************************************************/#if __fourbyteints__ #define _SIZEOF_INT 4 #define _EWL_SIZEOF_INT 4#else #define _SIZEOF_INT 2 #define _EWL_SIZEOF_INT 2#endif#define _EWL_DOUBLE_SIZE 64#endif /* __ansi_prefix__ *//*#pragma once on*//* Switching this pragma on, can improve compilation speed but it may cause problems with the use of assert.h, which generally depends upon being actually included more than once during compilation. */
Hi Daniel,
Is there a solution to this issue? I recently upgraded from CW5 to CW10.1. I have been modifying source code that compiled fine under CW5, but ran into a hurdle in the math functions. It seems the compiler does not like me using any math functions. I have "#include <math.h>" at the top of the source file, yet the compiler complains that there are no function prototypes for these functions. I shouldn't have to hack the compile options to get this to build, right?
Thank you,
Paul
I don't have an exact answer to your problem, I use a different processor, but recently I jumped far further into math.h functions than I wanted too.
Here is what I know, double check which precompiled libraries your linker is pointing too. Some of them do not contain the math functions. I think the libc_xx.a are reduce code sets and don't include and standard math functions. Theere is documentation in the Codewarrior install directory under help that can help you decode the naming conventions of the libraries.
I would recommend starting a temp project from scratch and checking if the math functions work, for the wizard selections you made.
If you still aren't making progress, create a service request. In my case the precompiled libraries had a bug in them and it didn't matter what I did until Freescale taught me the magic it would take to get it to work.
Hope this helps