Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/SPIFlashIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,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
Expand All @@ -183,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) {
Expand Down Expand Up @@ -252,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
}

Expand Down
18 changes: 18 additions & 0 deletions src/SPIFramIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/SPIMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <salearj@hotmail.com> 02.03.17
#define _delay_us(us) delayMicroseconds(us)
#elif PLATFORM_ID == PLATFORM_BORON
#define _delay_us(us) delayMicroseconds(us)
#else
#include <util/delay.h>
#endif
Expand Down