Implicit declaration of function when using set_usart_base((void *)) EVK1105 dev. board. Atmel

1.7k views Asked by At

I've just started with the evk1105 dev.board. and i need to get printf() redirected to usart. I have the following code (edited usart example for evk1105):

#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);
}

When adding set_usart_base I get the following compile error implicit declaration of function 'set_usart_base' set_usart_base found here: avrfreaks.net

Any hints on what I'm doing wrong?

1

There are 1 answers

1
Adriano Repetti On

Instead of this:

set_usart_base( ( void * ) EXAMPLE_USART );

use this:

extern volatile avr32_usart_t *volatile stdio_usart_base;
stdio_usart_base = EXAMPLE_USART;

Declaration to use may be:

extern volatile struct avr32_usart_t *volatile stdio_usart_base;

Take a look to: http://support.atmel.no/knowledgebase/avr32studiohelp/AT32UC3B_Software_Framework/SERVICES/USB/CLASS/HID/EXAMPLES/HID_EXAMPLE_STANDALONE/DOC/html/a00045.html#l00171