-
Notifications
You must be signed in to change notification settings - Fork 231
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Target microcontroller directly instead of an arduino board #125
Comments
Hi!
That's just because most people will be using one of those boards so that's what we tried making the easiest to get started with. Also, it is hard to write examples against a generic MCU, because you have no clue what peripherals are connected and could be used...
It really depends on the usecase I'd say. Is it a one-off application for a custom design? Then I'd just go with the HAL (
You really just need [dependencies.atmega328p-hal]
git = "https://github.com/Rahix/avr-hal"
rev = "206ff87bdc38afcffd9db1c9326c0d4d9487cb14"
features = ["atmega328p", "rt"] Note the #[atmega328p_hal::entry]
fn main() -> ! {
// ...
}
Instead of the board prelude, you'd go with the HAL prelude. E.g. use atmega328p_hal::prelude::*; Hope this helps! If you need anything else, let me know :) |
One more thing which might be important: The board support crates re-export the bare MCU pins (PA0, PB3, etc.) in this let dp = arduino_uno::Peripherals::take().unwrap();
let mut pins = arduino_uno::Pins::new(dp.PORTB, dp.PORTC, dp.PORTD);
let mut led = pins.d0.into_output(&mut pins.ddr); you'd have to write let dp = atmega328p_hal::pac::Peripherals::take().unwrap();
let mut portb = dp.PORTB.split();
let mut led = portb.pb0.into_output(&mut portb.ddr); (This works via the |
@Rahix
Yes, it's a special use case with a custom made PCB.
Ah, yes this was missing too. |
I might have one last question. In my program I need to access a peripheral in a ISR, so I have to share the peripherals in some way. The Rust Embedded Book takes an approach with an However when I try to use this approach in my program I get weird linker errors (the compilation is fine) as soon as I do something like this in my critical section:
Errors:
|
Heh, yeah, that's a known issue: rust-lang/compiler-builtins#347 There is a dirty workaround to add the following to your [profile.dev.package.compiler_builtins]
overflow-checks = false
|
I see. Many thanks! |
Hey @Rahix! |
Can't say I fully understand what the project is about, but it looks really neat! Is it a controller for a telescope mount? I see you also wrote an EEPROM driver. Would you be interested in upstreaming that into avr-hal? Also, do you have any feedback regarding your experience with using avr-hal & avr-device? What were the main painpoints? Were there any things where you had to "work around" the API because it hindered you from doing what you needed to? Are there any big missing things which would have helped you a lot? |
Thanks!
Yes exactly. The core functionality is to control a stepper motor which controls a telescope mount. The speed of the motor can be adjusted by trail and error using a Bluetooth module. Using this technique I was able to get a very good improvement in visual observation. As an additional improvement I thought of introducing a feedback loop that tries to hold a star in place with a webcam and therefore send guiding pulses to the stepper motor. This is what the C++ driver is for but unfortunately I never got this to work in a way that it actually could improve things.
I could actually imagine to work on such a feature but I think my current code isn't sophisticated enough yet to upstream it.
Well because I was new to Embedded Rust, I was confused at first by understanding the difference between the pac module and all of the other modules.
Eventually I could shorten this by utilizing some use statements but it always felt very odd to me.
I don't think so, except for the timer and eeprom which obviously had to be implemented by accessing the registers manually. |
That's amazing!
Yeah, you're not alone with that, I've gotten that report from quite a few people now... I think I can maybe add some sort of overview to the README which explains how all the parts fit together.
Right... I think the only real way to mitigate this would be creating type aliases in the relevant HAL crates directly which downstream code can then just reference easily. I'll have a look what is possible here. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Hello,
I'm new to avr-rust and Rust in general.
All examples I see in this repository seem to target a board (for example Arduino Uno). Is it possible or recommended to directly target a microcontroller such as atmega328p?
I found no example and had trouble while trying to do so.
I added those lines to the
Cargo.toml
:Do I need to write something like
#[avr_device::entry]
instead of#[arduino_uno::entry]
in the source file? Or how can I use the needed prelude?Thank you in advance!
The text was updated successfully, but these errors were encountered: