Stm32f3: add flash support#2083
Conversation
the hil::flash::Flash trait and a generic struct for Stm32f303 Flash page.
Implement write and erase for the option bytes. Cleanup the comments.
hudson-ayers
left a comment
There was a problem hiding this comment.
Thank you for this PR! I am excited to have flash support for an STM chip!
I have not completely reviewed this yet, but I left a few comments inline. One other comment: generally, we want upstream Tock boards to include support for all chip peripherals. This makes release testing much easier, and ensures that driver code continues to compile as Tock changes. Could you add the virtual flash to the stm32f3discovery board (using this driver) as part of this PR?
Co-authored-by: Hudson Ayers <32688905+hudson-ayers@users.noreply.github.com>
2. Added callbacks to PGERR and WRPRTERR
|
Could you give me some pointers in regards to adding the virtual flash? Do i have to write an additional flash capsule that I would use alongside the virtual flash capsule similar to what is done with the Alarm one? |
Sorry, I shouldn't have said virtual flash in my comment -- I just meant that there should be some capsule using the driver, instantiated in |
Ok. I'm on it! |
|
I have one question regarding the userspace address and length used by |
I am actually not sure how the userspace addresses/length are supposed to be chosen. Neither Imix nor the nrf52840dk assign the entire prog region as userspace accessible though, which makes me nervous that this does... @bradjc ? |
Used sstorage and estorage for the kernel address and length, as suggested. Changed the userspace address and length to 0x08038000 and 0x2000 in src/main.rs and chip_layout.ld to avoid overwriting the code segment
|
Ended up choosing 0x08038000 and 0x8000 (32KB) for the userspace address and length (prog being between 0x08020000 and 0x08040000). This leaves us with 96KB for the application binaries and 16 pages available for userspace programming. Imix does a similar thing, using 0x60000, while its prog area is between 0x40000 and 0x80000. Let me know if you have a different split in mind and sorry for having you review this twice. |
hudson-ayers
left a comment
There was a problem hiding this comment.
I am happy with this PR, but would like if someone more familiar than me with how we assign userspace flash regions could double check that.
319d2f6
ppannuto
left a comment
There was a problem hiding this comment.
I think this looks good -- one place where some comments would be valuable, but otherwise looks good to me
|
bors r+ |
2083: Stm32f3: add flash support r=bradjc a=krady21 ### Pull Request Overview This pull request adds flash memory support for stm32f303xc (embedded flash and option bytes). ### Testing Strategy This pull request was tested using a stm32f3discovery kit. All the main operations have been tested and work properly (read, write, erase). ### TODO or Help Wanted I am still somewhat unsure about how to treat the callbacks from writing and erasing the option bytes. ### Documentation Updated - [x] Updated the relevant files in `/docs`, or no updates are required. ### Formatting - [x] Ran `make prepush`. 2101: RFC: Remove `AppPtr::Drop()` and `Owned::Drop()` r=bradjc a=hudson-ayers ### Pull Request Overview This PR proposes removing `AppPtr::Drop()` and `Owned::Drop()`, as well as the `ProcessType::free()` method that they each call. Currently, `Process::free()` is implemented with an empty body, merely dropping the passed raw pointer. Therefore, as far as I can tell, calls to `Drop()` on each type have no useful effect. Despite this, the presence of these implementations have a significant cost -- the implementations of `Drop` call `kernel.process_map_or()`, which takes a trait object reference (e.g. `&dyn ProcessType`), so the compiler cannot know that the concrete `free()` function that will be called is empty, and optimize the call out. Currently, anytime an `AppPtr` or `Owned` type goes out of scope -- including anytime a struct containing such a type goes out of scope -- `drop()` is called on each type until the underlying `drop()` implementation is called. This happens frequently: a single iteration of the loop in the `Imix` app calls `AppPtr::drop()` 45 times; a single iteration of the `hello_loop` app calls `AppPtr::drop()` 4 times and `Owned::drop()` 3 times. Further, each call has some cost: ##### Cycles per call, measured using cortex-m DWT cycle counter peripheral: `AppSlice::drop()` - 139 cycles (increases to 145 if the board is configured for 8 processes instead of 4) `Owned::drop()` - 84-150 cycles, depending on context. Removing the Drop implementations for `AppPtr` and `Owned` reduces the measured cycle count in each case to 1 cycle. `AppSlice::drop()` is called regularly (inserted by the compiler) within the body of `allow()` system call implementations, `Owned::drop()` is called within the body of `Grant::enter()` and `Grant::each()`. Keeping in mind recent attempts to reduce Tock syscall overhead, I think that we should not pay all of this overhead for no benefit as Tock is implemented today. Alternatively, if there is reason to believe these implementations will be useful in the future, I think we should document these functions (and `ProcessType::free()`) as to why they are present. ### Testing Strategy This pull request was tested by running several apps with the drop implementations removed. ### TODO or Help Wanted The Tock SOSP paper talks a bit about the `Owned::drop()` implementation, but as far as I can tell it does not actually do anything in Tock today. Is there reason to believe we will need these implementations for some future process type? Am I totally missing something here? ### Documentation Updated - [x] No updates are required. ### Formatting - [x] Ran `make prepush`. Co-authored-by: Bogdan Grigoruta <bogdangrigoruta@gmail.com> Co-authored-by: Bogdan Grigoruta <43993819+krady21@users.noreply.github.com> Co-authored-by: Hudson Ayers <hayers@stanford.edu>
Pull Request Overview
This pull request adds flash memory support for stm32f303xc (embedded flash and option bytes).
Testing Strategy
This pull request was tested using a stm32f3discovery kit. All the main operations have been tested and work properly (read, write, erase).
TODO or Help Wanted
I am still somewhat unsure about how to treat the callbacks from writing and erasing the option bytes.
Documentation Updated
/docs, or no updates are required.Formatting
make prepush.