From 86f6b541f09cad1f8e7890154b153491ec086da5 Mon Sep 17 00:00:00 2001 From: jacky4566 Date: Sat, 10 Aug 2019 14:35:25 -0600 Subject: [PATCH 1/2] Added SPI transaction settings for STM32 --- src/SPIFlashIO.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/SPIFlashIO.cpp b/src/SPIFlashIO.cpp index 7611c20..ae642ae 100644 --- a/src/SPIFlashIO.cpp +++ b/src/SPIFlashIO.cpp @@ -166,6 +166,14 @@ #if defined ENABLEZERODMA dma_init(); #endif + #elif defined (ARCH_STM32) + #ifdef SPI_HAS_TRANSACTION + _spi->beginTransaction(_settings); + #else + _spi->setClockDivider(SPI_CLOCK_DIV_4); + _spi->setDataMode(SPI_MODE0); + _spi->setBitOrder(MSBFIRST); + #endif #else #if defined (ARDUINO_ARCH_AVR) //save current SPI settings From 4dab11b60d0c8bb7c15c1df940eaea8e633a69f3 Mon Sep 17 00:00:00 2001 From: jacky4566 Date: Wed, 11 Mar 2020 14:09:22 -0600 Subject: [PATCH 2/2] Include functions for Particle Boron --- src/SPIFlashIO.cpp | 21 ++++++++++++++++++++- src/SPIFramIO.cpp | 18 ++++++++++++++++++ src/SPIMemory.h | 2 ++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/SPIFlashIO.cpp b/src/SPIFlashIO.cpp index 29f1439..b3e43fa 100644 --- a/src/SPIFlashIO.cpp +++ b/src/SPIFlashIO.cpp @@ -191,6 +191,23 @@ return true; } +uint16_t _transfer16Flash(uint16_t data) +{ + uint16_t retVal = 0; + // if endianness of both sides fits together + // SPI.transfer((uint8_t*)&data, (uint8_t*)&retVal, sizeof(data), NULL); + + // MSB before LSB + retVal |= SPI.transfer(data >> 8) << 8; + retVal |= SPI.transfer(data & 0x00FF); + + // LSB before MSB + // retVal |= SPI.transfer(data & 0x00FF); + // retVal |= SPI.transfer(data >> 8) << 8; + + return retVal; +} + //Initiates SPI operation - but data is not transferred yet. Always call _prep() before this function (especially when it involves writing or reading to/from an address) bool SPIFlash::_beginSPI(uint8_t opcode) { if (!SPIBusState) { @@ -260,8 +277,10 @@ uint16_t SPIFlash::_nextInt(uint16_t data) { #if defined (ARDUINO_ARCH_SAMD) return _spi->transfer16(data); +#elif PLATFORM_ID == PLATFORM_BORON + return _transfer16Flash(data); #else - return SPI.transfer16(data); + return _transfer16(data); #endif } diff --git a/src/SPIFramIO.cpp b/src/SPIFramIO.cpp index 859301c..cdaa5bf 100644 --- a/src/SPIFramIO.cpp +++ b/src/SPIFramIO.cpp @@ -192,10 +192,28 @@ #endif } +uint16_t _transfer16Fram(uint16_t data) +{ + uint16_t retVal = 0; + // if endianness of both sides fits together + // SPI.transfer((uint8_t*)&data, (uint8_t*)&retVal, sizeof(data), NULL); + + // MSB before LSB + retVal |= SPI.transfer(data >> 8) << 8; + retVal |= SPI.transfer(data & 0x00FF); + + // LSB before MSB + // retVal |= SPI.transfer(data & 0x00FF); + // retVal |= SPI.transfer(data >> 8) << 8; + + return retVal; +} //Reads/Writes next int. Call 'n' times to read/write 'n' number of integers. Should be called after _beginSPI() uint16_t SPIFram::_nextInt(uint16_t data) { #if defined (ARDUINO_ARCH_SAMD) return _spi->transfer16(data); +#elif PLATFORM_ID == PLATFORM_BORON + return _transfer16Fram(data); #else return SPI.transfer16(data); #endif diff --git a/src/SPIMemory.h b/src/SPIMemory.h index cd1fcd9..5a5b4cf 100644 --- a/src/SPIMemory.h +++ b/src/SPIMemory.h @@ -110,6 +110,8 @@ #if defined (ARDUINO_ARCH_SAM) || defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_ESP8266) || defined (SIMBLEE) || defined (ARDUINO_ARCH_ESP32) || defined (BOARD_RTL8195A) || defined(ARCH_STM32) || defined(ESP32) || defined(NRF52) // RTL8195A included - @boseji 02.03.17 #define _delay_us(us) delayMicroseconds(us) +#elif PLATFORM_ID == PLATFORM_BORON + #define _delay_us(us) delayMicroseconds(us) #else #include #endif