adafruit / Adafruit_SPIFlash

Arduino library for external (Q)SPI flash device
MIT License
159 stars 84 forks source link

Error : Couldn't write updated sector! #5

Closed ParameshChary closed 5 years ago

ParameshChary commented 6 years ago

flash :W25Q16BV Serial Monitor OP:

Adafruit SPI Flash FatFs Format Example Flash chip JEDEC ID: 0xEF Partitioning flash with 1 primary partition... Couldn't write updated sector! Error, f_fdisk failed with error code: 1

I am getting this error in fatfs format example.

dhalbert commented 6 years ago

What board is this on?

ParameshChary commented 6 years ago

MEGA2560

ParameshChary commented 6 years ago

my first example erase flash worked well but fatfs format not working . please suggest corrections any mistakes... Interfacing winbond W25Q16BV SPI CHIP with ARDUINO MEGA2560. thanking you.

dhalbert commented 6 years ago

The MEGA is a 5V board and the W25Q16BV is 2.7-3.6V. How are you doing level-shifting?

There may be software issues too - we've only tested this library in limited environments (SPI flash chips on our boards). We haven't tested it with AVR boards, just M0 and M4.

spmcn commented 6 years ago

I am having the same problem.

I'm using Model: ItsyBitsy M0 Express Board-ID: SAMD21G18A-ItsyBitsy-v0

When running fatfs_format, this is the serial console:

Adafruit SPI Flash FatFs Format Example
Flash chip JEDEC ID: 0xFFFFFFFF
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
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
spmcn commented 6 years ago

I thought it was odd that the JDEC ID is 0xFFFFFFFF . . .

ladyada commented 6 years ago

if you get no JEDEC it means the wiring/pinout isnt right. no ETA on when we'll get to this, the repo is undergoing a rewrite

spmcn commented 6 years ago

I solved it. Was trying to communicate with internal flash, and on the ItsyBitsy M0 Express, SPI_INTERFACES_COUNT equals 2, which is expected, so SS and SS1 should both be defined.

However, #if !defined(SS1) in the fatfs_format.ino example evaluates as TRUE, which means that the FLASH_SS and FLASH_SPI_PORT are incorrect when trying to communicate with the internal flash. In fact, I checked if if SS1 is defined by printing to the serial, and I did in fact get a value (39 to be specific).

So the error is with the #if !defined(SS1) statement.

A temporary fix was just to comment the #if statement, but I want to make you guys aware that there's an error here.

martianzero commented 5 years ago

I have the same on a feather express M0, would this be the way to fix the code?:

total novice here...

//#if !defined(SS1) // #define FLASH_SS SS // Flash chip SS pin. // #define FLASH_SPI_PORT SPI // What SPI port is Flash on? // #define NEOPIN 8 //#else

define FLASH_SS SS1 // Flash chip SS pin.

define FLASH_SPI_PORT SPI1 // What SPI port is Flash on?

define NEOPIN 40

//#endif

rickpetersoniot commented 5 years ago

I tried martianzero code and it appears to have fixed the issue I was having with a new Feather M0 Express board. I no longer get JDEC ID is 0xFFFFFFFF, it now has a real value. I am having the same type of problem with an ItsyBitsy M4 Express board. I will try the same workaround and report back.

The Feather M0 Express documentation says the NeoPixel is connected to pin #8 in Arduino; so, I think the following edit is also required:

//#if !defined(SS1)
// #define FLASH_SS SS // Flash chip SS pin.
// #define FLASH_SPI_PORT SPI // What SPI port is Flash on?
#define NEOPIN 8
//#else
#define FLASH_SS SS1 // Flash chip SS pin.
#define FLASH_SPI_PORT SPI1 // What SPI port is Flash on?
//#define NEOPIN 40
//#endif
lfg6000 commented 5 years ago

These values work for the ItsyBitsy M0. You will get a valid JDEC ID.

define FLASH_SS SS1 // Flash chip SS pin.

define FLASH_SPI_PORT SPI1 // What SPI port is Flash on?

define NEOPIN 40

smarpug commented 5 years ago

I tried both rickpetersoniont's and lfg6000's versions on my ItsyBitsy M0 Express and both worked. I'm not sure the NEOPIN value is even used. The NeoPixel looks like it is pin 5 on the ItsyBitsy M0 express.

Ing-Dom commented 5 years ago

I don't get it working on my Itsy Bitsy M0 Express with the changes proposed by Ifg6000:

define FLASH_SS SS1 // Flash chip SS pin.

define FLASH_SPI_PORT SPI1 // What SPI port is Flash on?

define NEOPIN 40

=>

21:52:46.345 -> Adafruit Express CircuitPython Flash Repair 21:52:46.345 -> Flash chip JEDEC ID: 0x0 21:52:46.345 -> Error, failed to initialize flash chip!

ladyada commented 5 years ago

latest version has fixed the SS1 detection - not sure how it even worked before but it should now! please try it, and re-open if you still have an issue!