Skip to content

Instantly share code, notes, and snippets.

@phunanon phunanon/sketch.ino Secret
Created Jan 23, 2020

Embed
What would you like to do?
Non-working Adafruit SPIFlash configuration for Serpente R2
/*
* Print size, modify date/time, and name for all files in root.
*/
#include <SPI.h>
#include "SdFat.h"
#include "Adafruit_SPIFlash.h"
/*
#if defined(__SAMD51__) || defined(NRF52840_XXAA)
Adafruit_FlashTransport_QSPI flashTransport(PIN_QSPI_SCK, PIN_QSPI_CS, PIN_QSPI_IO0, PIN_QSPI_IO1, PIN_QSPI_IO2, PIN_QSPI_IO3);
#else
#if (SPI_INTERFACES_COUNT == 1 || defined(ADAFRUIT_CIRCUITPLAYGROUND_M0))
//Adafruit_FlashTransport_SPI flashTransport(SS, &SPI);
Adafruit_FlashTransport_SPI flashTransport(16, &SPI);
#else
//Adafruit_FlashTransport_SPI flashTransport(SS1, &SPI1);
#endif
#endif*/
#define SPI_INTERFACES_COUNT 2 // was 1
#define PIN_SPI_MISO (2ul) // PA06
#define PIN_SPI_MOSI (0ul) // PA04
#define PIN_SPI_SCK (1ul) // PA05
#define PERIPH_SPI sercom0
#define PAD_SPI_TX SPI_PAD_0_SCK_1
#define PAD_SPI_RX SERCOM_RX_PAD_2
// SPI FLASH
#define PIN_SPI1_MISO (12ul) // PA18 // D12 // PA18 FLASH_MISO // D12
#define PIN_SPI1_MOSI (11ul) // PA16 // D11 // PA16 FLASH_MOSI // D11
#define PIN_SPI1_SCK (9ul) // PA17 // D9 // PA17 FLASH_SCK // D9
#define PIN_SPI1_SS (10ul) // PA15 // D10 // PA15 FLASH_CS // D10
#define PERIPH_SPI1 sercom3 // serpente r2 schematic
#define PAD_SPI1_TX SPI_PAD_0_SCK_1 // tnr checked datasheet e18a: sercom3 pad 0
#define PAD_SPI1_RX SERCOM_RX_PAD_2 // tnr checked datasheet e18a: sercom3 pad 2
SPIClass mySPI = SPIClass(&PERIPH_SPI1, PIN_SPI1_MISO, PIN_SPI1_SCK, PIN_SPI1_MOSI, PAD_SPI1_TX, PAD_SPI1_RX);
Adafruit_FlashTransport_SPI flashTransport(PIN_SPI1_SS, &mySPI);
Adafruit_SPIFlash flash(&flashTransport);
// file system object from SdFat
FatFileSystem fatfs;
FatFile root;
FatFile file;
//------------------------------------------------------------------------------
void setup() {
Serial.begin(115200);
// Init external flash
flash.begin();
// Init file system on the flash
fatfs.begin(&flash);
// Wait for USB Serial
while (!Serial) {
SysCall::yield();
}
if (!root.open("/")) {
Serial.println("open root failed");
}
// Open next file in root.
// Warning, openNext starts at the current directory position
// so a rewind of the directory may be required.
while (file.openNext(&root, O_RDONLY)) {
file.printFileSize(&Serial);
Serial.write(' ');
file.printModifyDateTime(&Serial);
Serial.write(' ');
file.printName(&Serial);
if (file.isDir()) {
// Indicate a directory.
Serial.write('/');
}
Serial.println();
file.close();
}
if (root.getError()) {
Serial.println("openNext failed");
} else {
Serial.println("Done!");
}
}
//------------------------------------------------------------------------------
void loop() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.