/************************************************************************* * This demo uses the BAGuitar library to provide enhanced control of * the TGA Pro board. * * The latest copy of the BA Guitar library can be obtained from * https://github.com/Blackaddr/BAGuitar * * This demo will perform a DMA memory test on MEM0 attached * to SPI. * * NOTE: SPI MEM0 can be used by a Teensy 3.2/3.5/3.6. * pins. * */ #include #include "BAGuitar.h" using namespace BAGuitar; //#define SANITY #define DMA_SIZE 256 #define SPI_WRITE_CMD 0x2 #define SPI_READ_CMD 0x3 #define SPI_ADDR_2_MASK 0xFF0000 #define SPI_ADDR_2_SHIFT 16 #define SPI_ADDR_1_MASK 0x00FF00 #define SPI_ADDR_1_SHIFT 8 #define SPI_ADDR_0_MASK 0x0000FF SPISettings memSettings(20000000, MSBFIRST, SPI_MODE0); const int cs0pin = 15; BAGpio gpio; // access to User LED BASpiMemoryDMA spiMem0(SpiDeviceId::SPI_DEVICE0); bool compareBuffers(uint8_t *a, uint8_t *b, size_t numBytes) { bool pass=true; int errorCount = 0; for (size_t i=0; i(a), reinterpret_cast(b), sizeof(uint16_t)*numWords); } constexpr size_t TEST_END = SPI_MAX_ADDR; void setup() { Serial.begin(57600); while (!Serial) {} delay(5); Serial.println("Enabling SPI"); spiMem0.begin(); } bool spi8BitTest(void) { size_t spiAddress = 0; int spiPhase = 0; constexpr uint8_t MASK80 = 0xaa; constexpr uint8_t MASK81 = 0x55; uint8_t src8[DMA_SIZE]; uint8_t dest8[DMA_SIZE]; // Write to the memory using 8-bit transfers Serial.println("\nStarting 8-bit test Write/Read"); while (spiPhase < 4) { spiAddress = 0; while (spiAddress < TEST_END) { // fill the write data buffer switch (spiPhase) { case 0 : for (int i=0; i