/************************************************************************* * This demo uses the BALibrary to provide enhanced control of * the TGA Pro board. * * The latest copy of the BALibrary can be obtained from * https://github.com/Blackaddr/BALibrary * * This demo will perform a DMA memory test on MEM1 attached * to SPI1. * * NOTE: SPI MEM1 can be used by a Teensy 3.5/3.6. * pins. * */ #include #include "BALibrary.h" using namespace BALibrary; //#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 spiMem1(SpiDeviceId::SPI_DEVICE1); 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, testing MEM1"); spiMem1.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