-
Notifications
You must be signed in to change notification settings - Fork 85
Conversation
@japaric Do you have any questions, comments, or concerns on this addition? |
Sorry, I'm preparing several releases and don't have time to look in detail. I'll check this once I'm done with that. One concern I have about this though, regardless of the implementation, is that, with the new singletons approach, if you I suggest you try this change with the master branches of cortex-m and svd2rust to see how / if it works. |
Don't worry about not getting to this soon, I just wanted to double check it wasn't lost to a flood of notifications. I will look at getting this to work with the new peripheral mechanism in cortex-m and svd2rust. |
I wish I had seen the design coming down the pipeline a month ago. I agree that with the current implementation Passing the |
8664338
to
2a75015
Compare
I have updated the pull request with a method of passing the Peripherals from The main idea of this method passes the peripherals through a static. In addition this static is of a type This does not solve passing other structures, such as peripherals from board crates, from init_array. A similar method would have to be done for each crate. |
5300fc5
to
b43cd39
Compare
Hello, I know you are a very busy man, but I was wondering if I could get some feedback on the current solution. |
Signed-off-by: Gabriel Smith <[email protected]>
Signed-off-by: Gabriel Smith <[email protected]>
Signed-off-by: Gabriel Smith <[email protected]>
Signed-off-by: Gabriel Smith <[email protected]>
@yodaldevoid sorry for the long radio silence here. I'm afraid that your proposed solution is not general enough. One of the use cases for this feature is configuring the clock to operate at higher speed before initializing the RAM with the goal of making the boot / pre-main process faster. Your solution doesn't solve that problem because configuring the clock requires access to device specific peripherals. I also think that the extensive use of I'm currently leaning towards not solving the peripherals access problem in this crate, at least not right now. Instead we simply add the mechanism (e.g. One such mechanism could be a macro that uses the /* user code */
entry!(stm32f103xx, before_main, main);
// NOTE unsafe because accessing `static` variables in this context is forbidden
// (a lint instead of unsafe would be ideal)
unsafe fn before_main(c: &mut cortex_m::Peripherals, d: &mut stm32f103xx::Peripherals) {
// ..
}
fn main(c: cortex_m::Peripherals, d: stm32f103xx::Peripherals) -> ! {
// ..
}
/* end of user code */
/* expansion of `entry!` */
#[link_section = ".pre_init"]
pub static PRE_INIT: unsafe extern "C" fn() = pre_init;
unsafe extern "C" fn pre_init() {
before_main(&mut cortex_m::Peripherals::steal(), &mut stm32f103xx::Peripherals::steal());
}
#[export_name = "main"]
pub unsafe extern "C" fn __impl_main() -> ! {
main(cortex_m::Peripherals::steal(), stm32f103xx::Peripherals::steal())
}
/* end of expansion of `entry!` */
/* cortex-m-rt */
#[no_mangle]
pub unsafe extern "C" fn Reset() -> ! {
for f in PRE_INIT_ARRAY {
f();
}
r0::zero_bss(..);
r0::init_data(..);
extern "C" {
fn main() -> !;
}
main()
} |
That solution sounds fine by me. I understand not wanting to add hacked together solutions to this crate and as I think I mentioned before I had had reservations about this solution anyway. As it sounds like you are leaning towards the other (simpler) solution, I will close this and wait with baited breath. |
I found I needed support for running code at startup recently when I found that the
.data
region in one project grew large enough that initializing it was taking long enough that the default hardware watchdog was triggering a reset. Because of this usecaser0::run_init_array
is placed beforer0::zero_bss
andr0::init_data
in case either takes too long.The only downside from the user's perspective of the current implementation is the requirement on users to add
#![feature(used)]
to their crate if they want to use the macro.From the perspective of
cortex-m-rt
this does add another unstable feature inuse_extern_macros
(tracking issue). It appears that this feature will stay unstable until macros 2.0 lands. Users do not need to enableuse_extern_macros
and can use the macro either fromr0
or throughcortex-m-rt
via#[macro_use]
.