Author Topic: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes  (Read 2951 times)

0 Members and 1 Guest are viewing this topic.

Offline peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 3993
  • Country: gb
  • Doing electronics since the 1960s...
Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« on: August 05, 2024, 08:01:35 pm »
I have this in the production test and config.

Currently it is taking 120 seconds. There are 8192 blocks and each one takes 15ms (with pre-erase).

I am looking for a way to speed this up a lot because it is a bit of a bottleneck if you are processing say 100 boards.

There is a device erase command (45s typ.) but that sets it to 0xff. But then you can use the block write without pre-erase which is 3ms typ. That yields ~ 70s. Not much of a help really.

Other options are to not bother with this, but there are sound programming reasons for 0x00, similar to why BSS gets zeroed, setting any uninitialised variables to 0.

I just wonder if anyone knows of any tricks.

My SPI is running at 21MHz and I can't go any faster. But the data moving is worth only a few seconds (done with DMA so no gaps at all).

Currently my best idea is to perform some inspection and DVM tests on the next board while this one is zeroing itself.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline voltsandjolts

  • Supporter
  • ****
  • Posts: 2390
  • Country: gb
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #1 on: August 06, 2024, 07:20:01 am »
Use 4MB MRAM?
 

Offline glenenglish

  • Frequent Contributor
  • **
  • Posts: 439
  • Country: au
  • RF engineer. AI6UM / VK1XX . Aviation pilot. MTBr
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #2 on: August 06, 2024, 07:26:25 am »
change the memory bit charge threshold..

why do you want zeros anyway?.
 

Offline peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 3993
  • Country: gb
  • Doing electronics since the 1960s...
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #3 on: August 06, 2024, 02:46:11 pm »
Check the pricing of 4MB 8-pin package alternatives :)
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8644
  • Country: fi
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #4 on: August 06, 2024, 02:51:52 pm »
1) Fix the underlying design expectation of all zeroes, and the problem just goes away;
2) If absolutely unable, parallelize the shit out of it. Have to test 1000 units? Build 10 test stations instead of one.

If you have to test just 100, then it's just easier to go with what you have, even if it takes 70 seconds, than to invest any time into making it faster - you can, at most, reduce total test time by 116 minutes.

For testing 500 units, process improvements start to sound appealing.
 

Offline peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 3993
  • Country: gb
  • Doing electronics since the 1960s...
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #5 on: August 06, 2024, 03:07:32 pm »
The design does not rely on zeroed FLASH. It is just done (as I said before) for the same reason you zero BSS: to produce consistent results if something isn't right. I know your code has no bugs but I don't aspire to those heights myself, and C designers seem to agree :)

The other thing I thought about was to perform most of the zeroing as a background (one-off) RTOS task, when the other tests are being run. There is e.g. a factory test which takes a few mins, which is also an RTOS task, so that would work.

As an aside, I learnt a little lesson on this: It turns out that SPI1 can do 42MHz, whereas the other SPIs can do 21MHz max (168MHz CPU). But I made SPI1 inaccessible because the pin mapping forced that if I wanted four UARTs, and some other stuff. But as you rightly say that would not save any real time on this.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8644
  • Country: fi
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #6 on: August 06, 2024, 04:09:14 pm »
But flash isn't random content after erase (like RAM is after powerup); 0xFF is as consistent as 0 is. For detecting accidental failure to clear, it's even better than 0, as it's a more rare default value, and thus will fail more visibly.
 

Offline peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 3993
  • Country: gb
  • Doing electronics since the 1960s...
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #7 on: August 06, 2024, 04:56:18 pm »
Yes that's true. Well, apart from

- some of the device is storing floats of analog calibration values, and 0xffffffff is what float value? OTOH I could zero those areas very quickly...
- half the device is a FAT12 filesystem and 0x00.... is definitely not a directory entry, and probably offers better protection from corruption which is not avoidable with FAT especially as there is USB MSC (removable device) access also

I could achieve 45 secs (type data sheet figure) with the bulk chip erase. But no better, and the downside of that is that the background option mentioned above cannot be used because you cannot interrupt a bulk erase.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline WatchfulEye

  • Regular Contributor
  • *
  • Posts: 120
  • Country: gb
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #8 on: August 06, 2024, 09:12:51 pm »
Yes that's true. Well, apart from
- some of the device is storing floats of analog calibration values, and 0xffffffff is what float value? OTOH I could zero those areas very quickly...

0xffffffff signals NaN in IEEE 754, which I would have thought would be ideal to represent an uninitialized value. 
 
The following users thanked this post: Siwastaja, Pseudobyte

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4650
  • Country: dk
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #9 on: August 07, 2024, 12:19:04 am »
1) Fix the underlying design expectation of all zeroes, and the problem just goes away;
2) If absolutely unable, parallelize the shit out of it. Have to test 1000 units? Build 10 test stations instead of one.

If you have to test just 100, then it's just easier to go with what you have, even if it takes 70 seconds, than to invest any time into making it faster - you can, at most, reduce total test time by 116 minutes.

For testing 500 units, process improvements start to sound appealing.


https://xkcd.com/1205/ ;)
 
The following users thanked this post: Siwastaja, VinzC

Offline voltsandjolts

  • Supporter
  • ****
  • Posts: 2390
  • Country: gb
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #10 on: August 07, 2024, 08:35:52 am »
Yes that's true. Well, apart from

- some of the device is storing floats of analog calibration values, and 0xffffffff is what float value? OTOH I could zero those areas very quickly...
- half the device is a FAT12 filesystem and 0x00.... is definitely not a directory entry, and probably offers better protection from corruption which is not avoidable with FAT especially as there is USB MSC (removable device) access also

Erm, you are aware that the only way to go from 0 to 1 is by erasing a page/sector/chip, right? Clearing flash to zeroes prior to storing data in it makes no sense to me. I would say, erase the flash and write the data you need with block crc's as appropriate - that's the only way to be sure you have valid data, not whether it's all ff's or zeroes.
 
The following users thanked this post: wraper, artag, Siwastaja, Jacon

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8644
  • Country: fi
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #11 on: August 07, 2024, 09:09:27 am »
Erm, you are aware that the only way to go from 0 to 1 is by erasing a page/sector/chip, right? Clearing flash to zeroes prior to storing data in it makes no sense to me. I would say, erase the flash and write the data you need with block crc's as appropriate - that's the only way to be sure you have valid data, not whether it's all ff's or zeroes.

Of course, but as always, this is again one of those trick question threads which lead to nowhere. I have nothing against this as it makes interesting discussions, but I want to point out the funny thing how some people here get banned for behaving like this, others do not.
 

Offline peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 3993
  • Country: gb
  • Doing electronics since the 1960s...
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #12 on: August 07, 2024, 09:49:32 am »
Quote
Of course, but as always, this is again one of those trick question threads which lead to nowhere. I have nothing against this as it makes interesting discussions, but I want to point out the funny thing how some people here get banned for behaving like this, others do not.

What complete BS.

Trick question?

It was a serious question. Somebody may have known a way.

« Last Edit: August 07, 2024, 11:22:53 am by peter-h »
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8644
  • Country: fi
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #13 on: August 08, 2024, 10:35:39 am »
It was a serious question. Somebody may have known a way.

Oh, nearly everybody knows what you should do: abandon the idea of zeroing out the entire flash for reasons you mentioned, because those reasons are, as explained by others, made up and wrong (e.g. the float case, where NaN would be actually better than zero you suggest).

So as always, it's a classic X-Y problem where X is a weird and difficult problem to solve - and unnecessary, too. Just like treez topics.
 
The following users thanked this post: abyrvalg, ebastler, glenenglish

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13918
  • Country: gb
    • Mike's Electric Stuff
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #14 on: August 08, 2024, 10:39:10 am »
Add an inverter to Dout?
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13918
  • Country: gb
    • Mike's Electric Stuff
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #15 on: August 08, 2024, 10:41:13 am »
If you are writing zeroes, you don't need to erase it first


Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8644
  • Country: fi
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #16 on: August 08, 2024, 11:04:31 am »
If you are writing zeroes, you don't need to erase it first

Possibly. As a generic advice however, always double-check from documentation and/or flash manufacturer: some flash memories have internal checksumming that limits writing cycles to one, and others, for some reasons I don't understand, specify that for longevity and reliability of data, only limited number of write cycles between erases is allowed, which could be as low as 1. For example, nRF52 microcontrollers specify max n_write between erases 2.

So it's always a good idea to check before assuming you can just arbitrarily zero out existing bytes without erase.
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4650
  • Country: dk
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #17 on: August 08, 2024, 11:07:21 am »
If you are writing zeroes, you don't need to erase it first

and if you you write zeros you'll have to erase it before using it for anything else

*not all flash allows reprogramming a zero to zero
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8644
  • Country: fi
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #18 on: August 08, 2024, 11:25:08 am »
and if you you write zeros you'll have to erase it before using it for anything else

Which is exactly why it's a bad idea to write some calibration table to zero on production, only to be erased and rewritten on the next (calibration) step. Just bulk erase the device once in production, leave calibration as all-ones, calibrate, and write calibration results (including CRC over the calibration block) to the already erased flash. Fast and simple.
 

Offline peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 3993
  • Country: gb
  • Doing electronics since the 1960s...
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #19 on: August 08, 2024, 11:41:03 am »
On this project every write is the whole 512 byte block and it is always in the pre-erase mode. That is guaranteed to work. It takes 15ms.

But if, on a particular block, you could be sure a pre-erase (a separate command) was done then you can do a "block write without pre-erase" which takes 3ms.

Hence the suggestion of a whole device erase (45s) and then 8192 x "block write without pre-erase 0x00" which is a bit faster overall.

The cal table is a very small part of the device and not relevant to the overall time. Half the device is a FAT12 logical drive and other parts are, ahem, other things...

One advantage of the initial zeroing is that it also tests the whole device which is a good idea in itself.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6182
  • Country: es
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #20 on: August 08, 2024, 08:53:06 pm »
There's no way of making it faster, unless you're doing something wrong.
Are you waiting the time specified in the datasheet or polling the busy bit?
The latter will be way faster.

Why do you need to do this manually?
Set a checksum somehere, so if wrong the device automatically makes all the erasing/writing/verifying and initializes the default values.
« Last Edit: August 08, 2024, 08:56:32 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 3993
  • Country: gb
  • Doing electronics since the 1960s...
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #21 on: August 08, 2024, 09:01:28 pm »
Polling the BUSY state (actually over SPI).
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6182
  • Country: es
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #22 on: August 08, 2024, 09:48:20 pm »
I think you simply should allocate all those variables into some specific(s) sector(s), adding a checksum.
If the magic is wrong, erase and write defaults, simple as that, don't trust random flash contents without checksums.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline abyrvalg

  • Frequent Contributor
  • **
  • Posts: 833
  • Country: es
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #23 on: August 09, 2024, 11:52:47 am »
BTW, BSS zeroing is not some optional paranoidal “just in case” BS trick, but a part of C standard. GCC relies on it and places explicitly zero-initialized vars to BSS instead of DATA to reduce the executable image size by not including those zeroes.
 

Offline peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 3993
  • Country: gb
  • Doing electronics since the 1960s...
Re: Fastest way to set Adesto AT45DB321E 4MB SPI FLASH to zeroes
« Reply #24 on: August 09, 2024, 01:01:48 pm »
Indeed, and it is required for
int fred=0;
but not "actually" required for
int fred;
which also ends up in BSS.
But maybe C guarantees that the latter fred will also be zeroed?
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf