-
Notifications
You must be signed in to change notification settings - Fork 213
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
Adding support for the ESP32C3 #733
Conversation
As a sidenote, this should generalize well to the other ESP RISC-V MCUs but i don't have any to play around with. |
@romancardenas has suggested splitting up export like here https://github.com/greenlsi/rtic/tree/master/rtic%2Fsrc%2Fexport for better modularity. I think for now it might be overkill, but depending on how many unique backends we expect to support, it could be a good idea. |
If you don't like all those submodule folders, we could also leave it as In any case, I do believe that we should move the feature-gated definitions of functions like |
I've been able to move things around a bit, now this only relies on changes to the hal, the rt remains untouched. I've also fixed some weird errors regarding feature selection, which i'm not sure how they made it in there to begin with. |
@steewbsd and I have re-structured the export module of our fork so it has less folders. Have a look, maybe you prefer it that way. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice piece of work! I see we more or less reached the same point. Let's try to clarify the structure stuff and then I will adapt our fork to include yours :D
@@ -323,6 +323,14 @@ pub fn interrupt_exit(_app: &App, _analysis: &CodegenAnalysis) -> Vec<TokenStrea | |||
vec![] | |||
} | |||
|
|||
pub fn async_entry( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this new hook is required by ESP32C3 for un-pending the dispatchers' interrupt, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep
rtic-macros/src/codegen/main.rs
Outdated
@@ -20,7 +20,7 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 { | |||
quote!(#dispatcher();) | |||
} else { | |||
quote!(loop { | |||
rtic::export::nop() | |||
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious: why do you avoid the nop
function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like it achieves the same end result (this is just an empty idle generated when you don't give one), without the need for exporting nop. I guess there is no specific reason, just the solution i came up with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is effectively equivalent, then I'm in
rtic-macros/src/codegen/util.rs
Outdated
@@ -6,11 +6,20 @@ use syn::{Ident, PatType}; | |||
|
|||
const RTIC_INTERNAL: &str = "__rtic_internal"; | |||
|
|||
//this is named something else in the esp32c3 pac | |||
#[cfg(not(feature = "riscv-esp32c3"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check this. We had a similar issue and tackled this way. The idea is to avoid feature gates out of codegen::bindings
.
rtic/Cargo.toml
Outdated
esp32c3 = {version = "0.13.0", optional = true} | ||
#next goal is getting the neccessary changes to the hal upstreamed | ||
#esp32c3-hal = { git = "https://github.com/onsdagens/esp-hal", branch="scaled_back", optional = true} | ||
esp32c3-hal = { git = "https://github.com/onsdagens/esp-hal", branch="interrupt_preemption", optional = true} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you depend both on the PAC and the HAL. Could you explain to me why? Maybe we need this as well for the SLIC implementation
rtic/src/export.rs
Outdated
#[cfg(feature = "riscv-esp32c3")] | ||
pub use riscv_esp32c3::*; | ||
|
||
///I think all of these "pends" and "unpends" should be moved to /export/<device>.rs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same. We propose this structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, i'll align this with your proposal
@@ -0,0 +1,105 @@ | |||
use esp32c3::INTERRUPT_CORE0; //priority threshold control | |||
pub use esp32c3::{Interrupt, Peripherals}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you set your core peripherals as the PAC's peripherals. So this is basically what we have done. Thus, the core peripherals and device peripherals will be exactly the same. This is why I wonder if the core peripherals are needed for RISC-V targets, as there is no such thing. Maybe we can make it optional and include it only for Cortex. However, I think @korken89 would rather not modify struct fields depending on the backend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that API is set in stone - if there is a good reason to deviate I see no reason to strictly follow the old one :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
As a side note, it would be worth discussing removing from the API rtic::export::peripherals
and rtic::export::nop
at the next meeting. The prior looks too Cortex-M-driven, and the latter can just be continue
.
Some breaking changes if you've been using this fork. I've moved it to use the new upcoming If you're using the For some minimal examples check out https://github.com/perlindgren/esp32c3-test/tree/rtic_sw_tasks |
Rebased on upstream now with Per adding a drop-in replacement of atomics in |
Manually testing for toxic effects of extern "C" fn test_atomics(offset: u8) -> AtomicU8 {
(84 + offset).into()
}
It's not a complete test of course, but it looks as expected (compiled in release mode, without overflow checks). There is no reason to believe any other natively supported atomic data structures should cause problems. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you for the effort!
The merge-base changed after approval.
esp32c3 support
As discussed, this adds support for the ESP32C3.
It relies on forks of both the runtime and the hal for interrupt preemption, my next goal is possibly getting those upstreamed as well.