Hello,
We've been developing nRF52 software for about two years. We develop on Linux desktop machines, and build with GCC from the command line interface.
I'm starting to bring our software into compliance with SDK 14.2.0. I've encountered a strange compiler error in a very simple UART program. I am simply trying to print "Hello world" over the USB to a terminal. Here is the code, mostly copied verbatim from Nordic example code:
#include <stdio.h>
#include "app_uart.h"
#include "boards.h"
static void uart_error_handler(app_uart_evt_t * p_event)
{
if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
APP_ERROR_HANDLER(p_event->data.error_communication);
else if (p_event->evt_type == APP_UART_FIFO_ERROR)
APP_ERROR_HANDLER(p_event->data.error_code);
}
ret_code_t uart_init(void)
{
ret_code_t err_code;
const app_uart_comm_params_t comm_params =
{
RX_PIN_NUMBER,
TX_PIN_NUMBER,
RTS_PIN_NUMBER,
CTS_PIN_NUMBER,
APP_UART_FLOW_CONTROL_ENABLED,
false,
UART_BAUDRATE_BAUDRATE_Baud115200
};
// Not using the FIFO.
APP_UART_INIT(&comm_params,
uart_error_handler,
APP_IRQ_PRIORITY_LOW,
err_code);
return err_code;
}
int main(void)
{
ret_code_t err_code;
err_code = uart_init();
if (err_code == NRF_SUCCESS)
puts("Hello world!\n");
return 0;
}
Here's what happens when I try to invoke GCC:
john@L:~/Documents/accel$ make
Compiling file: main.c
Linking target: _build/nrf52832_xxaa.out
_build/nrf52832_xxaa/main.c.o: In function `uart_init':
/home/john/Documents/accel/./main.c:41: undefined reference to `app_uart_init'
collect2: error: ld returned 1 exit status
/home/john/src/nRF5_SDK_14.2.0/components/toolchain/gcc/Makefile.common:292: recipe for target '_build/nrf52832_xxaa.out' failed
make: *** [_build/nrf52832_xxaa.out] Error 1
My code uses the APP_UART_INIT macro from app_uart.h. The macro decodes to a string which includes a call to app_uart_init, which is also defined in app_uart.h. I am clearly including the header correctly. If I had not, the macro itself would cause the error, rather than the function call inside it.
I don't show the Makefile, but I am compiling app_uart.c as well.
So why do I have an undefined reference? Any advice is greatly appreciated, thanks!