lpcware

UART ROM example doesn't compile under C++ [SOLVED]

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by fjrg76 on Tue Dec 23 20:01:13 MST 2014
Hi everyone

Attempting to compile the "periph_uart_rom_polling" fails under C++. The example (as is) compiles ok under C. Nevertheless when I ported the code to a project in C++ then it fails to compile because of the "-fpermissive" flag.

../src/my_driver.cpp:137:89: error: invalid conversion from 'UART_HANDLE_T {aka void*}' to 'void**' [-fpermissive]


Let me post a striped version of the code so that we can focus in the issue:


/* UART handle and memory for ROM API */
static UART_HANDLE_T *uartHandle;

/* Use a buffer size larger than the expected return value of uart_get_mem_size() for the static UART handle type */
static uint32_t uartHandleMEM[0x10];

/* Setup UART handle and parameters */
static void setupUART()
{
uint32_t errCode;

/* 115.2KBPS, 8N1, ASYNC mode, no errors, clock filled in later */
UART_CONFIG_T cfg = {
0,/* U_PCLK frequency in Hz */
115200,/* Baud Rate in Hz */
1,/* 8N1 */
0,/* Asynchronous Mode */
NO_ERR_EN/* Enable No Errors */
};

/* Initialize UART0 */
Chip_UART_Init(LPC_USART0);

Chip_Clock_SetUARTFRGDivider(1);

/* Perform a sanity check on the storage allocation */
if (LPC_UARTD_API->uart_get_mem_size() > sizeof(uartHandleMEM)) {
/* Example only: this should never happen and probably isn't needed for most UART code. */
errorUART();
}

/* Setup the UART handle */
uartHandle = LPC_UARTD_API->uart_setup((uint32_t) LPC_USART0, (uint8_t *) &uartHandleMEM);
        // <---HERE IS THE ORIGINAL ERROR ...

//uartHandle = LPC_UARTD_API->uart_setup((uint32_t) LPC_USART0, (uint8_t *) uartHandleMEM);
        // SO, FOLLOWING THE LOGIC, I TRIED THESE

//uartHandle = LPC_UARTD_API->uart_setup((uint32_t) LPC_USART0, uartHandleMEM);
        // OTHER TWO LINES, BUT THE ERROR STILL EXISTS

        if (uartHandle == NULL) {
errorUART();
}

/* Need to tell UART ROM API function the current UART peripheral clock speed */
cfg.sys_clk_in_hz = Chip_Clock_GetSystemClockRate();

/* Initialize the UART with the configuration parameters */
errCode = LPC_UARTD_API->uart_init(uartHandle, &cfg);
if (errCode != LPC_OK) {
/* Some type of error handling here */
errorUART();
}
}


As the code shows, the uart_setup() callback is expecting, in the second argument, a pointer to uint_8, and in my two attempts I've sent what the callback expects, so I don't understand why the error reports:

error: invalid conversion from 'UART_HANDLE_T {aka void*}' to 'void**' [-fpermissive]


Maybe I'm overwatching something, but so far I cannot see any pointer to pointer. Besides, instead of

static uint32_t uartHandleMEM[0x10];


I've also used:

uint8_t uartHandleMEM[sizeof(uint32_t) * 16];


Right now I run out of ideas, so any help is welcomed. Thank you in advanced!

Outcomes