agausmann / atmega-usbd

Rust usb-device support for ATmega chips
BSD Zero Clause License
27 stars 10 forks source link

New to embedded rust. Some idle questions. #9

Closed alexmadeathing closed 1 year ago

alexmadeathing commented 1 year ago

Hi, so I managed to implement a simple midi controller yesterday, using usbd-midi and atmega-usbd. I'm not new to Rust and have done some arduino embedded before, but this was the first time I joined the two. Frankly, I'm still a newbie at embedded in general. So I have a few questions if you don't mind.

I realise this library is still fledgeling. Thank you for implementing it. You saved me a big headache!

agausmann commented 1 year ago

First things first, unfortunately Rust is not a good choice for stable development for AVR (yet). There are probably still bugs in rustc/LLVM, and atmega-usbd is definitely not stable. If you want a (relatively) painless development and support experience, I recommend using LUFA.

This crate is a very early prototype and I personally cannot provide support in every possible scenario; I've only really tested this on Windows/Linux with usbd-hid, and I don't use it very often. Currently I rely on library users to have the willingness and the low-level knowledge of USB on AVR to diagnose errors/bugs themselves. If they're willing to take the time to help solve it, I may be able to provide some guidance on specific problems.


With that out of the way, I'll try to answer your other questions:

Hope this helps.

alexmadeathing commented 1 year ago

Thank you for taking the time to consider my questions and write all that out. You went above and beyond. I appreciate it.

Noted regarding the ISRs and PLL section.

Alright. I'll work out whether I want to continue with Rust for this. I think I do, but it just means I might need to get down and dirty with datasheets and low level registers. And frankly, I can see I have a lot to learn about embedded in general.

I'll close this issue as I see it doesn't really relate to your lib.

agausmann commented 1 year ago

I want to clarify - Rust on AVR is usable, but it may take a lot more time and effort to do things compared to other embedded targets. You might encounter very weird compiler bugs sometimes (though that is becoming less common).

As a hobby, I would recommend it if you don't mind spending a lot of time digging and learning. That's what I do, and that's why I made this - I wanted to write my own Rust firmware for some AVR-based keyboards I own. It's been very rewarding getting this to work and helping make progress in support for AVR.

However, if you are designing a device from scratch and you want it to "just work" without much effort, I would either 1. drop AVR or 2. drop Rust. If you want to try out embedded Rust and don't care about the specific microcontroller, there is pretty good support for ARM Cortex-M chips. I've worked specifically with STM32 and RP2040, and both have good HAL libraries.

alexmadeathing commented 1 year ago

Ahhh thanks for the tips buddy. I actually have a few teensys lying around which are cortex M4 if I remember correctly. I'll dust them off. A bit overpowered for my project but that's no biggie as maybe I can drive a display too. Yes, it is just a hobby. I'm a C++ coder by profession, but haven't really explored embedded much, and Rust is my happy place, so I'm experimenting for fun.

Speaking of keyboards, what do you have? I've built myself a couple Corne splits for home and work and a Reviung for travelling. Via/QMK so not Rust yet, but I'm sure they will be soon. How far along is your firmware?

image