Configuring wi-fi port as SPI port in a Pixracer board

I’m working on a project to implement a TDoA location system using a UWB chip (DWM1000).
I’m using a Pixracer board but the DWM1000 is connected through the wi-fi port instead of the SPI port, as follows:


Now I’m trying to set the wi-fi port as it was set in the pixhawk (px4-v2) firmware but so far it doesn’t work.

Here’s a list of the changes I made:

/* External bus */
#define PX4_SPIDEV_EXT0		1
#define PX4_SPIDEV_EXT1		2
static struct spi_dev_s *spi4;
spi4 = up_spiinitialize(4);
	SPI_SETFREQUENCY(spi4, 10000000);
	SPI_SETBITS(spi4, 8);
	SPI_SELECT(spi4, PX4_SPIDEV_EXT0, false);
	SPI_SELECT(spi4, PX4_SPIDEV_EXT1, false);
#ifdef CONFIG_STM32_SPI4
	stm32_gpiowrite(GPIO_SPI_CS_EXT1, 1);
	stm32_gpiowrite(GPIO_SPI_CS_EXT0, 1);
__EXPORT uint8_t stm32_spi4status(FAR struct spi_dev_s *dev, enum spi_dev_e devid)

__EXPORT void stm32_spi4select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected)
	switch (devid) {
	case PX4_SPIDEV_EXT0:
	stm32_gpiowrite(GPIO_SPI_CS_EXT0, !selected);
	stm32_gpiowrite(GPIO_SPI_CS_EXT1, 1);
	case PX4_SPIDEV_EXT1:
	stm32_gpiowrite(GPIO_SPI_CS_EXT0, 1);
	stm32_gpiowrite(GPIO_SPI_CS_EXT1, !selected);
#define UARTF_DEFAULT_DEVICE "/dev/ttyS0" // wifi


#define UARTF_DEFAULT_DEVICE "/dev/null" // wifi

Please could you tell me if I did right so far and if I need to do something else?

Thank you very much.

@IDaniele this is quite an ambitious project!

I think you are on the right track with your changes. Trying to spot the error from your post is quite tricky though. What I can do is suggest some ways to debug this type of change.
The first thing you need is a logic analyser. I use a Saleae Pro8, but any decent logic analyser will do. Hook up the logic analyser to the pins you are setting up for SPI, but also hookup a couple of pins to general GPIO pins for debugging.
Then go methodically through your changes and use toggling of the debug pins to confirm which pieces of code are running. For example, toggle a GPIO pin quickly 4 times when you do the init of spi4, then confirm it is working as expected by looking at the trace.
Combined with the debug console and some printf() calls this should give you the ability to trace the execution of your code and find the issue.
Cheers, Tridge

As far as I understood you want to replace the UART port with a SPI port, correct? Did you enable SPI4 on Nuttx? Quickly checking it shows as disabled. See nuttx-configs/px4fmu-v4/nsh/defconfig:

# CONFIG_STM32_SPI4 is not set                                                                                                                                                                         

You may want to disable the correspondent uart port there as well (USART1). Instead of pasting the code here you can also push your changes to your repo… it makes it easier for review.

Hi @lucasdemarchi , thank you for helping me! :smile:
yes I noticed that CONFIG_STM32_SPI4 is not set, but I really couldn’t find where to change that.

Since there’s a line saying: "# Automatically generated file; DO NOT EDIT."
I thought defconfig wasn’t the place.

Sorry, I don’t understand if you told me to make the changes there or if that’s just where you checked.
If so, where should I edit?

Hi Danielle, have you been successful in your endeavors? I am actually trying to reassign the WIFI port of the pixracer as well!! Haha, help me/Save me