Seeed Studio Grove Base for XIAO (SPI Solution) SUCCESS!

Hello There, Seeed_Seraphina… :smile:
Thank you for providing me the library and examples. However there was no Flash profile present for the W25Q80DV that was needed by SFUD_FLASH_CHIP_TABLE for any of the examples to work.
However, I was able after much trial and error , many cups of coffee and some minor epiphanies along the way. Discover the original "Serial Flash Universal Driver " library that the Seeed SFUD 1.0.0 version is based on, and has some hints on the configuration not in the Seeed Version.
I was able to add the lines to the necessary files, i.e the Type of flash installed/ called out does NOT support the SFUD_SFDP and will give errors if enabled by default.

{"W25Q80BV", SFUD_MF_ID_WINBOND, 0x40, 0x14, 8L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20},

the above was added to the Flash_chip_table. and some adds to the sfud_cfg header.
I’m attaching the same ARChive in Zip format with all the edits included and working with this Hardware.
grove_base_for_xiao-FLASH.zip (32.4 KB)

As a BONUS I was able to also unravel the mystery (at least to me) how the Xiao and Nordic map the SPI and QSPI interfaces as related to the NRF_SPIMx . and adafruit_SPIFlash.h WOW what a spin Cycle.
The Included Flash speed test verifies the operation of Both Onboard QSPI flash and The Expansion board SPI flash. (uncomment).Includes “flash_devices.h” with w25Q80dv added.
Sketch_grove_flash_speedTest.zip (5.8 KB)
Last item is Basic test to identify and check if flash works. with output and compiler info.

// 12/16/2023  Grove Expansion Board Flash Chip Test Code //
// // Adafruit_SPIFlash Example
// Author: PJG
//
//----------------------------------------------------------------------------------------------
// BSP : Seeed nRF52 Boards 1.1.1
// Board : Seeed XIAO nRF52840 Sense
//----------------------------------------------------------------------------------------------
// SdFat - Adafruit Fork@ 2.2.3
// Adafruit SPIFlash@ 4.1.3
// Adafruit TinyUSB [email protected]
//
// This tests and Identifies the Onboard Xiao QSPI Flash Chip 
// and Expansion Flash Chip on Grove Board Hardwired to A1/D1 (pin 1) on Xiao 
// for the Flash chipSelect CS or SS 
// Adafruit_SPIFlash is set with SPI class mthod. You can mix QSPI mode and SPI class are possible.
// The trick is the Nordic NRF_SPIM0, NRF_SPIM1, NRF_SPIM2, NRF_SPIM3 for which mode or method.
// HTH
// 

#include <Wire.h>
#include <SPI.h>
#include <SdFat.h>
#include <Adafruit_SPIFlash.h>

SPIFlash_Device_t const p25q16h {   // You can Declare the chip you choose this way or add it to the flash_devices
  // Configuration for W25Q80DV flash chip from the Data Sheet.
  .total_size = (1UL << 21), // 2MiB
  .start_up_time_us = 10000,
  .manufacturer_id = 0x85,
  .memory_type = 0x60,
  .capacity = 0x15,
  .max_clock_speed_mhz = 55,
  .quad_enable_bit_mask = 0x02,
  .has_sector_protection = 1,
  .supports_fast_read = 1,
  .supports_qspi = 1,
  .supports_qspi_writes = 1,
  .write_status_register_split = 1,
  .single_status_byte = 0,
  .is_fram = 0,
};
SPIFlash_Device_t const w25q80 {  // Also seemsto be case sensative lower case preferred
  // Configuration for W25Q80DV flash chip from the Data Sheet.
  .total_size = (1UL << 20), // 1MiB
  .start_up_time_us = 5000,
  .manufacturer_id = 0xEF,
  .memory_type = 0x40,
  .capacity = 0x14,
  .max_clock_speed_mhz = 104,
  .quad_enable_bit_mask = 0x02, 
  .has_sector_protection = 0,  
  .supports_fast_read = 1,     
  .supports_qspi = 1,           
  .supports_qspi_writes = 0,    
  .write_status_register_split = 0, 
  .single_status_byte = 0,     
  .is_fram = 0,                 
};

#define SS_SPI0 1  // seems to default to Pin 7 if you don't declare it as the CS for the Flash Chip A1/D1 pin1 on the Xiao
#define SS_SPI1 25

SPIClass SPI_2(NRF_SPIM0, PIN_QSPI_IO1, PIN_QSPI_SCK, PIN_QSPI_IO0); // Onboard QSPI Flash chip
Adafruit_FlashTransport_SPI QflashTransport(PIN_QSPI_CS, SPI_2);     // CS for QSPI Flash

Adafruit_SPIFlash Qflash(&QflashTransport);

SPIClass SPI_1(NRF_SPIM3, D9, D8, D10);   // MISO, SCK, MOSI /EXPANSION FLASH// CS pin D1 (hardwired)
Adafruit_FlashTransport_SPI EflashTransport(SS_SPI0, SPI_1);  // Flash Type

Adafruit_SPIFlash Eflash(&EflashTransport); 


void setup() {
  Serial.begin(9600);
  while (!Serial) delay(2100);
  
  Serial.println();
  Serial.println(" Program " __FILE__ " compiled on " __DATE__ " at " __TIME__ );
  Serial.println("----RESET----");
  pinMode(D6, INPUT_PULLUP);  // /WP
  pinMode(D7, INPUT_PULLUP);  // /HOLD
  pinMode(SS_SPI0, OUTPUT); // CS for flash
  digitalWrite(SS_SPI0, HIGH); // <-- Set CS pin HIGH to deselect
  
  Serial.println("--------------");
  Serial.println(SS_SPI0);
  Serial.println(MOSI); // master out, slave in
  Serial.println(MISO); // master in, slave out
  Serial.println(SCK);  // clock
  Serial.println("--------------");

  Serial.println("Onboard QSPI Flash Testing");
  Serial.println(F("QSPI Flash ID P25Q16H"));
   // Initialize QSPI flash library and check its chip ID.
 if (!Qflash.begin(&p25q16h, 1)) {
   Serial.println(F("Error, failed to initialize QSPI flash chip!"));
   while(1);
  }
  Serial.print(F("QFlash chip JEDEC ID: 0x")); Serial.println(Qflash.getJEDECID(), HEX);
  Serial.print(F("Flash size: ")); Serial.print(Qflash.size() / 1024); Serial.println(F(" KB"));
  Serial.println(F("QFlash chip successfully ID'd!"));
  delay (1500);
  Serial.println();
  Serial.println("Expansion Flash testing!!");
  digitalWrite(SS_SPI0, HIGH); // <-- Set CS pin HIGH to deselect
  Serial.println(F("SPI Flash ID W25Q80DV"));
   // Initialize W25Q80DV flash library and check its chip ID.
 if (!Eflash.begin(&w25q80)) {
   Serial.println(F("Error, failed to initialize W25Q80DV flash chip!"));
   while(1);
  }
  Serial.print(F("W25Q80DV chip JEDEC ID: 0x")); Serial.println(Eflash.getJEDECID(), HEX);
  Serial.print(F("Flash size: ")); Serial.print(Eflash.size() / 1024); Serial.println(F(" KB"));
  Serial.println(F("SPI Flash chip successfully ID'd!"));
  
}

void loop() {
//delay(500); // Your code here
}

compiler output.

Zip created at C:\Users\Dude\AppData\Local\Temp\arduino\sketches\A25B9D6E2C523EB8A1B4ECDC58048CC7/GroveFlash_Final.ino.zip

Using library Wire at version 1.0 in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\nrf52\1.1.1\libraries\Wire 
Using library SPI at version 1.0 in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\nrf52\1.1.1\libraries\SPI 
Using library SdFat - Adafruit Fork at version 2.2.3 in folder: D:\Arduino_projects\libraries\SdFat_-_Adafruit_Fork 
Using library Adafruit SPIFlash at version 4.1.3 in folder: D:\Arduino_projects\libraries\Adafruit_SPIFlash 
Using library Adafruit TinyUSB Library at version 1.7.0 in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\nrf52\1.1.1\libraries\Adafruit_TinyUSB_Arduino 
"C:\\Users\\Dude\\AppData\\Local\\Arduino15\\packages\\Seeeduino\\tools\\arm-none-eabi-gcc\\9-2019q4/bin/arm-none-eabi-size" -A "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\A25B9D6E2C523EB8A1B4ECDC58048CC7/GroveFlash_Final.ino.elf"
Sketch uses 56544 bytes (6%) of program storage space. Maximum is 811008 bytes.
Global variables use 7784 bytes (3%) of dynamic memory, leaving 229784 bytes for local variables. Maximum is 237568 bytes.
Performing 1200-bps touch reset on serial port COM12
Waiting for upload port...
Upload port found on COM6
"C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\nrf52\1.1.1/tools/adafruit-nrfutil/win32/adafruit-nrfutil.exe" --verbose dfu serial -pkg "C:\Users\Dude\AppData\Local\Temp\arduino\sketches\A25B9D6E2C523EB8A1B4ECDC58048CC7/GroveFlash_Final.ino.zip" -p COM6 -b 115200 --singlebank
Upgrading target on COM6 with DFU package C:\Users\Dude\AppData\Local\Temp\arduino\sketches\A25B9D6E2C523EB8A1B4ECDC58048CC7\GroveFlash_Final.ino.zip. Flow control is disabled, Single bank, Touch disabled
Opened serial port COM6
Starting DFU upgrade of type 4, SoftDevice size: 0, bootloader size: 0, application size: 56552
Sending DFU start packet
Sending DFU init packet
Sending firmware file
########################################
########################################
###############################
Activating new firmware

DFU upgrade took 3.736424684524536s
Device programmed.

Serial Output after reset…


 Program D:\Arduino_projects\GroveFlash_Final\GroveFlash_Final.ino compiled on Dec 17 2023 at 03:17:24
----RESET----
--------------
1
10
9
8
--------------
Onboard QSPI Flash Testing
QSPI Flash ID P25Q16H
QFlash chip JEDEC ID: 0x856015
Flash size: 2048 KB
QFlash chip successfully ID'd!

Expansion Flash testing!!
SPI Flash ID W25Q80DV
W25Q80DV chip JEDEC ID: 0xEF4014
Flash size: 1024 KB
SPI Flash chip successfully ID'd!

GroveFlash_Final.zip (1.8 KB)

HTH :+1:
AMA
GL :slight_smile: PJ