Invalid conversion from 'unsigned int' to 'PinName' when initialising SPI

I’m trying to write a library to carry out SPI communication using the Arduino Portenta H7 Lite. The SPI initialiser is complaining about the parameters, giving the error invalid conversion from 'unsigned int' to 'PinName' when initialising SPI, when I attempt to initialise it in my function below.

    void OV2640_portenta::init()

        /* set spi pins */

        spi = new SPI(PA_8, PA_10, PA_9, PA_7); // mosi, miso, sclk, ssel=NC

        spi->frequency(1000000); // 1MHz
        spi->format(8, 0); // bits, mode


The error persists if I use the numbers of the pins (ie SPI(D8, D10, D9, D7), or just numbers, which the PA_x values are enums for.

One fix I found here: suggests putting #undef __MBED__ in the file, which does work… but as mentioned in the github issue might cause problems down the line, and generally seems like a bit of a hacky fix.

Does anyone know what input I can provide to the function to make it work, and without having to undefine MBED?

Can you look at SPI capable pins on the board? I’ve checked the arrays mbed-os/PeripheralPins.c at master · ARMmbed/mbed-os · GitHub, and I can’t find the pins there (mosi pin PA_8 is not supported for instance).

That’s a good point! The board lists digital pins D7-D10 as SPI 1 interfaces - I’m not sure how the arduino pins will match up with the STM pins, so I’ll have to have a look at the datasheet for it. That said, I don’t think the issue is that it’s not a valid pin for SPI, the error looks more like it’s unhappy at the type passed into the function (i think)?

My hunch is that there’s some conflict between the Arduino SPI library and the mbed library

The PinName type is defined in the in the arduino15/packages/STMicroelectronics/hardware/stm32/2.3.0/cores/arduino/stm32/PinNames.h header file as:

typedef enum {
} PinName;

Considering Portenta H7 Pinout try to explicitly convert/cast int to enum type:

spi = new SPI(PinName(PC_3), PinName(PC_2), PinName(PI_1), PinName(PI_0)); // mosi, miso, sclk, ssel=NC
1 Like

Thank you! Can’t believe I didn’t spot that orange column on the datasheet…