This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Linker error when using some (but not all) UART functions in Zephyr

I am trying to use UART1 on nRF52840 to communicate with another device on  a custom board. I am using Zephyr. I have successfully compiled code using the function uart_poll_out() and that works for sending one character at a time. However, when I try to call the functions uart_callback_set() and uart_tx() to send several bytes at a time, I get the following linking errors at build time:

....../ncs/v1.3.0/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(main.c.obj): in function `main':
1> ......\build_nrf52840dk_nrf52840/../src/main.c:85: undefined reference to `uart_callback_set'
1> ....../ncs/v1.3.0/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(main.c.obj): in function `uart_tx':
1> ......\build_nrf52840dk_nrf52840/zephyr/include/generated/syscalls/uart.h:33: undefined reference to `z_impl_uart_tx'
1> collect2.exe: error: ld returned 1 exit status

The linker clearly can't find the functions uart_callback_set and z_impl_uart_tx, but I don't know what to do to make those functions available to the linker, especially since the function uart_poll_out does work. Code below:

/*
 * Copyright (c) 2015-2016 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr/types.h>
#include <stddef.h>
#include <errno.h>
#include <zephyr.h>
#include <sys/printk.h>

#include <device.h>
#include <gpio.h>
#include <uart.h>

#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/conn.h>
#include <bluetooth/uuid.h>
#include <bluetooth/gatt.h>
#include <sys/byteorder.h>

//this will serve as the link between BLE and WIFI modules
struct device* uart1dev;

void uartTXCallback(struct device *dev, struct uart_event evt, void *user_data){
//called after TX
}


bool sendAT(u32_t* buffer){
  //this is the function that will format the AT command and send it
  return true;
}

void main(void){

    uint8_t testBuffer[] = {'A','T','\r','\n'};
    size_t bufLen = sizeof(testBuffer);
    int32_t TXtimeout = 100;

    //set up UART1:
    uart1dev = device_get_binding(DT_LABEL(DT_NODELABEL(uart1)));

    uart_callback_set(uart1dev, uartTXCallback, NULL);
    while(1){
      uart_tx(uart1dev, testBuffer, bufLen, TXtimeout);
      //for(int i = 0; i<bufLen; ++i)
      //  uart_poll_out(uart1dev, testBuffer[i]);
      k_busy_wait(200000);
    }
}

Parents Reply Children
No Data
Related