Cannot add custom libararies to main.c file in ESP IDF

sonysunny028
Posts: 1
Joined: Fri Oct 05, 2018 12:15 pm

Cannot add custom libararies to main.c file in ESP IDF

Postby sonysunny028 » Fri Oct 05, 2018 12:24 pm

Hi all,

I am working in a project where i need to add addtional libraries. I have made a custom uart.c and uart.h file. But unfortunately when i am building, it shows an error. The error is "Undefined reference to uart0_init();

Currently i am stuck in this project. Please help me.

main.c

Code: Select all

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/uart.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "uart.h"
#include "esp_log.h"
#include "freertos/queue.h"
#include <string.h>


static const char *TAG = "uart_events";


#define BUF_SIZE (1024)
#define PATTERN_CHR_NUM    (3)         /*!< Set the number of consecutive and identical characters received by receiver which defines a UART pattern*/
#define BUF_SIZE (1024)
#define RD_BUF_SIZE (BUF_SIZE)


void uart_event_task();
void uart_reception();


void app_main()
{
   esp_log_level_set(TAG, ESP_LOG_INFO);
   //uart1_intr_init(9600);
   uart0_init(57600);
   uart1_init(57600);
   uart2_intr_init(57600);
   esp_log_level_set(TAG, ESP_LOG_INFO);
   
}
uart.h

Code: Select all

#ifndef UART_HEADER_H
#define	UART_HEADER_H

//PIN CONFIG FOR UART0
#define ECHO_TEST_TXD_UART0  (UART_PIN_NO_CHANGE)
#define ECHO_TEST_RXD_UART0  (UART_PIN_NO_CHANGE)
#define ECHO_TEST_RTS_UART0  (UART_PIN_NO_CHANGE)
#define ECHO_TEST_CTS_UART0  (UART_PIN_NO_CHANGE)

//PIN CONFIG FOR UART1
#define ECHO_TEST_TXD_UART1  (GPIO_NUM_4)
#define ECHO_TEST_RXD_UART1  (GPIO_NUM_5)
#define ECHO_TEST_RTS_UART1  (UART_PIN_NO_CHANGE)
#define ECHO_TEST_CTS_UART1  (UART_PIN_NO_CHANGE)

//PIN CONFIG FOR UART2
#define ECHO_TEST_TXD_UART2  (GPIO_NUM_19)
#define ECHO_TEST_RXD_UART2  (GPIO_NUM_18)
#define ECHO_TEST_RTS_UART2  (UART_PIN_NO_CHANGE)
#define ECHO_TEST_CTS_UART2  (UART_PIN_NO_CHANGE)
#define BUF_SIZE (1024)

#define PATTERN_CHR_NUM    (3)         /*!< Set the number of consecutive and identical characters received by receiver which defines a UART pattern*/
#define BUF_SIZE (1024)


#ifdef	__cplusplus
extern "C" {
#endif

static QueueHandle_t uart0_queue;
static QueueHandle_t uart1_queue;
static QueueHandle_t uart2_queue;

void uart0_init(double baudrate);
void uart1_init(double baudrate);
void uart2_init(double baudrate);
static void echo_task_uart0();
static void echo_task_uart1();
static void echo_task_uart2();
void uart1_intr_init(int baudrate);
void uart2_intr_init(int baudrate);

#ifdef	__cplusplus
}
#endif
#endif
uart.c

Code: Select all

#include "driver/uart.h"
#include "uart1.h"

static QueueHandle_t uart0_queue;
static QueueHandle_t uart1_queue;
static QueueHandle_t uart2_queue;

//////////////////////////////////////////// UART0 INIT //////////////////////////////////////////////////////////////
void uart0_init(double baudrate)
{
    uart_config_t uart_config = {
        .baud_rate = baudrate,
        .data_bits = UART_DATA_8_BITS,
        .parity    = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE
    };
    uart_param_config(UART_NUM_0, &uart_config);
    //esp_log_level_set(TAG, ESP_LOG_INFO);          //Set UART log level
    uart_set_pin(UART_NUM_0, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
    uart_driver_install(UART_NUM_0, BUF_SIZE * 2, 0, 0, NULL, 0);
}
//////////////////////////////////////////// UART1 INIT //////////////////////////////////////////////////////////////
void uart1_init(double baudrate)
{
    uart_config_t uart_config = {
        .baud_rate = baudrate,
        .data_bits = UART_DATA_8_BITS,
        .parity    = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE
    };
    uart_param_config(UART_NUM_1, &uart_config);
    //esp_log_level_set(TAG, ESP_LOG_INFO);          //Set UART log level
    uart_set_pin(UART_NUM_1, ECHO_TEST_TXD_UART1, ECHO_TEST_RXD_UART1, ECHO_TEST_RTS_UART1, ECHO_TEST_CTS_UART1);
    uart_driver_install(UART_NUM_1, BUF_SIZE * 2, 0, 0, NULL, 0);
}
//////////////////////////////////////////// UART2 INIT //////////////////////////////////////////////////////////////
void uart2_init(double baudrate)
{
    uart_config_t uart_config = {
        .baud_rate = baudrate,
        .data_bits = UART_DATA_8_BITS,
        .parity    = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE
    };
    uart_param_config(UART_NUM_2, &uart_config);
    //esp_log_level_set(TAG, ESP_LOG_INFO);          //Set UART log level
    uart_set_pin(UART_NUM_2, ECHO_TEST_TXD_UART2, ECHO_TEST_RXD_UART2, ECHO_TEST_RTS_UART2, ECHO_TEST_CTS_UART2);
    uart_driver_install(UART_NUM_2, BUF_SIZE * 2, 0, 0, NULL, 0);
    
}
//////////////////////////////////////////// UART0 ECHO RECEPTION //////////////////////////////////////////////////////////////
static void echo_task_uart0()
{
    // Configure a temporary buffer for the incoming data
    uint8_t *data = (uint8_t *) malloc(BUF_SIZE);
    
    while (1) {
        // Read data from the UART
        int len = uart_read_bytes(UART_NUM_0, data, BUF_SIZE, 20 / portTICK_RATE_MS);
        // Write data back to the UART
        uart_write_bytes(UART_NUM_0, (const char *) data, len);
    }
}
//////////////////////////////////////////// UART1 ECHO RECEPTION //////////////////////////////////////////////////////////////
static void echo_task_uart1()
{
    // Configure a temporary buffer for the incoming data
    uint8_t *data = (uint8_t *) malloc(BUF_SIZE);
    
    while (1) {
        // Read data from the UART
        int len = uart_read_bytes(UART_NUM_1, data, BUF_SIZE, 20 / portTICK_RATE_MS);
        // Write data back to the UART
        uart_write_bytes(UART_NUM_1, (const char *) data, len);
    }
}
//////////////////////////////////////////// UART2 ECHO RECEPTION //////////////////////////////////////////////////////////////
static void echo_task_uart2()
{
    // Configure a temporary buffer for the incoming data 
    uint8_t *data = (uint8_t *) malloc(BUF_SIZE);
    while (1) {
        // Read data from the UART
        int len = uart_read_bytes(UART_NUM_2, data, BUF_SIZE, 20 / portTICK_RATE_MS);
        // Write data back to the UART
        uart_write_bytes(UART_NUM_2, (const char *) data, len);
    
    }
}
//////////////////////////////////////////// UART1 EVENT INIT //////////////////////////////////////////////////////////////
void uart1_intr_init(int baudrate){
    /* Configure parameters of an UART driver,
     * communication pins and install the driver */
    uart_config_t uart_config = {
        .baud_rate = 57600,
        .data_bits = UART_DATA_8_BITS,
        .parity = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE
    };
    uart_param_config(UART_NUM_1, &uart_config);

    //Set UART pins (using UART0 default pins ie no changes.)
    uart_set_pin(UART_NUM_1, ECHO_TEST_TXD_UART1, ECHO_TEST_RXD_UART1, ECHO_TEST_RTS_UART1, ECHO_TEST_CTS_UART1);
    //Install UART driver, and get the queue.
    uart_driver_install(UART_NUM_1, BUF_SIZE * 2, BUF_SIZE * 2, 20, &uart1_queue, 0);

    //Set uart pattern detect function.
    uart_enable_pattern_det_intr(UART_NUM_1, '+', PATTERN_CHR_NUM, 10000, 10, 10);
    //Reset the pattern queue length to record at most 20 pattern positions.
    uart_pattern_queue_reset(UART_NUM_1, 20);
}
//////////////////////////////////////////// UART2 EVENT INIT //////////////////////////////////////////////////////////////
void uart2_intr_init(int baudrate){
    /* Configure parameters of an UART driver,
     * communication pins and install the driver */
    uart_config_t uart_config = {
        .baud_rate = 57600,
        .data_bits = UART_DATA_8_BITS,
        .parity = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE
    };
    uart_param_config(UART_NUM_2, &uart_config);

    //Set UART pins (using UART0 default pins ie no changes.)
    uart_set_pin(UART_NUM_2, ECHO_TEST_TXD_UART2, ECHO_TEST_RXD_UART2, ECHO_TEST_RTS_UART2, ECHO_TEST_CTS_UART2);
    //Install UART driver, and get the queue.
    uart_driver_install(UART_NUM_2, BUF_SIZE * 2, BUF_SIZE * 2, 20, &uart2_queue, 0);

    //Set uart pattern detect function.
    uart_enable_pattern_det_intr(UART_NUM_2, '+', PATTERN_CHR_NUM, 10000, 10, 10);
    //Reset the pattern queue length to record at most 20 pattern positions.
    uart_pattern_queue_reset(UART_NUM_2, 20);
}


Who is online

Users browsing this forum: karunt and 87 guests