/************************************************************************* * This demo uses the BALibrary to provide enhanced control of * the TGA Pro board. * * The latest copy of BALibrary can be obtained from * https://github.com/Blackaddr/BALibrary * * 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 "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 = SPI0_CS_PIN; 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); } size_t SPI_MAX_ADDR; void setup() { TGA_PRO_MKII_REV1(); // Declare the version of the TGA Pro you are using. //TGA_PRO_REVB(x); //TGA_PRO_REVA(x); gpio.begin(); Serial.begin(57600); while (!Serial) { yield(); } delay(5); SPI_MEM0_1M(); SPI_MAX_ADDR = BAHardwareConfig.getSpiMemMaxAddr(MemSelect::MEM0); Serial.printf("Enabling SPI, testing MEM0 up to addres %08X\n\r", SPI_MAX_ADDR); 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 <= SPI_MAX_ADDR) { // fill the write data buffer switch (spiPhase) { case 0 : for (int i=0; i