From 631f7da772c33da2b59345b2b986ae7f4f6b1c0b Mon Sep 17 00:00:00 2001 From: Blackaddr Audio Date: Fri, 11 Mar 2022 21:24:29 -0500 Subject: [PATCH] Fix revb issues (#17) * Add support for 64M memory * Fix startup PIN config issues with GPIO and DMA SPI * Fixup in BAGpio.pp * Updates some test files --- .../Tests/DMA_MEM0_test/DMA_MEM0_test.ino | 9 ++- .../Tests/DMA_MEM1_test/DMA_MEM1_test.ino | 8 ++- .../TGA_PRO_Basic_Test/TGA_PRO_Basic_Test.ino | 2 + src/BAGpio.h | 4 ++ src/BAHardware.h | 19 ++++-- src/peripherals/BAGpio.cpp | 14 ++-- src/peripherals/BASpiMemory.cpp | 68 ++++++++----------- 7 files changed, 70 insertions(+), 54 deletions(-) diff --git a/examples/Tests/DMA_MEM0_test/DMA_MEM0_test.ino b/examples/Tests/DMA_MEM0_test/DMA_MEM0_test.ino index 10edd02..244a60e 100644 --- a/examples/Tests/DMA_MEM0_test/DMA_MEM0_test.ino +++ b/examples/Tests/DMA_MEM0_test/DMA_MEM0_test.ino @@ -28,7 +28,7 @@ using namespace BALibrary; #define SPI_ADDR_1_SHIFT 8 #define SPI_ADDR_0_MASK 0x0000FF SPISettings memSettings(20000000, MSBFIRST, SPI_MODE0); -const int cs0pin = 15; +const int cs0pin = SPI0_CS_PIN; BAGpio gpio; // access to User LED BASpiMemoryDMA spiMem0(SpiDeviceId::SPI_DEVICE0); @@ -56,10 +56,15 @@ bool compareBuffers16(uint16_t *a, uint16_t *b, size_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); diff --git a/examples/Tests/DMA_MEM1_test/DMA_MEM1_test.ino b/examples/Tests/DMA_MEM1_test/DMA_MEM1_test.ino index 953e44a..17fc9ea 100644 --- a/examples/Tests/DMA_MEM1_test/DMA_MEM1_test.ino +++ b/examples/Tests/DMA_MEM1_test/DMA_MEM1_test.ino @@ -28,7 +28,7 @@ using namespace BALibrary; #define SPI_ADDR_1_SHIFT 8 #define SPI_ADDR_0_MASK 0x0000FF SPISettings memSettings(20000000, MSBFIRST, SPI_MODE0); -const int cs0pin = 15; +const int cs0pin = SPI1_CS_PIN; BAGpio gpio; // access to User LED BASpiMemoryDMA spiMem1(SpiDeviceId::SPI_DEVICE1); @@ -58,6 +58,12 @@ size_t SPI_MAX_ADDR = 0; 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); diff --git a/examples/Tests/TGA_PRO_Basic_Test/TGA_PRO_Basic_Test.ino b/examples/Tests/TGA_PRO_Basic_Test/TGA_PRO_Basic_Test.ino index 3b1fc55..6282873 100644 --- a/examples/Tests/TGA_PRO_Basic_Test/TGA_PRO_Basic_Test.ino +++ b/examples/Tests/TGA_PRO_Basic_Test/TGA_PRO_Basic_Test.ino @@ -90,6 +90,8 @@ void setup() { //TGA_PRO_REVB(x); //TGA_PRO_REVA(x); + gpio.begin(); + Serial.begin(57600); //while (!Serial) { yield(); } delay(500); diff --git a/src/BAGpio.h b/src/BAGpio.h index b038c3d..aae92f2 100644 --- a/src/BAGpio.h +++ b/src/BAGpio.h @@ -38,6 +38,10 @@ public: /// Construct a GPIO object for controlling the various GPIO and user pins BAGpio(); virtual ~BAGpio(); + + /// resets the configuration of the GPIO pins. Call this after to call the + /// hardware config macro. E.g. TGA_PRO_REVB(); + void begin(); /// Set the direction of the specified GPIO pin. /// @param gpioId Specify a GPIO pin such as GPIO::GPIO0 diff --git a/src/BAHardware.h b/src/BAHardware.h index befe8da..1fdf93f 100644 --- a/src/BAHardware.h +++ b/src/BAHardware.h @@ -61,7 +61,8 @@ enum class ExpansionBoard : unsigned { enum class SpiMemorySize : unsigned { NO_MEMORY = 0, ///< default, indicates no SPI memory installed MEM_1M, ///< indicates 1Mbit memory is installed - MEM_4M ///< indicates 4Mbit memory is installed + MEM_4M, ///< indicates 4Mbit memory is installed + MEM_64M ///< indicates 64Mbit memory is installed }; constexpr unsigned NUM_MEM_SLOTS = 2; ///< The TGA Pro has two SPI ports for memory @@ -81,6 +82,12 @@ struct SpiMemoryDefinition { size_t DIE_BOUNDARY; }; +/// Settings for 64Mbit SPI MEM +constexpr SpiMemoryDefinition SPI_MEMORY_64M = { + .MEM_SIZE_BYTES = 8388608, + .DIE_BOUNDARY = 0 +}; + /// Settings for 4Mbit SPI MEM constexpr SpiMemoryDefinition SPI_MEMORY_4M = { .MEM_SIZE_BYTES = 524288, @@ -201,10 +208,12 @@ extern BAHardware BAHardwareConfig; ///< external definition of global configura #define TGA_PRO_EXPAND_REV2(x) BALibrary::BAHardwareConfig.setExpansionBoard(ExpansionBoard::REV_2) ///< Macro for specifying REV 2 of the Expansion Board #define TGA_PRO_EXPAND_REV3(x) BALibrary::BAHardwareConfig.setExpansionBoard(ExpansionBoard::REV_3) ///< Macro for specifying REV 2 of the Expansion Board -#define SPI_MEM0_1M(x) BALibrary::BAHardwareConfig.set(MEM0, SPI_MEMORY_1M) ///< Macro for specifying MEM0 is 1Mbit -#define SPI_MEM0_4M(x) BALibrary::BAHardwareConfig.set(MEM0, SPI_MEMORY_4M) ///< Macro for specifying MEM1 is 4Mbit -#define SPI_MEM1_1M(x) BALibrary::BAHardwareConfig.set(MEM1, SPI_MEMORY_1M) ///< Macro for specifying MEM0 is 1Mbit -#define SPI_MEM1_4M(x) BALibrary::BAHardwareConfig.set(MEM1, SPI_MEMORY_4M) ///< Macro for specifying MEM1 is 1Mbit +#define SPI_MEM0_1M(x) BALibrary::BAHardwareConfig.set(MEM0, SPI_MEMORY_1M) ///< Macro for specifying MEM0 is 1Mbit +#define SPI_MEM0_4M(x) BALibrary::BAHardwareConfig.set(MEM0, SPI_MEMORY_4M) ///< Macro for specifying MEM0 is 4Mbit +#define SPI_MEM0_64M(x) BALibrary::BAHardwareConfig.set(MEM0, SPI_MEMORY_64M) ///< Macro for specifying MEM0 is 64Mbit +#define SPI_MEM1_1M(x) BALibrary::BAHardwareConfig.set(MEM1, SPI_MEMORY_1M) ///< Macro for specifying MEM1 is 1Mbit +#define SPI_MEM1_4M(x) BALibrary::BAHardwareConfig.set(MEM1, SPI_MEMORY_4M) ///< Macro for specifying MEM1 is 4Mbit +#define SPI_MEM1_64M(x) BALibrary::BAHardwareConfig.set(MEM1, SPI_MEMORY_64M) ///< Macro for specifying MEM1 is 64Mbit extern uint8_t USR_LED_ID; ///< Teensy IO number for the user LED. diff --git a/src/peripherals/BAGpio.cpp b/src/peripherals/BAGpio.cpp index 6f15e0e..5ef5866 100644 --- a/src/peripherals/BAGpio.cpp +++ b/src/peripherals/BAGpio.cpp @@ -24,6 +24,15 @@ namespace BALibrary { BAGpio::BAGpio() +{ + +} + +BAGpio::~BAGpio() +{ +} + +void BAGpio::begin() { // Set all GPIOs to input pinMode(GPIO0, INPUT); @@ -40,11 +49,6 @@ BAGpio::BAGpio() // Set the LED to ouput pinMode(USR_LED_ID, OUTPUT); clearLed(); // turn off the LED - -} - -BAGpio::~BAGpio() -{ } void BAGpio::setGPIODirection(GPIO gpioId, int direction) diff --git a/src/peripherals/BASpiMemory.cpp b/src/peripherals/BASpiMemory.cpp index 1c9e702..290a5b6 100644 --- a/src/peripherals/BASpiMemory.cpp +++ b/src/peripherals/BASpiMemory.cpp @@ -364,52 +364,15 @@ void BASpiMemory::m_rawRead16(size_t address, uint16_t *dest, size_t numWords) BASpiMemoryDMA::BASpiMemoryDMA(SpiDeviceId memDeviceId) : BASpiMemory(memDeviceId) { - int cs; - switch (memDeviceId) { - case SpiDeviceId::SPI_DEVICE0 : - cs = SPI0_CS_PIN; - m_cs = new ActiveLowChipSelect(cs, m_settings); - break; -#if defined(__MK66FX1M0__) - case SpiDeviceId::SPI_DEVICE1 : - cs = SPI1_CS_PIN; - m_cs = new ActiveLowChipSelect1(cs, m_settings); - break; -#endif - default : - cs = SPI0_CS_PIN; - } - - // add 4 bytes to buffer for SPI CMD and 3 bytes of address - m_txCommandBuffer = new uint8_t[CMD_ADDRESS_SIZE]; - m_rxCommandBuffer = new uint8_t[CMD_ADDRESS_SIZE]; - m_txTransfer = new DmaSpi::Transfer[2]; - m_rxTransfer = new DmaSpi::Transfer[2]; + m_memDeviceId = memDeviceId; + m_settings = {20000000, MSBFIRST, SPI_MODE0}; } BASpiMemoryDMA::BASpiMemoryDMA(SpiDeviceId memDeviceId, uint32_t speedHz) : BASpiMemory(memDeviceId, speedHz) { - int cs; - switch (memDeviceId) { - case SpiDeviceId::SPI_DEVICE0 : - cs = SPI0_CS_PIN; - m_cs = new ActiveLowChipSelect(cs, m_settings); - break; -#if defined(__MK66FX1M0__) - case SpiDeviceId::SPI_DEVICE1 : - cs = SPI1_CS_PIN; - m_cs = new ActiveLowChipSelect1(cs, m_settings); - break; -#endif - default : - cs = SPI0_CS_PIN; - } - - m_txCommandBuffer = new uint8_t[CMD_ADDRESS_SIZE]; - m_rxCommandBuffer = new uint8_t[CMD_ADDRESS_SIZE]; - m_txTransfer = new DmaSpi::Transfer[2]; - m_rxTransfer = new DmaSpi::Transfer[2]; + m_memDeviceId = memDeviceId; + m_settings = {20000000, MSBFIRST, SPI_MODE0}; } BASpiMemoryDMA::~BASpiMemoryDMA() @@ -431,6 +394,29 @@ void BASpiMemoryDMA::m_setSpiCmdAddr(int command, size_t address, uint8_t *dest) void BASpiMemoryDMA::begin(void) { + int cs; + switch (m_memDeviceId) { + case SpiDeviceId::SPI_DEVICE0 : + cs = SPI0_CS_PIN; + m_cs = new ActiveLowChipSelect(cs, m_settings); + break; +#if defined(__MK66FX1M0__) + case SpiDeviceId::SPI_DEVICE1 : + cs = SPI1_CS_PIN; + m_cs = new ActiveLowChipSelect1(cs, m_settings); + break; +#endif + default : + cs = SPI0_CS_PIN; + } + + // add 4 bytes to buffer for SPI CMD and 3 bytes of address + m_txCommandBuffer = new uint8_t[CMD_ADDRESS_SIZE]; + m_rxCommandBuffer = new uint8_t[CMD_ADDRESS_SIZE]; + m_txTransfer = new DmaSpi::Transfer[2]; + m_rxTransfer = new DmaSpi::Transfer[2]; + + switch (m_memDeviceId) { case SpiDeviceId::SPI_DEVICE0 : m_csPin = SPI0_CS_PIN;