c++cembeddedmsp432

Macro compiles in C but not in C++ (MSP432 BSL invocation)


I'm trying to invoke the BSL(bootloader) on a TI MSP432P401R device. The following macro gets compiled correctly in C, but fails when using C++, with the error "Too many arguments to function". What is the C++ preprocessor/compiler doing differently?

/******************************************************************************
* BSL                                                                         *
******************************************************************************/
#define BSL_DEFAULT_PARAM                        ((uint32_t)0xFC48FFFF)          /*!< I2C slave address = 0x48, Interface selection = Auto */
#define BSL_API_TABLE_ADDR                       ((uint32_t)0x00202000)          /*!< Address of BSL API table */
#define BSL_ENTRY_FUNCTION                       (*((uint32_t *)BSL_API_TABLE_ADDR))

#define BSL_AUTO_INTERFACE                       ((uint32_t)0x0000E0000)         /*!< Auto detect interface */
#define BSL_UART_INTERFACE                       ((uint32_t)0x0000C0000)         /*!< UART interface */
#define BSL_SPI_INTERFACE                        ((uint32_t)0x0000A0000)         /*!< SPI interface */
#define BSL_I2C_INTERFACE                        ((uint32_t)0x000080000)         /*!< I2C interface */

#define BSL_INVOKE(x)                            ((void (*)())BSL_ENTRY_FUNCTION)((uint32_t) x) /*!< Invoke the BSL with parameters */

int main()
{
    BSL_INVOKE(BSL_UART_INTERFACE);
}

Solution

  • In C, a function of type void f() means a function that accepts any parameter - this is obsolete style in C but still allowed.

    In C++, void f() means a function which is equivalent to void f(void), so you can't pass any parameter to it.

    You should not use this line in neither C nor C++:

    ((void (*)())BSL_ENTRY_FUNCTION)((uint32_t) x)
    

    Change it, as well as the function declaration, to:

    ((void (*)(uint32_t))BSL_ENTRY_FUNCTION)((uint32_t) x)