Use ESP-IDF functions (UART)

#1

Hi,

I want to use ESP-IDF functions for UART communication, but it doesn’t compiles. Here I attach the code:

main.c

#include "mgos.h"
#include "mgos_uart.h"
#include "mgos_timers.h"

#define UART_NO           1

#define UART_BUFFER_SIZE  1024

static void uart_init(void)

{

  uart_config_t uart_config = 

  {

    .baudrate = 9600,

    .data_bits = UART_DATA_8_BITS,

    .parity = UART_PARITY_DISABLE,

    .stop_bits = UART_STOP_BITS_1,

    .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,

  }

  /* Configure UART parameter */

  ESP_ERROR_CHECK(uart_param_config(UART_NO, &uart_config));

  /* Set UART pins(TX: IO26, RX: IO16, RTS: (DEFAULT), CTS: (DEFAULT)) */

  ESP_ERROR_CHECK(uart_set_pin(UART_NO, GPIO_NUM_26, GPIO_NUM_18, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));

  /* Install UART driver using an event queue here */

  ESP_ERROR_CHECK(uart_driver_install(UART_NO, UART_BUFFER_SIZE, UART_BUFFER_SIZE, 0, NULL, 0));

}

static void uart_handler_cb(void *arg)

{

  uint8_t rx_data[138];

  int lenght = 0;

  uint8_t *buff;

  uart_get_buffered_data_len(UART_NO, (size_t *)&lenght);

  lenght = uart_read_bytes(UART_NO, data, lenght, 10);

}

enum mgos_app_init(void)

{

  uart_init();

  LOG(LL_INFO,

      ("UART Initialized...", UART_NO));

  mgos_set_timer(1000 /* ms */, true /* repeat */, uart_handler_cb /* callback function */, NULL /* arg */);

}

mos.yml

# arch: PLATFORM
version: 1.0
manifest_version: 2017-05-18
author: mongoose-os
description: UART usage example in C/C++

libs_version: ${mos.version}
modules_version: ${mos.version}
mongoose_os_version: ${mos.version}

sources:
  - src
libs:
  - origin: https://github.com/mongoose-os-libs/boards

tags:
  - c
  - hw

What do I need to add to build the project?

ESP32 uart problems