SdFat: only try to use DMA if it is implemented

This commit is contained in:
Daniel Fekete 2017-06-13 17:19:42 +02:00
parent 21a856702b
commit 7b13128353
2 changed files with 6 additions and 3 deletions

View File

@ -4,6 +4,10 @@
#include <Arduino.h> #include <Arduino.h>
#include "stm32_gpio_af.h" #include "stm32_gpio_af.h"
#if defined(STM32F1) || defined(STM32F4)
#define SPI_HAS_OLD_DMATRANSFER
#endif
// SPI_HAS_TRANSACTION means SPI has // SPI_HAS_TRANSACTION means SPI has
// - beginTransaction() // - beginTransaction()
// - endTransaction() // - endTransaction()

View File

@ -19,7 +19,6 @@
*/ */
#if defined(ARDUINO_ARCH_STM32) #if defined(ARDUINO_ARCH_STM32)
#include "SdSpiDriver.h" #include "SdSpiDriver.h"
#define USE_STM32F1_DMAC 1
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
static SPIClass& pSpi = SPI; static SPIClass& pSpi = SPI;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -66,7 +65,7 @@ uint8_t SdSpiAltDriver::receive() {
*/ */
uint8_t SdSpiAltDriver::receive(uint8_t* buf, size_t n) { uint8_t SdSpiAltDriver::receive(uint8_t* buf, size_t n) {
int rtn = 0; int rtn = 0;
#if USE_STM32F1_DMAC #ifdef SPI_HAS_OLD_DMATRANSFER
rtn = pSpi.dmaTransfer(0, buf, n); rtn = pSpi.dmaTransfer(0, buf, n);
#else // USE_STM32F1_DMAC #else // USE_STM32F1_DMAC
// pSpi.read(buf, n); fails ?? use byte transfer // pSpi.read(buf, n); fails ?? use byte transfer
@ -91,7 +90,7 @@ void SdSpiAltDriver::send(uint8_t b) {
* \param[in] n Number of bytes to send. * \param[in] n Number of bytes to send.
*/ */
void SdSpiAltDriver::send(const uint8_t* buf , size_t n) { void SdSpiAltDriver::send(const uint8_t* buf , size_t n) {
#if USE_STM32F1_DMAC #ifdef SPI_HAS_OLD_DMATRANSFER
pSpi.dmaSend(const_cast<uint8_t*>(buf), n); pSpi.dmaSend(const_cast<uint8_t*>(buf), n);
#else // #if USE_STM32F1_DMAC #else // #if USE_STM32F1_DMAC
for (size_t i = 0; i < n; i++) { for (size_t i = 0; i < n; i++) {