unknown type name 'FILE'

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hallo Leute,

ich versuche mein UART mit printf einzubinden. Leider meldet es das der Type 'FILE' nicht findet, trotz das STDIO.h eingebunden ist.

 

Habt ihr eine Idee wo mein Fehler liegt?

 

------------------------------ ENGLISH -------------------------------------------

Hi guys,
I try to include my UART with printf. Unfortunately it reports that the type 'FILE' is not found, although STDIO.h is included.

 

Do you have any idea where my error is?

 

UART.h

#ifndef UART_H_
#define UART_H_

#ifndef BAUD
#define BAUD 19200
#endif

void UART_Init(void);
int uartPutChar(char data, FILE *stream);
char uartGetChar(void);
//void uartPutString(const char *buffer);

#endif /* UART_H_ */

UART.c

#include <avr/io.h>
#include <avr/iom32.h>
#include <stdlib.h>
#include <stdio.h>
#include "Clock.h"
#include "UART.h"

FILE mystdout = FDEV_SETUP_STREAM( uartPutChar, NULL, _FDEV_SETUP_WRITE );

void UART_Init()
{
	UCSRB |= _BV(3); 	// TX aktiv
	UCSRB |= _BV(4); 	// RX aktivieren
	UBRRL=(uint8_t)(F_CPU/(BAUD*16L))-1; 	// Baudrate festlegen
	UBRRH=(uint8_t)((F_CPU/(BAUD*16L))-1)>>8; 	// Baudrate festlegen	
	stdout = &mystdout;
}


//----------------------------------------------------------------------
// Titel 	: C-Funktion Zeichen zu UART senden.
//----------------------------------------------------------------------
// Funktion 	: ...
// IN  	 	: char data
// OUT 	 	: ...
//----------------------------------------------------------------------
int uartPutChar(char data, FILE *stream)
{
	////warte bis UDR leer ist UCSRA / USR bei z.B.: 2313
	//while (!(UCSRA&32));
	////sende
	//UDR=data;
	
	
	if( data == '\n' )
	uartPutChar( '\r', stream );

	while (!(UCSRA&32));
	UDR = data;
	return 0;
}

//----------------------------------------------------------------------
// Titel 	: C-Funktion Zeichen von UART holen.
//----------------------------------------------------------------------
// Funktion 	: ...
// IN  	 	: ...
// OUT 	 	: data
//----------------------------------------------------------------------
char uartGetChar()
{
	char data=0;
	//warte bis RX-complete RXC UCSRA / USR bei z.B.: AT090S2313
	while (!(UCSRA&128));
	//empfangen
	data=UDR;
	return data;
}
//----------------------------------------------------------------------
// Titel 	: C-Funktion Zeichenkette zu UART senden.
//----------------------------------------------------------------------
// Funktion 	: ...
// IN  	 	: char *buffer, Zeichenkette mit NUll abgeschlossen
// OUT 	 	: ...
//----------------------------------------------------------------------
//void uartPutString(const char *buffer)
//{
	//for (int i=0; buffer[i] !=0;i++)
	//uartPutChar(buffer[i]);
//}

 

This topic has a solution.
Last Edited: Thu. Jun 2, 2022 - 09:19 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hmmm Your code compiles for me.  (After removing the Clock.h line of course)

 

BTW:

Because UART.h itself has a dependency on FILE then you should #include <stdio.h> within UART.h also.

 

BTWII:

#include <avr/io.h>
#include <avr/iom32.h> /* This line is redundant. It should not appear. */

 

Last Edited: Tue. May 31, 2022 - 11:39 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

FILE and for that matter FDEV_SETUP_STREAM are in <stdio.h > so that needs to be included in any file that references those things. 

 

Bottom line. Move your include of stdio.h from UART.c to UART.h (and the same for anything else that appears in UART.h, it needs to be "self supporting" 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Ahhhh. Thank you.

 

Kind of makes sense.

Last Edited: Tue. May 31, 2022 - 02:05 PM