Repository navigation
Conversation
c38bb6d to
b20dbe0
Compare
| pub const Flash = struct { | ||
| // TODO: We must also wait for flash dma transfers to finish in addition to | ||
| // critical sections | ||
| // TODO: Maybe instead of asserts we should return errors? |
There was a problem hiding this comment.
I think so, unless we're going down we shouldn't make a hal that makes it hard to make a resilient system
| }); | ||
| rp2xxx.uart.init_logger(uart); | ||
|
|
||
| const flash_storage_start: u32 = 256 * 1024; |
There was a problem hiding this comment.
Can we take this from the target? We don't want someone to build an example and accidentally wipe something important.
There was a problem hiding this comment.
This is generic across all rp2xxx. is 256k as the start going to be safe? What about different boards/variants?
This is probably totally fine, but I was basically asking whether we can use a field in board or something to put this value so e.g. a board with some bootloader won't have the bootloader accidentally wiped running this example.
It is probably not worth worrying about at this point.
| var current_offset: u32 = flash_storage_start; | ||
| while (current_offset < flash_storage_end) : (current_offset += flash.SECTOR_SIZE) { | ||
| std.log.info("Erasing sector at offset {x}", .{current_offset}); | ||
| flash.range_erase(current_offset, flash.SECTOR_SIZE); |
There was a problem hiding this comment.
shouldn't this function handle whatever looping it needs to do to wipe everything in the requested range?
|
|
||
| /// A generic storage implementation that can be used with any flash device. | ||
| /// Items are stored sequentially in sectors (inspired by the rust crate | ||
| /// sequential storage). It should be resilient to power loss and flash |
There was a problem hiding this comment.
can you link the crate?
| try testing.expectEqual(@as(?u32, null), try s.fetch(3, u32)); | ||
| } | ||
|
|
||
| test "overwrite frees the old item" { |
| if (i > 1000) return error.NeverRanOutOfMemory; | ||
| } | ||
| } | ||
| }; |
There was a problem hiding this comment.
I imagine you plan on writing tests which utilize the tripwires?
There was a problem hiding this comment.
I tried to implement some fuzzing, but unfortunatelly the zig compiler crashed when trying to run the fuzz test 😄
There was a problem hiding this comment.
apparently now fuzzing works but I have no idea how to use it, I wrote a basic test but I am not sure I am generating the values the right way. There are no docs at the moment :)
There was a problem hiding this comment.
I mean like power_loss_tripwire which you support and check for but never use in your tests.
|
In addition to this PR, could you write a couple issues to implement this driver for architectures unlike the rp2xxx? I want to try to catch any leaky abstractions by having you think through some systems like AVR or MSP430, but I don't want to make you implement a patch for hardware you may not have. |
Generic flash storage driver inspired by the rust crate sequential-storage. I needed a persistent storage lib for a project of mine and this is my attempt at writing one. I tried to make it as resilient as possible, like an interrupted store operation shouldn't mess anything up. There are still some TODOs left, but I'd love some feedback on it. I wrote a tiny rp2xxx demo example if anyone wants to try it out.