How to Learn Embedded Rust on the STM32F103 Blue Pill

Created   

Categories: , , , ,

STM32F103 Blue Pill with STLink V2 Debugger

The water’s not that deep - you’ll be fine

You will find tutorials and blog posts telling you how easy it is to get started in Rust on an STM32 platform.

They lie!

Or at least, they are written by experienced embedded developers who are simply transitioning to Rust.

As an Arduino developer, you are familiar with:

  • downloading the IDE
  • changing the board type
  • copy-pasting some demo code
  • change the odd pin assignment
  • compile and upload
  • Done!

This is not Arduino

Instead you are now faced with:

  • Manual setup of your toolchain
  • Manual configuration of your debugging tool/uploader
  • No out of the box integration with your IDE
  • Blog posts which are outdated, whose code won’t compile anymore
  • Libraries at a much lower level than Arduino ones
  • Having to be very familiar with your chip’s data sheets

The Wrong Way to Learn

My initial approach to learning, which has usually served me well, was

  • Avoid any dusty official documentation, it takes too long to digest all that detail
  • Find a respectable looking blog-with-code
  • Relicate the steps in the blog; make some trial and error modifictions; add some interesting looking libraries to tinker with peripherals
  • Glue together the various bits of experimentation into your actual project

I wasted a lot of time. Rust and the libraries in the ecosystem have changed in the last 3 years, and most of the blog posts were written by seasoned embedded developers who were early adopters in Rust. Although I learned something from every one of them, it was not the right apporoach to learning a whole new language and ecosystem.

Take Your Time, Structure Your Learning

The right way is to take your time and use the official docs - they are excellent, and shouldn’t be rushed. I am using a multi-faceted approach.

The above list is not a strict sequence, I am learning a little about each of the 3 top level areas each week. Progress, for me at least, is not particularly fast, which can be frustrating when you have projects in mind. Which is why the next point helps.

Keep a Learning Log

This has helped me to avoid the feeling that I’m not getting anywhere. It helps me see what to study and try out next. I abbreviate book titles.

I use a simple table in OneNote

Excerpt…

Date Notes
older Pckt RustIn7days, ch1, ch2 Got a bit stuck on Traits with Generics
2020-01-29 RBE ch1, ch2
2020-01-30 RBE ch3 skipped linked list example
  RBE ch4 variable shadowing. Not sure of the point!
  RBE ch5, ch6, ch7, ch8.3
2020-01-31 RBE ->8.5.1 Refs!! Destructuring. See also RB (RustBook) 4.1,4.2
2020-02-03 RBE 8.5.3, 8.6, 8.7 9, 9.1 Binding… didn’t really get it, but likely don’t need to!
  If…let - stupid syntax, blame Swift
  while…let skipped

I’ve seen lots of more complex Learning logs online, but for me, just a running virtual bookmark is enough. Notes may be a page or chapter reference. Sometimes I’ll note an immportant topic I convered. I’ll note any code I worked on. My log isn’t well written or consistent in its type of content. I don’t go into great detail about what I’ve learnt, it isn’t a summary. It is more to track progress.

I’ve found it a great help.

So that is my Rust learning story so far. I hope it helps!

Comments