Skip to content

Marlin SPI Review

Victor Oliveira edited this page Sep 20, 2020 · 11 revisions

Marlin SPI Review

Marlin born with a few peripheral using SPI. But now, we have a lot of concurrent devices sharing SPI.

For one SPI peripheral work, it needs prepare the spi device with ALL this parameters, before each spi usage:

  • SPI device
  • Speed
  • Bit Order
  • Data Mode

A lot of current Marlin code rely upon HAL to configure the SPI. But it leads to a problem: the current HAL code only handles ONE spi device at time. So, the client code must ensure that the SPI is properly configure before the use.

This review try to search for every spi usage to check if it's doing all the SPI setup before the use.

Marlin Core

Sd2Card.cpp - SD using SPI (~OK)

uses spiXXXX functions available in HAL call spiInit before use the spi

!!! rely on the spiInit to configure ALL spi paramenters for SD !!!

USB_FLASH_DRIVE_SUPPORT / MAX3421e (NOK)

uses spiXXXX functions available in HAL call spiBegin+spiInit ONLY ONCE in the init of the code

!!! don't call any begin or init to send/recv data !!!

Temperature sensor: MAX6675 (~OK)

uses spiXXXX functions available in HAL call spiBegin+spiInit before use the spi

!!! rely on the spiInit to configure ALL spi paramenters !!!

TFDI eve touch ui (~OK)

rely on the spiInit to configure the correct spi paramenters (media player)

use global SPI object. Have its own SPISettings instance and use beginTransaction. (good)

!!! rely on global SPI object to select the correct spi device !!!

LPC1768

u8g_com_HAL_LPC1768_hw_spi_fn (NOK)

uses spiXXXX functions available in HAL call spiBegin+spiInit ONLY ONCE in the init of the LCD setup

!!! don't call any begin or init to send data to LCD !!!

Libs

u8glib

TMCStepper

HAL status

As a lot of code rely upon spiInit function, here is the status of that function in each HAL.

!!! Note: the current spiXXXX functions ONLY works with ONE spi device !!!

STM32F1 (~OK)

spiInit function configure ALL spi parameters to the HAL default.

!!! problem: spiXXXX functions alter the SPI global object

LPC1768

Clone this wiki locally