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

Hi,
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:


pins_2

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:

  • https://github.com/ArduPilot/PX4Firmware/blob/master/nuttx-configs/px4fmu-v4/include/board.h
    added:
#define GPIO_SPI4_MISO	(GPIO_SPI4_MISO_1|GPIO_SPEED_50MHz)
#define GPIO_SPI4_MOSI	(GPIO_SPI4_MOSI_1|GPIO_SPEED_50MHz)
#define GPIO_SPI4_SCK	(GPIO_SPI4_SCK_1|GPIO_SPEED_50MHz)
#define GPIO_SPI4_NSS	(GPIO_SPI4_NSS_1|GPIO_SPEED_50MHz)
#define GPIO_SPI4_CS_EXT    (GPIO_SPI_CS_EXT1|GPIO_SPEED_50MHz)
  • https://github.com/ArduPilot/PX4Firmware/blob/master/src/drivers/boards/px4fmu-v4/board_config.h
    added:
#define GPIO_SPI_CS_EXT0	(GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_SET|GPIO_PORTE|GPIO_PIN4)
#define GPIO_SPI_CS_EXT1	(GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_SET|GPIO_PORTC|GPIO_PIN14)
/* External bus */
#define PX4_SPIDEV_EXT0		1
#define PX4_SPIDEV_EXT1		2
  • https://github.com/ArduPilot/PX4Firmware/blob/master/src/drivers/boards/px4fmu-v4/px4fmu_init.c
    added:
static struct spi_dev_s *spi4;
spi4 = up_spiinitialize(4);
	SPI_SETFREQUENCY(spi4, 10000000);
	SPI_SETBITS(spi4, 8);
	SPI_SETMODE(spi4, SPIDEV_MODE3);
	SPI_SELECT(spi4, PX4_SPIDEV_EXT0, false);
	SPI_SELECT(spi4, PX4_SPIDEV_EXT1, false);
  • https://github.com/ArduPilot/PX4Firmware/blob/master/src/drivers/boards/px4fmu-v4/px4fmu_spi.c
    added:
#ifdef CONFIG_STM32_SPI4
	stm32_configgpio(GPIO_SPI_CS_EXT1);
	stm32_gpiowrite(GPIO_SPI_CS_EXT1, 1);
	stm32_configgpio(GPIO_SPI_CS_EXT0);
	stm32_gpiowrite(GPIO_SPI_CS_EXT0, 1);
#endif
__EXPORT uint8_t stm32_spi4status(FAR struct spi_dev_s *dev, enum spi_dev_e devid)
{
	return SPI_STATUS_PRESENT;
}

__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);
	default:
	        break;
	}
}
  • https://github.com/ArduPilot/ardupilot/blob/master/libraries/AP_HAL_PX4/HAL_PX4_Class.cpp#L68
    changed:
#define UARTF_DEFAULT_DEVICE "/dev/ttyS0" // wifi

to:

#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

Regards,
Ryan