Browse Source

Fix SPI, SD for BIGTREETECH SKR Mini (#14287)

pull/1/head
3DSmitty 6 years ago
committed by Scott Lahteine
parent
commit
66d51272af
  1. 47
      Marlin/src/HAL/HAL_STM32F1/HAL_spi_STM32F1.cpp
  2. 26
      Marlin/src/HAL/HAL_STM32F1/spi_pins.h
  3. 26
      Marlin/src/pins/pins_BIGTREE_SKR_MINI_V1_1.h

47
Marlin/src/HAL/HAL_STM32F1/HAL_spi_STM32F1.cpp

@ -36,20 +36,14 @@
// Includes // Includes
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#include "HAL.h" #include "../../inc/MarlinConfig.h"
#include "../shared/HAL_SPI.h"
#include "pins_arduino.h"
#include "spi_pins.h"
#include <SPI.h> #include <SPI.h>
#include "../../inc/MarlinConfigPre.h"
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Public Variables // Public Variables
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
static SPISettings spiConfig;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Public functions // Public functions
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -82,8 +76,7 @@ void spiBegin() {
#if !PIN_EXISTS(SS) #if !PIN_EXISTS(SS)
#error "SS_PIN not defined!" #error "SS_PIN not defined!"
#endif #endif
SET_OUTPUT(SS_PIN); OUT_WRITE(SS_PIN, HIGH);
WRITE(SS_PIN, HIGH);
} }
/** /**
@ -105,8 +98,11 @@ void spiInit(uint8_t spiRate) {
case SPI_SPEED_6: clock = SPI_CLOCK_DIV64; break; case SPI_SPEED_6: clock = SPI_CLOCK_DIV64; break;
default: clock = SPI_CLOCK_DIV2; // Default from the SPI library default: clock = SPI_CLOCK_DIV2; // Default from the SPI library
} }
spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0); SPI.setModule(SPI_DEVICE);
SPI.begin(); SPI.begin();
SPI.setClockDivider(clock);
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
} }
/** /**
@ -117,9 +113,9 @@ void spiInit(uint8_t spiRate) {
* @details * @details
*/ */
uint8_t spiRec(void) { uint8_t spiRec(void) {
SPI.beginTransaction(spiConfig); WRITE(SS_PIN, LOW);
uint8_t returnByte = SPI.transfer(0xFF); uint8_t returnByte = SPI.transfer(0xFF);
SPI.endTransaction(); WRITE(SS_PIN, HIGH);
return returnByte; return returnByte;
} }
@ -133,9 +129,9 @@ uint8_t spiRec(void) {
* @details Uses DMA * @details Uses DMA
*/ */
void spiRead(uint8_t* buf, uint16_t nbyte) { void spiRead(uint8_t* buf, uint16_t nbyte) {
SPI.beginTransaction(spiConfig); WRITE(SS_PIN, LOW);
SPI.dmaTransfer(0, const_cast<uint8_t*>(buf), nbyte); SPI.dmaTransfer(0, const_cast<uint8_t*>(buf), nbyte);
SPI.endTransaction(); WRITE(SS_PIN, HIGH);
} }
/** /**
@ -146,9 +142,9 @@ void spiRead(uint8_t* buf, uint16_t nbyte) {
* @details * @details
*/ */
void spiSend(uint8_t b) { void spiSend(uint8_t b) {
SPI.beginTransaction(spiConfig); WRITE(SS_PIN, LOW);
SPI.send(b); SPI.send(b);
SPI.endTransaction(); WRITE(SS_PIN, HIGH);
} }
/** /**
@ -160,25 +156,10 @@ void spiSend(uint8_t b) {
* @details Use DMA * @details Use DMA
*/ */
void spiSendBlock(uint8_t token, const uint8_t* buf) { void spiSendBlock(uint8_t token, const uint8_t* buf) {
SPI.beginTransaction(spiConfig); WRITE(SS_PIN, LOW);
SPI.send(token); SPI.send(token);
SPI.dmaSend(const_cast<uint8_t*>(buf), 512); SPI.dmaSend(const_cast<uint8_t*>(buf), 512);
SPI.endTransaction(); WRITE(SS_PIN, HIGH);
}
/**
* @brief Begin SPI transaction, set clock, bit order, data mode
*
* @param spiClock Clock setting
* @param bitOrder Bit Order setting
* @param dataMode Data Mode setting
* @return Nothing
*
* @details Uses an SPI Config via SPISettings
*/
void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) {
spiConfig = SPISettings(spiClock, (BitOrder)bitOrder, dataMode);
SPI.beginTransaction(spiConfig);
} }
#if ENABLED(SPI_EEPROM) #if ENABLED(SPI_EEPROM)

26
Marlin/src/HAL/HAL_STM32F1/spi_pins.h

@ -21,13 +21,29 @@
/** /**
* HAL for stm32duino.com based on Libmaple and compatible (STM32F1) * HAL for stm32duino.com based on Libmaple and compatible (STM32F1)
*/ */
/** /**
* Define SPI Pins: SCK, MISO, MOSI, SS * Define SPI Pins: SCK, MISO, MOSI, SS
* *
* Any PIN can be used for Chip Select (SS) * Any PIN can be used for Chip Select (SS)
*
* SPI1 is enabled by default
*/ */
#define SCK_PIN PA5 #if ENABLED(ENABLE_SPI3)
#define MISO_PIN PA6 #define SPI_DEVICE 3
#define MOSI_PIN PA7 #define SCK_PIN BOARD_SPI3_SCK_PIN
#define SS_PIN PA4 #define MISO_PIN BOARD_SPI3_MISO_PIN
#define MOSI_PIN BOARD_SPI3_MOSI_PIN
#define SS_PIN BOARD_SPI3_NSS_PIN
#elif ENABLED(ENABLE_SPI2)
#define SPI_DEVICE 2
#define SCK_PIN BOARD_SPI2_SCK_PIN
#define MISO_PIN BOARD_SPI2_MISO_PIN
#define MOSI_PIN BOARD_SPI2_MOSI_PIN
#define SS_PIN BOARD_SPI2_NSS_PIN
#else
#define SPI_DEVICE 1
#define SCK_PIN BOARD_SPI1_SCK_PIN
#define MISO_PIN BOARD_SPI1_MISO_PIN
#define MOSI_PIN BOARD_SPI1_MOSI_PIN
#define SS_PIN BOARD_SPI1_NSS_PIN
#endif

26
Marlin/src/pins/pins_BIGTREE_SKR_MINI_V1_1.h

@ -28,6 +28,9 @@
#define BOARD_NAME "BIGTREE SKR mini V1.1" #define BOARD_NAME "BIGTREE SKR mini V1.1"
#endif #endif
//#define DISABLE_DEBUG
#define DISABLE_JTAG
// Ignore temp readings during develpment. // Ignore temp readings during develpment.
//#define BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE //#define BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE
@ -89,14 +92,14 @@
// //
/** /**
* _____ _____ * _____ _____
* NC | · · | GND 5V | · · | GND * NC | · · | GND 5V | · · | GND
* RESET | · · | 1.31(SD_DETECT) (LCD_D7) 1.23 | · · | 1.22 (LCD_D6) * RESET | · · | PB9 (SD_DETECT) (LCD_D7) PC14 | · · | PC15 (LCD_D6)
* (MOSI)0.18 | · · | 3.25(BTN_EN2) (LCD_D5) 1.21 | · · | 1.20 (LCD_D4) * (MOSI) PB5 | · · | PB8 (BTN_EN2) (LCD_D5) PB7 | · · | PC13 (LCD_D4)
* (SD_SS)0.16 | · · | 3.26(BTN_EN1) (LCD_RS) 1.19 | · · | 1.18 (LCD_EN) * (SD_SS) PA15 | · · | PD2 (BTN_EN1) (LCD_RS) PC12 | · · | PB6 (LCD_EN)
* (SCK)0.15 | · · | 0.17(MISO) (BTN_ENC) 0.28 | · · | 1.30 (BEEPER) * (SCK) PB3 | · · | PB4 (MISO) (BTN_ENC) PC11 | · · | PC10 (BEEPER)
* *
* EXP2 EXP1 * EXP2 EXP1
*/ */
#if ENABLED(ULTRA_LCD) #if ENABLED(ULTRA_LCD)
@ -123,10 +126,13 @@
// SD Card // SD Card
// //
// Marlin uses the SD drive attached to the LCD // By default the onboard SD is enabled.
// To disable it and use an external SD (connected to LCD)
// enable STM32_SD_LCD.
//#define STM32_SD_LCD //#define STM32_SD_LCD
#ifdef STM32_SD_LCD #if ENABLED(STM32_SD_LCD)
#define SD_DETECT_PIN PB9 #define SD_DETECT_PIN PB9
#define ENABLE_SPI3 #define ENABLE_SPI3
#else #else

Loading…
Cancel
Save