Skip to content

Stm32f3: add flash support#2083

Merged
bors[bot] merged 24 commits into
tock:masterfrom
krady21:stm32f3-flash
Sep 17, 2020
Merged

Stm32f3: add flash support#2083
bors[bot] merged 24 commits into
tock:masterfrom
krady21:stm32f3-flash

Conversation

@krady21

@krady21 krady21 commented Aug 24, 2020

Copy link
Copy Markdown
Contributor

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

  • Updated the relevant files in /docs, or no updates are required.

Formatting

  • Ran make prepush.

@krady21 krady21 changed the title Stm32f3: Add flash support Stm32f3: add flash support Aug 24, 2020

@hudson-ayers hudson-ayers left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread chips/stm32f303xc/src/flash.rs Outdated
Comment thread chips/stm32f303xc/src/flash.rs Outdated
Comment thread chips/stm32f303xc/src/flash.rs Outdated
Comment thread chips/stm32f303xc/src/flash.rs Outdated
Comment thread chips/stm32f303xc/src/flash.rs Outdated
@krady21

krady21 commented Aug 24, 2020

Copy link
Copy Markdown
Contributor Author

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?

@hudson-ayers

Copy link
Copy Markdown
Contributor

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 boards/stm32f3discovery/src/main.rs. Implementing the nonvolatile storage driver should be fine. There are examples of how to do so in https://github.com/tock/tock/blob/master/boards/imix/src/main.rs and https://github.com/tock/tock/blob/master/boards/nordic/nrf52840dk/src/main.rs

@krady21

krady21 commented Aug 24, 2020

Copy link
Copy Markdown
Contributor Author

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 boards/stm32f3discovery/src/main.rs. Implementing the nonvolatile storage driver should be fine. There are examples of how to do so in https://github.com/tock/tock/blob/master/boards/imix/src/main.rs and https://github.com/tock/tock/blob/master/boards/nordic/nrf52840dk/src/main.rs

Ok. I'm on it!

hudson-ayers
hudson-ayers previously approved these changes Aug 24, 2020
@krady21

krady21 commented Aug 25, 2020

Copy link
Copy Markdown
Contributor Author

I have one question regarding the userspace address and length used by NonvolatileStorageComponent::new(). In the last commit, I used the ones that I found in chip_layout.ld. Can you confirm that they are the right ones? I am worried that i might overwrite the code segment.

alistair23
alistair23 previously approved these changes Aug 25, 2020
Comment thread boards/stm32f3discovery/src/main.rs Outdated
@hudson-ayers

Copy link
Copy Markdown
Contributor

I have one question regarding the userspace addresses and length used by NonvolatileStorageComponent::new(). In the last commit, I used the ones that I found in chip_layout.ld. Can you confirm that they are the right ones? I am worried that i might overwrite the code segment.

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
@krady21 krady21 dismissed stale reviews from alistair23 and hudson-ayers via 0d018ba August 26, 2020 13:44
@krady21

krady21 commented Aug 27, 2020

Copy link
Copy Markdown
Contributor Author

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
hudson-ayers previously approved these changes Aug 28, 2020

@hudson-ayers hudson-ayers left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

alistair23
alistair23 previously approved these changes Aug 28, 2020
Comment thread chips/stm32f303xc/src/flash.rs
alistair23
alistair23 previously approved these changes Sep 11, 2020

@ppannuto ppannuto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good -- one place where some comments would be valuable, but otherwise looks good to me

Comment thread boards/stm32f3discovery/src/main.rs Outdated
@ppannuto ppannuto added the last-call Final review period for a pull request. label Sep 11, 2020
@bradjc

bradjc commented Sep 17, 2020

Copy link
Copy Markdown
Contributor

bors r+

@bors

bors Bot commented Sep 17, 2020

Copy link
Copy Markdown
Contributor

@bors bors Bot merged commit 14dda51 into tock:master Sep 17, 2020
sirchnik pushed a commit to sirchnik/tock that referenced this pull request May 12, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

last-call Final review period for a pull request.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants