Pushed something like you described, new flash_area_is_empty function in
flash_map
https://github.com/apache/incubator-mynewt-core/pull/281

Currently doesnt actually work.. either my code sucks or the erase doesnt
actually ever succeed on nrf51 is is leaving behind non 0xff bytes.. not
sure which

On Tue, May 16, 2017 at 5:26 PM, Christopher Collins <ch...@runtime.io>
wrote:

> On Tue, May 16, 2017 at 05:11:36PM -0700, Jacob Rosenthal wrote:
> > Seems like it could go in flash_map?
> >
> > Its also been requested to also have a function that detects if an area
> > should be erased, based on it having any non 0xff bytes within.
> >
> > Should that go there as well.
>
> That is the same thing, isn't it?
>
> > Whats a good method to loop through all bytes of a flash area?
>
> Perhaps something like the following:
>
> 1. Allocate a buffer that is properly aligned to be accessed by an
> unsigned int*.  It may take some testing to
> determine a good size that balances speed and size efficiency; I would
> start with 64 bytes.  I would also start by putting this buffer on the
> stack.
>
> 2. Read a chunk of flash into the buffer
> (min(size-of-buffer, num-unread-bytes).
>
> 3. Use an unsigned int* to iterate through the buffer.  If the pointer
> points to something other than (unsigned int)-1, then the flash is not
> erased.
>
> 4. If there are any remaining bytes (i.e., number of bytes read is not a
> multiple of sizeof(unsigned int)), compare them individually against
> 0xff using a uint8_t*.
>
> Chris
>

Reply via email to