/stm32c0-metapac-example

Me figuring out how to use stm32-metapac on the stm32c0

Primary LanguageRustMozilla Public License 2.0MPL-2.0

Basic stm32-metapac / stm32c0 example

I'm trying to use some STM32C0 parts in designs, and the stm32-rs crate I normally turn to is lacking support. Adding it turned out to rub me up against all the parts of the crate I like least -- editing diffs to try to describe the thing I want, instead of just describing it.

So I got very excited to find stm32-metapac, which uses a diferent approach (and not svd2rust even!). However, it has ... essentially no docs at the time of this writing, and I can't find any worked examples online that use a recent version of the crate.

So, I have stumbled my way through writing one so you don't have to.

This is tested on an STM32C011F6 board of my own design with an LED on PA8. If you want to blink a different pin, change the 8s.

Notes on programming the STM32C0

  • STM32C0 support was added to OpenOCD after the 0.12 release, so you will need it built from git. I used the openocd-git AUR package on Arch. If you've used OpenOCD for any length of time, you'll be accustomed to having to build it from git. :-)

  • The C0 series picked up the same odd behavior from the G0 series, where the EMPTY bit in the flash controller -- used to determine if there's code worth booting in the flash -- seems not to get re-evaluated at reset, and only at power-on. This means the very first time you program an STM32C0, if you reset it, it will bounce right back into the ROM like it's not programmed. To fix this, power cycle it. This is only necessary when starting with a factory-fresh part.

  • Remember to mux your dual-function pins correctly in SYSCFG.