8000 Fix UartMux to be able to use multiple muxes by alexandruradovici · Pull Request #3216 · tock/tock · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix UartMux to be able to use multiple muxes #3216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 30, 2022

Conversation

alexandruradovici
Copy link
Contributor

Pull Request Overview

This pull request fixes the way in which UartMux is being instantiated. Before this PR:

  • the new function from the UartMuxComponent would instantiate the UartMux using a static_init! macro. Due to this, instantiating two UartMux structures would result in the second instance overwriting the first one.
  • the RX_BUF was defined within the virtual_uart capsule, meaning that two instances of UartMux would use the same buffer.

This PR:

  • moves the instantiating of the UartMux in the uart_mux_component_helper macro.
  • moves the instantiating of the RX_BUF in the uart_mux_component_helper macro.

Example

let uart_mux1 = components::console::UartMuxComponent::new(
    &peripherals.usart1,
    115200,
    dynamic_deferred_caller,
)
.finalize(components::uart_component_helper!(64));

let uart_mux2 = components::console::UartMuxComponent::new(
    &peripherals.usart2,
    115200,
    dynamic_deferred_caller,
)
.finalize(components::uart_component_helper!(64));

Without this PR uart_mux2 overwrites uart_mux1, as the structure is allocated in the same memory space.

This PR enables the usart2 for the STM32F3Discovery board.

This is similar to what the I2C and SPI components do.

Testing Strategy

This pull request was tested using an STM32F3 Discovery board with two serial ports. One serial port was used for the kernel messages and process console, while the second one was used for applications.

TODO or Help Wanted

N/A

Documentation Updated

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

Formatting

  • Ran make prepush.

@github-actions github-actions bot added the WG-OpenTitan In the purview of the OpenTitan working group. label Sep 13, 2022
@bradjc
Copy link
Contributor
bradjc commented Sep 13, 2022

Does this conflict or overlap #3046?

@alexandruradovici
Copy link
Contributor Author

Does this conflict or overlap #3046?

I don't think it does, #3046 does not seem to change anything for the mux initialization or the uart receive buffer. The boards/components/src/console.rs file is not changed.

hudson-ayers
hudson-ayers previously approved these changes Sep 13, 2022
< 8000 summary data-view-component="true" class="timeline-comment-action Link--secondary Button--link Button--medium Button"> Copy link
Contributor
@hudson-ayers hudson-ayers left a comment

Choose a reason for hiding this comment

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

Looks good to me -- it was always a problem that the receive buffer was defined in the capsule.

I am adding a new label for this PR to track changes that modify the board interface in a way that an out-of-tree board maintainer would need to replicate, just so we can track these types of changes between releases.

@hudson-ayers hudson-ayers added the board-interface-change Changes the interface between boards and the kernel; may need to be replicated in out-of-tree boards label Sep 13, 2022
Copy link
Contributor
@bradjc bradjc left a comment

Choose a reason for hiding this comment

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

I see that this is inline with the I2C component, but I'm not sure about this change. static_ini_half! was created for a very specific purpose: to support sharing components when the actual object is templated on a chip-specific type. Here there is no chip-specific type in the virtual uart object, and as such the console component didn't use static_init_half.

I don't think we should continue to use static_init_half for a different purpose (to allow the same component to be used multiple times). Also, there is currently no indication of which components can be used multiple times. If components are going to be maintainable and usable, I think we need something more clear about how they can be used.

@hudson-ayers
Copy link
Contributor

Ideally the policy should be that every component is reusable; but that would require a high-effort overhaul of all components to get there, and we have seen with #1618 that there isn't anyone motivated for a whole-scale components overhaul. IMO it seems like a shame to not at least make usability improvements on an as-needed basis, or to block those improvements on a very high-effort complete overhaul.

@alexandruradovici
Copy link
Contributor Author

@bradjc are you suggesting moving the arguments of new to the macro?

The UartMux needs to be initialized in a macro, otherwise it will be overwritten every time we call new.

@bradjc
Copy link
Contributor
bradjc commented Sep 14, 2022

I'm not suggesting we do a full change to components, or that we cannot upgrade the console component independently of all other components. What I'm saying is that static_init_half!() is a hack I added to allow us to share components across microcontrollers. According to our own documentation, we aren't supposed to be using static_init_half anymore:

/// This macro is deprecated. You should migrate to using `static_buf!`
/// followed by a call to `StaticUninitializedBuffer::initialize()`.
///
/// Same as `static_init!()` but without actually creating the static buffer.
/// The static buffer must be passed in.
#[macro_export]
macro_rules! static_init_half {

But what I want to avoid is adding a new hack using an old hack to get re-usable components. I assume there must be some mechanism we can add or use that makes it clear that the console component is now reusable.

@alexandruradovici
Copy link
Contributor Author

So using static_buf instead would work?

@github-actions github-actions bot added the stm32 Change pertains to the stm32 family of MCUSs label Sep 14, 2022
@alexandruradovici
Copy link
Contributor Author

I updated it to use the static_buf macro.

hudson-ayers
hudson-ayers previously approved these changes Sep 19, 2022
alistair23
alistair23 previously approved these changes Sep 20, 2022
@bradjc bradjc added the blocked Waiting on something, like a different PR or a dependency. label Sep 22, 2022
@alexandruradovici
Copy link
Contributor Author

I rebased it to use the new static_buf with MaybeUninit. I think this is good to go.

8000
@bradjc bradjc removed the blocked Waiting on something, like a different PR or a dependency. label Sep 26, 2022
bradjc
bradjc previously approved these changes Sep 27, 2022
@bradjc bradjc added the last-call Final review period for a pull request. label Sep 27, 2022
alistair23
alistair23 previously approved these changes Sep 27, 2022
@bradjc
Copy link
Contributor
bradjc commented Sep 28, 2022

bors r+

bors bot added a commit that referenced this pull request Sep 28, 2022
3216: Fix UartMux to be able to use multiple muxes r=bradjc a=alexandruradovici

### Pull Request Overview

This pull request fixes the way in which `UartMux` is being instantiated. Before this PR:
- the `new` function from the `UartMuxComponent` would instantiate the `UartMux` using a `static_init!` macro. Due to this, instantiating two `UartMux` structures would result in the second instance overwriting the first one.
- the `RX_BUF` was defined within the `virtual_uart` capsule, meaning that two instances of `UartMux` would use the same buffer.

This PR:
- moves the instantiating of the `UartMux` in the `uart_mux_component_helper` macro.
- moves the instantiating of the `RX_BUF` in the `uart_mux_component_helper` macro.

#### Example

```rust
let uart_mux1 = components::console::UartMuxComponent::new(
    &peripherals.usart1,
    115200,
    dynamic_deferred_caller,
)
.finalize(components::uart_component_helper!(64));

let uart_mux2 = components::console::UartMuxComponent::new(
    &peripherals.usart2,
    1
8000
15200,
    dynamic_deferred_caller,
)
.finalize(components::uart_component_helper!(64));
```

Without this PR `uart_mux2` overwrites `uart_mux1`, as the structure is allocated in the same memory space.

This PR enables the `usart2` for the STM32F3Discovery board.

This is similar to what the I2C and SPI components do.

### Testing Strategy

This pull request was tested using an STM32F3 Discovery board with two serial ports. One serial port was used for the kernel messages and process console, while the second one was used for applications.


### TODO or Help Wanted

N/A


### Documentation Updated

- [x] Updated the relevant files in `/docs`, or no updates are required.

### Formatting

- [x] Ran `make prepush`.


Co-authored-by: Alexandru RADOVICI <alexandru.radovici@wyliodrin.com>
Co-authored-by: Alexandru Radovici <msg4alex@gmail.com>
@bors
Copy link
Contributor
bors bot commented Sep 28, 2022

Build failed:

@alexandruradovici
Copy link
Contributor Author

Rebased

alexandruradovici and others added 2 commits September 30, 2022 19:51
Co-authored-by: Brad Campbell <bradjc5@gmail.com>
Co-authored-by: Brad Campbell <bradjc5@gmail.com>
@bradjc
Copy link
Contributor
bradjc commented Sep 30, 2022

bors r+

@bors
Copy link
Contributor
bors bot commented Sep 30, 2022

@bors bors bot merged commit 77b46df into tock:master Sep 30, 2022
mateibarbu19 added a commit to WyliodrinEmbeddedIoT/tock that referenced this pull request Oct 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
board-interface-change Changes the interface between boards and the kernel; may need to be replicated in out-of-tree boards last-call Final review period for a pull request. stm32 Change pertains to the stm32 family of MCUSs WG-OpenTitan In the purview of the OpenTitan working group.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0