SPIflash on feather MO express

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
BernaFiesta
 
Posts: 2
Joined: Fri Jan 05, 2018 1:53 pm

SPIflash on feather MO express

Post by BernaFiesta »

Hello!
I'm stuck in a temperature/humidity/pressure experiment, because I can't format the SPIflash (I'd like to code with arduino ide)
The fafts_format doesn't work.. Maybe should I change something in the code? (I'm a beginner on electronic, so... I'm a bit lost)

Here is the code (and lower the answer, with error message):

Code: Select all

// Adafruit SPI Flash FatFs Format Example
// Author: Tony DiCola
//
// This will partition and format the SPI flash to have a new
// blank FAT filesystem.  This is useful for resetting the flash
// filesystem and erasing all the old data.  This is also a good
// example of using the low-level FatFs library functions directly
// instead of wrappers from this library.  See documentation on
// FatFs functions here:
//   http://elm-chan.org/fsw/ff/00index_e.html
//
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!  NOTE: YOU WILL ERASE ALL DATA BY RUNNING THIS SKETCH!  !!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//
// Usage:
// - Modify the pins and type of fatfs object in the config
//   section below if necessary (usually not necessary).
// - Upload this sketch to your M0 express board.
// - Open the serial monitor at 115200 baud.  You should see a
//   prompt to confirm formatting.  If you don't see the prompt
//   close the serial monitor, press the board reset buttton,
//   wait a few seconds, then open the serial monitor again.
// - Type OK and enter to confirm the format when prompted.
// - Partitioning and formatting will take about 30-60 seconds.
//   Once formatted a message will be printed to notify you that
//   it is finished.
//
#include <SPI.h>
#include <Adafruit_SPIFlash.h>
#include <Adafruit_SPIFlash_FatFs.h>

// Include the FatFs library header to use its low level functions
// directly.  Specifically the f_fdisk and f_mkfs functions are used
// to partition and create the filesystem.
#include "utility/ff.h"


// Configuration of the flash chip pins and flash fatfs object.
// You don't normally need to change these if using a Feather/Metro
// M0 express board.
#define FLASH_TYPE     SPIFLASHTYPE_W25Q16BV  // Flash chip type.
                                              // If you change this be
                                              // sure to change the fatfs
                                              // object type below to match.

#define FLASH_SS       SS1                    // Flash chip SS pin.
#define FLASH_SPI_PORT SPI1                   // What SPI port is Flash on?

Adafruit_SPIFlash flash(FLASH_SS, &FLASH_SPI_PORT);     // Use hardware SPI 

// Alternatively you can define and use non-SPI pins!
// Adafruit_SPIFlash flash(FLASH_SCK, FLASH_MISO, FLASH_MOSI, FLASH_SS);

Adafruit_W25Q16BV_FatFs fatfs(flash);


void setup() {
  // Initialize serial port and wait for it to open before continuing.
  Serial.begin(115200);
  while (!Serial) {
    delay(100);
  }
  Serial.println("Adafruit SPI Flash FatFs Format Example");

  // Initialize flash library and check its chip ID.
  if (!flash.begin(FLASH_TYPE)) {
    Serial.println("Error, failed to initialize flash chip!");
    while(1);
  }
  Serial.print("Flash chip JEDEC ID: 0x"); Serial.println(flash.GetJEDECID(), HEX);

  // Wait for user to send OK to continue.
  Serial.setTimeout(30000);  // Increase timeout to print message less frequently.
  do {
    Serial.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    Serial.println("This sketch will ERASE ALL DATA on the flash chip and format it with a new filesystem!");
    Serial.println("Type OK (all caps) and press enter to continue.");
    Serial.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  }
  while (!Serial.find("OK"));

  // Call fatfs activate to make it the active chip that receives low level fatfs
  // callbacks.  This is necessary before making any manual fatfs function calls
  // (like the f_fdisk and f_mkfs functions further below).  Be sure to call
  // activate before you call any fatfs functions yourself!
  fatfs.activate();

  // Partition the flash with 1 partition that takes the entire space.
  Serial.println("Partitioning flash with 1 primary partition...");
  DWORD plist[] = {100, 0, 0, 0};  // 1 primary partition with 100% of space.
  uint8_t buf[512] = {0};          // Working buffer for f_fdisk function.
  FRESULT r = f_fdisk(0, plist, buf);
  if (r != FR_OK) {
    Serial.print("Error, f_fdisk failed with error code: "); Serial.println(r, DEC);
    while(1);
  }
  Serial.println("Partitioned flash!");

  // Make filesystem.
  Serial.println("Creating and formatting FAT filesystem (this takes ~60 seconds)...");
  r = f_mkfs("", FM_ANY, 0, buf, sizeof(buf));
  if (r != FR_OK) {
    Serial.print("Error, f_mkfs failed with error code: "); Serial.println(r, DEC);
    while(1);
  }
  Serial.println("Formatted flash!");

  // Finally test that the filesystem can be mounted.
  if (!fatfs.begin()) {
    Serial.println("Error, failed to mount newly formatted filesystem!");
    while(1);
  }

  // Done!
  Serial.println("Flash chip successfully formatted with new empty filesystem!");
}

void loop() {
  // Nothing to be done in the main loop.
  delay(100);
}

And here is the answer:

Code: Select all

Adafruit SPI Flash FatFs Format Example
Flash chip JEDEC ID: 0x1401501
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
This sketch will ERASE ALL DATA on the flash chip and format it with a new filesystem!
Type OK (all caps) and press enter to continue.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Partitioning flash with 1 primary partition...
Couldn't read sector before performing write!
Error, f_fdisk failed with error code: 1
If someone could help, it would be great, thank you!
Last edited by danhalbert on Fri Jan 05, 2018 3:16 pm, edited 1 time in total.
Reason: added [CODE] tags

User avatar
danhalbert
 
Posts: 3483
Joined: Tue Aug 08, 2017 12:37 pm

Re: SPIflash on feather MO express

Post by danhalbert »

A recent code change broke this. We're working on a fix, but in the meantime, you can follow the instructions here to retrieve an older version of the formatting program: viewtopic.php?f=57&t=127244#p634694

User avatar
BernaFiesta
 
Posts: 2
Joined: Fri Jan 05, 2018 1:53 pm

Re: SPIflash on feather MO express

Post by BernaFiesta »

NICE! Thank you very much!!!

rogerthat
 
Posts: 13
Joined: Sun Mar 16, 2014 9:30 pm

Re: SPIflash on feather MO express

Post by rogerthat »

I have exactly the same problem with Feather M0-ATSAMD21+ATWINC1. I get the message:

Adafruit SPI Flash FatFs Format Example
Flash chip JEDEC ID: 0x0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
This sketch will ERASE ALL DATA on the flash chip and format it with a new filesystem!
Type OK (all caps) and press enter to continue.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Partitioning flash with 1 primary partition...
Couldn't erase sector before performing write!
Error, f_fdisk failed with error code: 1


I loaded the old 1.0.0 library as suggested in this post but no luck. Obviously erase also fails.

Need this fixed since we are porting from a teensy with EEPROM and we need some NVM variable storage. Thanks.

User avatar
danhalbert
 
Posts: 3483
Joined: Tue Aug 08, 2017 12:37 pm

Re: SPIflash on feather MO express

Post by danhalbert »

The Feather M0 WiFi - ATSAMD21 + ATWINC1500 does not have an external SPI flash chip, which is what that program is looking for. I'm not sure: are you trying to erase the internal flash on the SAMD21? Loading any Arduino program will do that as a side-effect.

rogerthat
 
Posts: 13
Joined: Sun Mar 16, 2014 9:30 pm

Re: SPIflash on feather MO express

Post by rogerthat »

OK. That explains that. Thanks for the quick reply. How do I read and write data to the SAMD21 ? I just need to save some configuration data between power up.

User avatar
danhalbert
 
Posts: 3483
Joined: Tue Aug 08, 2017 12:37 pm

Re: SPIflash on feather MO express

Post by danhalbert »

Are you using Arduino or CircuitPython?

rogerthat
 
Posts: 13
Joined: Sun Mar 16, 2014 9:30 pm

Re: SPIflash on feather MO express

Post by rogerthat »

Arduino

User avatar
danhalbert
 
Posts: 3483
Joined: Tue Aug 08, 2017 12:37 pm

Re: SPIflash on feather MO express

Post by danhalbert »

Check out this library, which will allow you use a section of flash as simulated EEPROM: https://github.com/cmaglie/FlashStorage. Study the README warnings about not wearing out the flash. This library is available in the Library Manager as "FlashStorage by Various".

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”