This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C3x / C4x Optimizing C compiler get error msg: [F108] 'FILE' undefined. However I have included stdio.h

Hi,

I am trying to use C3x/C4x Optimizing C Compiler to compile a c code to run on a dps. I used a batch file to compile it and I want to open an external txt file to get the input for the C program. However, I get this error msg when I compile:

".\pmsm.c", line 96: [F108] 'FILE' undefined
".\pmsm.c", line 96: [F108] 'inputfile' undefined
COMPILE FAILURE
I have included stdio.h and the function 'printf' works in the code, and 'printf' is in stdio.h. I don't get it why 'FILE' can't be find in the stdio.h. 
This is my batch file code:

@echo off
cl30 -g -mn -v40 -q -x2 -o2 -fr . -iC:\M44\Include\Target -iC:\c3xtools\INCLUDE .\PMSM.c

IF ERRORLEVEL == 255 goto failure

lnk30 -o PMSM.out -i c:\m44\lib\target -i c:\m44 -i c:\c3xtools\lib -q -c -stack 0x200 -heap 0x400 -x .\PMSM.obj -l stdio.lib -l periph.lib -l dsp.lib -l prts40.lib -l rts40.lib c:\m44\generic.cmd
echo COMPILE SUCCESS - PMSM.out created
goto end

:failure
echo COMPILE FAILURE
pause

:end

Here is a part of my C code:

#include <math.h> // defines trig, epx, and hyperbolic math
// functions
#include <intpt40.h> // interrupts???
#include "dsp.h" // commonly requested C-callable digital
#include "periph.h" // definitions for peripheral devices.
#include <stdio.h> // definitions for console terminal.
#include <stdlib.h>
//--------------------------Define Constants---------------------------
#define F_Delta 20E3 // delta_hyst frequency (max = 20k for stable interrupts?).
#define F_DDS 20E6 // frequency of DDS timer.
#define IO_TIMER 1 // channel of IO timer.
#define IO_XRPT 1 // IO interrupt address.
#define IO_TRIG PIT1 // IO trigger.
#define RESOLUTION 4096 // resolution of sine waves.
#define Max_I 20 // maximum allowed current.
#define pi2 6.2831853071796 // 2.0*pi
#define sqrt2 1.4142135623731 // square root of 2.0
#define offset -25 // rotor position offset (for 90deg electrical) in encoder counts. (zero for testing)
#define off_flag 1 // rotor position offset flag (1=active, 0=inactive)
#define P 4 // machine poles.

//--------------------------Define Variables---------------------------
volatile float Ias_pH; // upper commanded current band.
volatile float Ias_nH; // lower commanded current band.
volatile float Ibs_pH; // upper commanded current band.
volatile float Ibs_nH; // lower commanded current band.
volatile float Ics_pH; // upper commanded current band.
volatile float Ics_nH; // lower commanded current band.
volatile float ADC1; // ADC M0 CH0 input.
volatile float ADC2; // ADC M0 CH1 input.
volatile float ADC5; // ADC M1 CH0 input.
volatile float ADC6; // ADC M1 CH1 input.
volatile float ADC7; // ADC M1 CH2 input.
volatile float Ia; // A phase current input.
volatile float Ib; // B phase current input.
volatile float Ic; // C phase current input.
volatile float I; // commanded current
volatile float Ii; // commanded current
volatile float H; // hystersis band
volatile float Hi; // hystersis band
volatile float speed; // commanded speed counter
volatile float deg90; // ninty electrical degrees
volatile int flag; // delta hysteresis flag.
volatile int count; // counter for sinusoids.
volatile int sp_count; // speed counter.
float cos_as[RESOLUTION]; // a phase cosign vector.
float cos_bs[RESOLUTION]; // b phase cosign vector.
float cos_cs[RESOLUTION]; // c phase cosign vector.
int position = 0; // position read directly from position encoder (12 bit)
float qrm = 0.0; // mechanical rotor position in radians

//--------------------------Define Functions---------------------------
#pragma CODE_SECTION(IO_isr, ".onchip"); // define isr as ext interrupt?
#pragma INTERRUPT(IO_isr); // DAC function.
void IO_isr(void); // IO interrupt service routine.
void initialize(void); // initialization function.
void shutdown(void); // shutdown function.
void display(int i, int pcount); // display function.

//--------------------------MAIN FUNCTION------------------------------

/**********************************************************************
Function: main(void)

Description: This is the main function of the application.

**********************************************************************/
main( void )
{
// Define Variables
int i,col, row, pcount; // index variables
float two_pi = 2.0 * (4.0 * atan(1.0)); // 2*pi
float two_pi_third = two_pi/3.0; // 2*pi/3
float a_res = (P/2)*two_pi/RESOLUTION; // position angle resolution
FILE* inputfile;  // this is line 96
// Initialize variables
flag = 0; // delta hystersis flag
count = 0; // sinusoid counter flag
sp_count = 1; // speed count
pcount = 0; // print counter

// Initialize DSP
initialize();

// Generate position vector and sine waves
for (i = 0; i <= RESOLUTION; i++)
{
qrm = i*a_res;
cos_as[i] = cos(qrm);
cos_bs[i] = cos(qrm - two_pi_third);
cos_cs[i] = cos(qrm + two_pi_third);
}

// Set up 90 degree offset
deg90 = RESOLUTION/(2*P);

cursor(OFF);
printf("\n\nDacs: ");
wherexy(&col, &row);

// Enable Interrupt
EnableInterrupt(IO_XRPT); // enable IO update interrupt

// Runtime Loop
while(!kbd_hit())
{
inputfile = NULL;//initialize pointer
inputfile = fopen("datafile.txt","r");//open file here
// if (inputfile != NULL)//check if the file exist
// {
fscanf(inputfile,"%f", &Ii);//scan first data
fscanf(inputfile,"%f", &Hi);//scan second data
fclose(inputfile);//close file to reset the pointer...........

  • Determine where stdio.h is coming from.  Use the section titled #include File Search Paths in the C30 compiler manual to determine which directory contains stdio.h.  Is it the stdio.h that came with the compiler?  I suspect it isn't.  Because the stdio.h that comes with the compiler does define the type FILE.

    A related tip worth mentioning ... The printf family of functions, as supplied with the compiler, only work when executing under Code Composer Studio.  You can make printf work in your system.  Start by checking out the description of the RTS function add_device in the compiler manual.

    Thanks and regards,

    -George

  • Hi George,

    Thank you so much. I will track stdio.h to see if this will fix the problem. 

    Best regards,

    Wudi Zhou

  • Hi George,

    Now I no longer have the 'FILE' error. But when I compiled it said :

    >>symbol  _getchar multiply defined: getchar.obj <c:\m44\lib\target\stdio.lib> and fgetc.obj <c:\c3xtools\lib\rts40.lib>

    >>symbol  _fopen multiply defined: fopen.obj <c:\m44\lib\target\stdio.lib> and fopen.obj <c:\c3xtools\lib\rts40.lib>

    Seems getchar and fopen have been defined differently in those to .lib files. Do you have any advice for this situation?

    Thank you!

    Wudi 

  • This library stdio.lib is not from TI.  I recommend you carefully follow the documentation which comes with that library.  That should clear up these problems, including the earlier one with stdio.h.

    Thanks and regards,

    -George