我刚开始使用 evk1105 dev.board。我需要将 printf() 重定向到 usart。我有以下代码(evk1105 的编辑 usart 示例):
#include <avr32/io.h>
#include "compiler.h"
#include "board.h"
#include "power_clocks_lib.h"
#include "gpio.h"
#include "usart.h"
#include "nmea.h"
#include <stdio.h>
/*! \name USART Settings
*/
//! @{
# define EXAMPLE_TARGET_PBACLK_FREQ_HZ FOSC0 // PBA clock target frequency, in Hz
#if BOARD == EVK1105
# define EXAMPLE_USART (&AVR32_USART0)
# define EXAMPLE_USART_RX_PIN AVR32_USART0_RXD_0_0_PIN
# define EXAMPLE_USART_RX_FUNCTION AVR32_USART0_RXD_0_0_FUNCTION
# define EXAMPLE_USART_TX_PIN AVR32_USART0_TXD_0_0_PIN
# define EXAMPLE_USART_TX_FUNCTION AVR32_USART0_TXD_0_0_FUNCTION
# define EXAMPLE_USART_CLOCK_MASK AVR32_USART0_CLK_PBA
# define EXAMPLE_PDCA_CLOCK_HSB AVR32_PDCA_CLK_HSB
# define EXAMPLE_PDCA_CLOCK_PB AVR32_PDCA_CLK_PBA
#endif
#if !defined(EXAMPLE_USART) || \
!defined(EXAMPLE_USART_RX_PIN) || \
!defined(EXAMPLE_USART_RX_FUNCTION) || \
!defined(EXAMPLE_USART_TX_PIN) || \
!defined(EXAMPLE_USART_TX_FUNCTION)
# error The USART configuration to use in this example is missing.
#endif
//! @}
#if UC3L
/*! \name Parameters to pcl_configure_clocks().
*/
//! @{
static scif_gclk_opt_t gc_dfllif_ref_opt = { SCIF_GCCTRL_SLOWCLOCK, 0, false };
static pcl_freq_param_t pcl_dfll_freq_param =
{
.main_clk_src = PCL_MC_DFLL0,
.cpu_f = EXAMPLE_TARGET_MCUCLK_FREQ_HZ,
.pba_f = EXAMPLE_TARGET_PBACLK_FREQ_HZ,
.pbb_f = EXAMPLE_TARGET_PBACLK_FREQ_HZ,
.dfll_f = EXAMPLE_TARGET_DFLL_FREQ_HZ,
.pextra_params = &gc_dfllif_ref_opt
};
//! @}
#endif
/* STIAN */
char nmea1[] ="$GPRMC,131637.000,V,5820.0658,N,00834.5652,E,0.00,,090911,,,A*69";
char nmea2[]="$GPRMC,131637.000,A,5820.0658,N,00834.5652,E,0.00,,090911,,,A*7E";
char nmea3[]="$GPRMC,131640.000,A,5820.0657,N,00834.5652,E,0.00,,090911,,,A*71";
char line [82];
char nmea[90];
/*END STIAN*/
int usart_get_return(volatile avr32_usart_t *usart)
{
int rx_char;
int retval = USART_SUCCESS;
int i = 0;
while (1)
{
rx_char = usart_getchar(usart);
if (rx_char == USART_FAILURE)
{
usart_write_line(usart, "Error!!!\r\n");
retval = USART_FAILURE;
break;
}
if (rx_char == '\x03')
{
retval = USART_FAILURE;
break;
}
usart_putchar(usart, rx_char);
nmea[i] = rx_char;
i++;
if (rx_char == '\r')
{ // Add a LF and consider this as the end of the line.
usart_putchar(usart, '\n');
break;
}
}
return retval;
}
int main(void)
{
pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);
static const gpio_map_t USART_GPIO_MAP =
{
{EXAMPLE_USART_RX_PIN, EXAMPLE_USART_RX_FUNCTION},
{EXAMPLE_USART_TX_PIN, EXAMPLE_USART_TX_FUNCTION}
};
// USART options.
static const usart_options_t USART_OPTIONS =
{
.baudrate = 57600,
.charlength = 8,
.paritytype = USART_NO_PARITY,
.stopbits = USART_1_STOPBIT,
.channelmode = USART_NORMAL_CHMODE
};
//set_usart_base( ( void * ) EXAMPLE_USART );
// Assign GPIO to USART.
gpio_enable_module(USART_GPIO_MAP,
sizeof(USART_GPIO_MAP) / sizeof(USART_GPIO_MAP[0]));
// Initialize USART in RS232 mode.
usart_init_rs232(EXAMPLE_USART, &USART_OPTIONS, EXAMPLE_TARGET_PBACLK_FREQ_HZ);
// Hello world!
usart_write_line(EXAMPLE_USART, "Polycon AIS-module! (press enter)\r\n");
// Press enter to continue.
while (usart_get_return(EXAMPLE_USART) == USART_FAILURE); // Get and echo characters until end of line.
printf("NMEA inneholder:%s\r\n",nmea);
while (usart_get_return(EXAMPLE_USART) == USART_FAILURE); // Get and echo characters until end of line.
usart_write_line(EXAMPLE_USART, "Goodbye.\r\n");
while (true);
}
添加 set_usart_base 时,我在implicit declaration of function 'set_usart_base'
此处找到以下编译错误 set_usart_base:avrfreaks.net
关于我做错了什么的任何提示?