Uart Library does not work on StartKIT

First time on the site? Say hello here!
jems
Member
Posts: 8
Joined: Tue Jun 25, 2019 1:23 pm

Uart Library does not work on StartKIT

Postby jems » Thu Jun 27, 2019 12:36 pm

Actually, I tested all the example which they had given into example folder but when I tried to compile/build into XMOS IDE it shows much error.
Even I added all the depended library for uart program running.
So, the error generated on the bulid up following,
../src/uart_new_one.xc: Error: Undefined reference to '__i_uart_rx_if_wait_for_data_and_read' (possible inline definition without external definition)
../src/uart_new_one.xc: Error: Undefined reference to '_i.input_gpio_if.input_gpio_1bit_with_events._c0.event_when_pins_eq'
../src/uart_new_one.xc: Error: Undefined reference to '_i.input_gpio_if.input_gpio_1bit_with_events._c0.input'
../src/uart_new_one.xc: Error: Undefined reference to '_i.input_gpio_if.input_gpio_1bit_with_events._c0.input_and_timestamp'
../src/uart_new_one.xc: Error: Undefined reference to '_i.output_gpio_if.output_gpio.0.output'
../src/uart_new_one.xc: Error: Undefined reference to '_i.output_gpio_if.output_gpio.0.output_and_timestamp'
../src/uart_new_one.xc: Error: Undefined reference to '_i.uart_tx_if.uart_tx.0.write'
../src/uart_new_one.xc: Error: Undefined reference to 'input_gpio_1bit_with_events'
../src/uart_new_one.xc: Error: Undefined reference to 'input_gpio_1bit_with_events.dynalloc_maxchanends'
../src/uart_new_one.xc: Error: Undefined reference to 'input_gpio_1bit_with_events.dynalloc_maxcores'
../src/uart_new_one.xc: Error: Undefined reference to 'input_gpio_1bit_with_events.dynalloc_maxtimers'
../src/uart_new_one.xc: Error: Undefined reference to 'input_gpio_1bit_with_events.fini'
../src/uart_new_one.xc: Error: Undefined reference to 'input_gpio_1bit_with_events.init.0'
../src/uart_new_one.xc: Error: Undefined reference to 'input_gpio_1bit_with_events.init.0.savedstate'
../src/uart_new_one.xc: Error: Undefined reference to 'input_gpio_1bit_with_events.init.1'
../src/uart_new_one.xc: Error: Undefined reference to 'input_gpio_1bit_with_events.select.enable'
../src/uart_new_one.xc: Error: Undefined reference to 'output_gpio'
../src/uart_new_one.xc: Error: Undefined reference to 'output_gpio.dynalloc_maxchanends'
../src/uart_new_one.xc: Error: Undefined reference to 'output_gpio.dynalloc_maxcores'
../src/uart_new_one.xc: Error: Undefined reference to 'output_gpio.dynalloc_maxtimers'
../src/uart_new_one.xc: Error: Undefined reference to 'output_gpio.init.0'
../src/uart_new_one.xc: Error: Undefined reference to 'output_gpio.init.0.savedstate'
../src/uart_new_one.xc: Error: Undefined reference to 'output_gpio.init.1'
../src/uart_new_one.xc: Error: Undefined reference to 'uart_rx'
../src/uart_new_one.xc: Error: Undefined reference to 'uart_rx.dynalloc_maxchanends'
../src/uart_new_one.xc: Error: Undefined reference to 'uart_rx.dynalloc_maxcores'
../src/uart_new_one.xc: Error: Undefined reference to 'uart_rx.dynalloc_maxtimers'
../src/uart_new_one.xc: Error: Undefined reference to 'uart_rx.fini'
../src/uart_new_one.xc: Error: Undefined reference to 'uart_rx.init.0'
../src/uart_new_one.xc: Error: Undefined reference to 'uart_rx.init.0.savedstate'
../src/uart_new_one.xc: Error: Undefined reference to 'uart_rx.init.1'
../src/uart_new_one.xc: Error: Undefined reference to 'uart_rx.select.enable'
../src/uart_new_one.xc: Error: Undefined reference to 'uart_tx'
../src/uart_new_one.xc: Error: Undefined reference to 'uart_tx.dynalloc_maxchanends'
../src/uart_new_one.xc: Error: Undefined reference to 'uart_tx.dynalloc_maxcores'
../src/uart_new_one.xc: Error: Undefined reference to 'uart_tx.dynalloc_maxtimers'
../src/uart_new_one.xc: Error: Undefined reference to 'uart_tx.init.0'
../src/uart_new_one.xc: Error: Undefined reference to 'uart_tx.init.0.savedstate'
../src/uart_new_one.xc: Error: Undefined reference to 'uart_tx.init.1
'

help me out this problem.
Even I tested one independent program it compiled perfectly but it gives wrong on UART port. So, i also post that program. So, tell me where actually mistake on the program or any other thing,

Code: Select all

#include <xs1.h>
#include <platform.h>
#include <stdlib.h>

#define BIT_RATE 115200
#define BIT_TIME XS1_TIMER_HZ / BIT_RATE

void txByte(unsigned char);
unsigned char rxByte(void);

//port RXD = XS1_PORT_1L;// X0D35  =>> 19 pin
//port TXD = XS1_PORT_1I;// X0D24  =>> 20 pin

port TXD = XS1_PORT_1L;// X0D35  =>> 19 pin
port RXD = XS1_PORT_1I;// X0D24  =>> 20 pin


unsigned char array[] = "I l you/n";

int main()
{
    //unsigned char c;
    int i;

    while (1)
    {
        //for (i = 0; i < 10; i++)
            //array[i] = rxByte();

        for (i = 0; i < 10; i++)
            txByte(array[i]);
    }

    return 0;
}

unsigned char rxByte(void)
{
   unsigned data = 0, time;
   int i;
   unsigned char c;

   // Wait for stop bit
   RXD when pinseq (1) :> int _;

   // wait for start bit
   RXD when pinseq (0) :> int _ @ time;
   time += BIT_TIME + (BIT_TIME >> 1);

   // sample each bit in the middle.
   for (i = 0; i < 8; i += 1)
   {
      RXD @ time :> >> data;
      time += BIT_TIME;
   }

   // reshuffle the data.
   c = (unsigned char) (data >> 24);

   return {c};
}

void txByte(unsigned char c)
{
   unsigned int time, data;

   data = (unsigned int)c;

   // get current time from port with force out.
   TXD <: 1 @ time;

   // Start bit.
   TXD <: 0;

   // Data bits.
   for (int i = 0; i < 8; i += 1)
   {
      time += BIT_TIME;
      TXD @ time <: >> data;
   }

   // two stop bits
   time += BIT_TIME;
   TXD @ time <: 1;
   time += BIT_TIME;
   TXD @ time <: 1;
}
I hope anyone helps me.
Thanks for advance.
CousinItt
XCore Addict
Posts: 138
Joined: Wed May 31, 2017 6:55 pm

Postby CousinItt » Thu Jun 27, 2019 3:14 pm

Try these:

1) #include <uart.h>

2) Make sure the makefile contains lib_uart in the USED_MODULES list

3) Open the lib_uart project (I sometimes have problems where xtimecomposer can't see uart.h)

4) Clean the project before building
jems
Member
Posts: 8
Joined: Tue Jun 25, 2019 1:23 pm

Postby jems » Fri Jun 28, 2019 12:27 pm

I already added all the library. But still, it shows this error. I tried four times but I do not think so this would be sorted my problem.
Any other suggestion for your side.
User avatar
mon2
XCore Legend
Posts: 1480
Joined: Thu Jun 10, 2010 11:43 am

Postby mon2 » Fri Jun 28, 2019 12:49 pm

Try the following:

1) start with a fresh workspace with the XMOS toolchain.

2) Select Examples button on LEFT side of the screen.

3) Go to StartKit examples -> select AN00175 -> double click to import this project into your workspace

4) Then after the import -> Select Edit button on LEFT side of the screen.

5) Select SRC inside your project folder tree -> double click the main.xc to edit this file

6) Select ALL -> delete the contents of this main.xc file.

7) Cut & Paste your code using the UART:

Code: Select all

// Copyright (c) 2016, XMOS Ltd, All rights reserved
#include <xs1.h>
#include <platform.h>
#include <stdlib.h>

#define BIT_RATE 115200
#define BIT_TIME XS1_TIMER_HZ / BIT_RATE

void txByte(unsigned char);
unsigned char rxByte(void);

//port RXD = XS1_PORT_1L;// X0D35  =>> 19 pin
//port TXD = XS1_PORT_1I;// X0D24  =>> 20 pin

port TXD = XS1_PORT_1L;// X0D35  =>> 19 pin
port RXD = XS1_PORT_1I;// X0D24  =>> 20 pin


unsigned char array[] = "I l you/n";

unsigned char rxByte(void)
{
   unsigned data = 0, time;
   int i;
   unsigned char c;

   // Wait for stop bit
   RXD when pinseq (1) :> int _;

   // wait for start bit
   RXD when pinseq (0) :> int _ @ time;
   time += BIT_TIME + (BIT_TIME >> 1);

   // sample each bit in the middle.
   for (i = 0; i < 8; i += 1)
   {
      RXD @ time :> >> data;
      time += BIT_TIME;
   }

   // reshuffle the data.
   c = (unsigned char) (data >> 24);

   return {c};
}

void txByte(unsigned char c)
{
   unsigned int time, data;

   data = (unsigned int)c;

   // get current time from port with force out.
   TXD <: 1 @ time;

   // Start bit.
   TXD <: 0;

   // Data bits.
   for (int i = 0; i < 8; i += 1)
   {
      time += BIT_TIME;
      TXD @ time <: >> data;
   }

   // two stop bits
   time += BIT_TIME;
   TXD @ time <: 1;
   time += BIT_TIME;
   TXD @ time <: 1;
}

int main(void) {
    //unsigned char c;
    int i;

    while (1)
    {
        //for (i = 0; i < 10; i++)
            //array[i] = rxByte();

        for (i = 0; i < 10; i++)
            txByte(array[i]);
    }

    return 0;

}
File -> Save / Save ALL

Compile using Project -> Build ALL.

Please try the above and post your results.
jems
Member
Posts: 8
Joined: Tue Jun 25, 2019 1:23 pm

Postby jems » Mon Jul 08, 2019 1:31 pm

Thanks for a reply now it is working perfectly without any problem.
Thank you.....

Who is online

Users browsing this forum: No registered users and 0 guests