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

This commit is contained in:
3DSmitty 2019-06-15 19:12:05 -04:00 committed by Scott Lahteine
parent 903863dcb6
commit 66d51272af
3 changed files with 51 additions and 48 deletions

View file

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

View file

@ -21,13 +21,29 @@
/**
* HAL for stm32duino.com based on Libmaple and compatible (STM32F1)
*/
/**
* Define SPI Pins: SCK, MISO, MOSI, SS
*
* Any PIN can be used for Chip Select (SS)
*
* SPI1 is enabled by default
*/
#define SCK_PIN PA5
#define MISO_PIN PA6
#define MOSI_PIN PA7
#define SS_PIN PA4
#if ENABLED(ENABLE_SPI3)
#define SPI_DEVICE 3
#define SCK_PIN BOARD_SPI3_SCK_PIN
#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

View file

@ -28,6 +28,9 @@
#define BOARD_NAME "BIGTREE SKR mini V1.1"
#endif
//#define DISABLE_DEBUG
#define DISABLE_JTAG
// Ignore temp readings during develpment.
//#define BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE
@ -91,11 +94,11 @@
/**
* _____ _____
* NC | · · | GND 5V | · · | GND
* RESET | · · | 1.31(SD_DETECT) (LCD_D7) 1.23 | · · | 1.22 (LCD_D6)
* (MOSI)0.18 | · · | 3.25(BTN_EN2) (LCD_D5) 1.21 | · · | 1.20 (LCD_D4)
* (SD_SS)0.16 | · · | 3.26(BTN_EN1) (LCD_RS) 1.19 | · · | 1.18 (LCD_EN)
* (SCK)0.15 | · · | 0.17(MISO) (BTN_ENC) 0.28 | · · | 1.30 (BEEPER)
*
* RESET | · · | PB9 (SD_DETECT) (LCD_D7) PC14 | · · | PC15 (LCD_D6)
* (MOSI) PB5 | · · | PB8 (BTN_EN2) (LCD_D5) PB7 | · · | PC13 (LCD_D4)
* (SD_SS) PA15 | · · | PD2 (BTN_EN1) (LCD_RS) PC12 | · · | PB6 (LCD_EN)
* (SCK) PB3 | · · | PB4 (MISO) (BTN_ENC) PC11 | · · | PC10 (BEEPER)
*
* EXP2 EXP1
*/
@ -123,10 +126,13 @@
// 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
#ifdef STM32_SD_LCD
#if ENABLED(STM32_SD_LCD)
#define SD_DETECT_PIN PB9
#define ENABLE_SPI3
#else