Closed asob closed 2 years ago
@asob, thank you for reporting this.
Indeed without a valid storage partition defined the sample will not work. Your fix will enable to use the nvs subsystem for your application, but maybe we need to add some extra information in the README.rst (and/or documentation) stating that "a valid flash partitioning setup (including a storage partition) is required".
I wouldn't go as far as to call this a bug, the flash partitioning was just not setup. When new devices are added this is to be expected. Some hardware manufacturers are helping a lot in the zephyr development and they are monitoring so that their devices can be used to their full potential. For other cases there are users who are contributing without connection to the hardware manufacturer. These users might be a bit more conservative into adding features they have not tested, so sometimes things are not added.
@Laczen: You're welcome. Chip shortage is forcing many of us to switch to devices that are actually available so it's no longer about eing able to pick the device that has best support but rather a device that is available and make it work.
Valid partitioning information is not enough to get this sample working, I found that SOC_FLASH_SAM0_EMULATE_BYTE_PAGES
must be defaulted to yes
in drivers/flash/Kconfig.sam0
in order to have this sample operate as expected.
@asob, I guess that if you have to enable EMULATE_BYTE_PAGES
that the write-block-size
of the flash is larger than 32. If this is the case and the driver does not allow rewrites to a flash address DO NOT USE nvs. The EMULATE_BYTE_PAGES
is writing one write-block-size
at a time and the method works well if you only "linearly" write to flash. nvs however writes data at the beginning of a sector and a allocation entry at the end (so "jumping" around). The result will be (unless the driver allows rewrites) that for each write of a nvs entry at least two write-block-sizes
will be taken, resulting in very bad flash utilization and fast flash wear. If this is the case it is better to use fcb for storage. This is not so fail safe but uses "linear" writes.
Maybe this is the reason why the developers have not partitioned the flash.
@Laczen Ok, I understand. I see from atmel's datasheet that flash writing is a bit restrictive in terms of minimum size, so I played around with the idea of having a block-sized buffer in ram (8192 bytes) which is used when writes are perfomed, to have some sort of read-modify-write procedure.
So I re-wrote the flash_sam0_write
in such a way that every time a write occurs (aligned/unaligned to block boundary), i copy the whole block or blocks into ram, modify and then write it to back to flash. So far it loooks like it's working on nvs
, littlefs
samples.
So far the only downside is that I have to have an 8k buffer in ram at all times, well unless I choose to allocate/free it on demand.
Hi @asob , It will be nice if you can upstream your solution.
CC: @arvinf
@Laczen Ok, I understand. I see from atmel's datasheet that flash writing is a bit restrictive in terms of minimum size, so I played around with the idea of having a block-sized buffer in ram (8192 bytes) which is used when writes are perfomed, to have some sort of read-modify-write procedure.
So I re-wrote the
flash_sam0_write
in such a way that every time a write occurs (aligned/unaligned to block boundary), i copy the whole block or blocks into ram, modify and then write it to back to flash. So far it loooks like it's working onnvs
,littlefs
samples.So far the only downside is that I have to have an 8k buffer in ram at all times, well unless I choose to allocate/free it on demand.
@asob, if this works there is no need for such a large buffer, just one of the write block size should suffice.
I have an update to the flash driver that I'll be submitting as a PR soon to deal with this issue. If the write size or alignment is smaller than a page (which is 512 bytes on the SAM53) then it uses WQW -- write quad word -- command to write the data.
This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.
Describe the bug
samples/subsys/nvs
does not compile for atsame54_xpro even though that flash drivers exists for sam0. See further down for potential fix.To Reproduce
Expected behavior Output as described in
samples/subsys/nvs/README.rst
Impact Showstopper, can't use nvs subsystem
Logs and console output
Environment (please complete the following information):
Additional context I've made the following changes
which results in nvs sample working properly