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

Can't instantiate uart driver

Hello all,

I try to instantiate an uart driver using NRF_DRV_UART_INSTANCE macro, but I got the following error :

sdk/components/drivers_nrf/uart/nrf_drv_uart.h:97:1: error: invalid conversion from 'void*' to 'NRF_UARTE_Type*' [-fpermissive]
 }
 ^
drivers/uart.hpp:41:27: note: in expansion of macro 'NRF_DRV_UART_INSTANCE'
     nrf_drv_uart_t uart = NRF_DRV_UART_INSTANCE(0);
                           ^

bellow is my code :

#include "nrf_drv_uart.h"
#include "app_error.h"
#include "nrf.h"

void uartEventHandler(nrf_drv_uart_evt_type_t *p_event)
{}

void initUART()
{
    nrf_drv_uart_t uart = NRF_DRV_UART_INSTANCE(0);
    uint32_t err_code;
    nrf_drv_uart_config_t uart_cfg;

    uart_cfg.pseltxd=RX_PIN_NUMBER;
    uart_cfg.pselrxd=TX_PIN_NUMBER;
    uart_cfg.pselcts=RTS_PIN_NUMBER;
    uart_cfg.pselrts=CTS_PIN_NUMBER;
    uart_cfg.hwfc=UART_CONFIG_HWFC_Disabled;
    uart_cfg.parity=false;
    uart_cfg.baudrate=UART_BAUDRATE_BAUDRATE_Baud115200;
    uart_cfg.use_easy_dma = true;

    err_code = nrf_drv_uart_init(&uart, &uart_cfg, uartEventHandler);
    nrf_drv_uart_rx_enable(&uart_cfg);
}

thank you in advance for help ! there is my sdk config file : sdk_config.h my toolchain : arm-gcc-none-eabi-4.9-2015q3. my main.cpp file : main.cpp

  • hello again; I made a modification, I instantiate separatly the uart declaration and the instance index, as bellow :

    void initUART()
    {
        nrf_drv_uart_t uart_inst;
        uart_inst.drv_inst_idx = CONCAT_3(UART, 0, _INSTANCE_INDEX);
    
        uint32_t err_code;
        nrf_drv_uart_config_t uart_cfg=NRF_DRV_UART_DEFAULT_CONFIG;
    
        uart_cfg.pseltxd=RX_PIN_NUMBER;
        uart_cfg.pselrxd=TX_PIN_NUMBER;
        uart_cfg.pselcts=RTS_PIN_NUMBER;
        uart_cfg.pselrts=CTS_PIN_NUMBER;
        uart_cfg.hwfc=(nrf_uart_hwfc_t)UART_CONFIG_HWFC_Disabled;
        uart_cfg.parity=(nrf_uart_parity_t)false;
        uart_cfg.baudrate=(nrf_uart_baudrate_t)UART_BAUDRATE_BAUDRATE_Baud115200;
    
        err_code = nrf_drv_uart_init(&uart_inst, &uart_cfg, uartEventHandler);
        nrf_drv_uart_rx_enable(&uart_inst);
        APP_ERROR_CHECK(err_code);
    }
    

    That's compile, but i don't know that i made the right instantiation? o_O

  • You should do something like this:

    #include "nrf_drv_uart.h"
    
    const nrf_drv_uart_t uart = NRF_DRV_UART_INSTANCE(0);
    
    void uart_event_handler(nrf_drv_uart_event_t * p_event, void * p_context)
    {
    }
    
    void initUART()
    {
        uint32_t err_code;
        nrf_drv_uart_config_t uart_cfg;
    
        uart_cfg.pseltxd        = RX_PIN_NUMBER;
        uart_cfg.pselrxd        = TX_PIN_NUMBER;
        uart_cfg.pselcts        = RTS_PIN_NUMBER;
        uart_cfg.pselrts        = CTS_PIN_NUMBER;
        uart_cfg.hwfc           = NRF_UART_HWFC_DISABLED;
        uart_cfg.parity         = NRF_UART_PARITY_EXCLUDED;
        uart_cfg.baudrate       = NRF_UART_BAUDRATE_115200;
        uart_cfg.use_easy_dma   = true;
    
        err_code = nrf_drv_uart_init(&uart, &uart_cfg, uart_event_handler);
        APP_ERROR_CHECK(err_code);
        nrf_drv_uart_rx_enable(&uart);
    }
    
  • I tried this solution, but the error persist, I still have this error message :

    sdk/components/drivers_nrf/uart/nrf_drv_uart.h:97:1: error: invalid conversion from 'void*' to 'NRF_UARTE_Type*' [-fpermissive] } ^ drivers/uart.hpp:20:29: note: in expansion of macro 'NRF_DRV_UART_INSTANCE' const nrf_drv_uart_t uart = NRF_DRV_UART_INSTANCE(0);

Related