Fix SPI, SD for BIGTREETECH SKR Mini (#14287)
This commit is contained in:
@ -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)
|
||||
|
@ -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
|
Reference in New Issue
Block a user