Hi,
I am trying to override SPI_HOWMANY (by default 1) to 2 in a rp2040 project. I do this on the platformio.ini as:
-D SPI_HOWMANY=2
But it’s not working. If I want to use SPI1, I must change the file arduino_pins.h. If not, it gives me an error.
lib/hal/scr_spi_hal.h:44:28: error: ‘SPI1’ was not declared in this scope; did you mean ‘SPI’?
44 | inline SPIHal spi_hal_aux(&SPI1);
Assuming we are talking about the Arduino-Pico core (Earlephilhower), then
Redefining SPI_HOWMANY is wrong because it’s hardcoded per board, based on which SPI pins are actually available on the board. If you find yourself that you should have a second SPI but the board doesn’t define it, you found a bug. You should file it. The other possibility is that you’re using the wrong board. The most generic board = rpipico has both SPIs available
The SPI libary will refuse to create a second SPI object if you don’t also define its other dependencies.
You can also create the object yourself independently and use it.
#include "SPI.h"
#include <hardware/spi.h>
/* can also be named differently */
#define MY_SPI_MISO 8 /* or 12, 24, 28 */
#define MY_SPI_SS 9 /* or 13, 25, 29 */
#define MY_SPI_SCK 10 /* or 14, 26 */
#define MY_SPI_MOSI 11 /* or 15, 27 */
SPIClassRP2040 SPI1(spi1, MY_SPI_MISO, MY_SPI_SS, MY_SPI_SCK, MY_SPI_MOSI);