STM32 toolchain/libraries (Thinkpad EC)?

Hi, if somebody could help me save some time on research.. I'd like to

  • program an STM32F072 board I have
  • do it in Rust if practical
  • do it on Ubuntu if practical
  • I'm waiting for an ST-Link V2 clone to arrive

The task is quite grandiose

  • service Thinkpad T60 keyboard, convert it a USB keyboard
  • talk to Thinkpad trackpoint over PS2 and convert it to a USB mouse
  • talk to Synaptic trackpad over PS2 and convert it to a USB mouse
  • control a bunch of on/off things like LED-s etc
  • control display backlight brightness (issue PWM signal)
  • (optional) use one of keyboard buttons - On/Off as an actual on/off - listen to presses when asleep, wake up and switch the system on if pressed; switch system off if pressed
  • (optional) talk to Thinkpad T60 smart battery over SMBus (similar to I2C)
  • (optional) present a new USB device which can be queried about the battery status etc

As you can see it's a new "embedded controller" to live within Thinkpad T60 or R60 body, possibly X201 body. Then there'd be a single board computer like Raspberi PI 4 to connect to it over USB and a separate power cable. HDMI->LVDS converter will be a separate further step. (Some more details on the idea.)

So this thing would need to present 3-4 USB devices over the USB interface that STM32F072 presumably has. Talking to 2 separate PS/2 devices may turn out to be a challenge too - perhaps the software would need to "bit-bang" PS/2 interface or two.. This thing would need to do multiple things simultaneously - cooperative multi-tasking would be very good.


  • does it sound doable at all?
  • does Rust sound like a good language to do it?
  • is Ununtu a good operating system to use for development?

I expect the answers are "yes", so further questions

  • what software do I need?
  • any IDE?
  • any good links to get me up to speed?
  • what libraries should I learn?

I have come accross today but I'm not sure if that is the best/only option. Also please do feel free to tell me I should go back to C because it's got better librarires/tooling - I really don't mind.

Extra questions:

  • how do you folks debug these toys?
  • would implementing a serial console over one of the legs of STM32 for outputting log be a sane idea? what hardware do I connect to it? Some extra USB<->serial thingie? Any links?..

Finally if anybody feels like cooperating on this rather long-haul project of planting a Raspberi PI 4 compute module - or another single board computer - into classic Thinkpad bodies (R60/T60/T61/X200 era) please do ping me :slight_smile:

P.S. I'm aware of these links: 1 2 3 4 on converting Thinkpad keyboards to USB, i also have some links on PS/2 5 6 7 8 9 10, I have sort of found most of the connectors I need apart from 5353190-6 for the display cable; I'm just about literate enough on electronics and holding my soldering gun; the initial plan is to use toner transfer method and ferric chloride transfer method to make the PCB-s; final plan is to order required boards from China

P.P.S. I will probably need a website for this project and some other venue for discussions - in case I do find some collaborators.. It's obviously going to be open source, though not sure which license at this point yet. Maybe a github repo with wiki?..

It is certainly possible to do it in Ubuntu. I'd suggest the following for now:

Install STMCubeIDE. This comes packaged with a CubeMX plugin. CubeMX is a GUI frontend for setting up and configuring peripherals, etc. and a code generator generating the code to do so.

Then use STM32F0 HAL. It's a C library, but I find it quite easy to use. It is relatively well supported and is integrated in CubeMX.

If you need multitasking, you can use the FreeRTOS real-time operating system middleware directly from CubeMX as well.

Alternatively, you can try to use ARM Mbed with the chip, but I don't know how well-supported it is. You'll also have to do more to get debugging with breakpoints working. With CubeIDE and STM32F0 HAL it's super simple.

Rust doesn't have that good support or tooling yet for STM32. The CubeMX code generator and config tool really is brilliant and not something I'd give up yet. If you feel adventurous, you can try using the STM32F0xx HAL crate, but you'll have to figure out some stuff first. And you'll not get as much info online if you run into problems.

Thanks a bunch for all your advises, much appreciated. First question: I actually purchased a couple of STM32F072 boards because they were cheaper but eventually I was hoping to transition to smth like this STM32L476 board - primarily because L chips promise even lower power consumption. Should I be concerned about F0 being part of both C library name and Rust crate name? Are there separate libraries/crates for STM32L4? Would I be able to simply re-use the code?

As a separate question, somehow I don't trust USB that much for uploading code, that is why I've ordered that ST-Link V2 clone. I understand ST-Link V2 connects to 4 separate pins on the STM32 board. But how do you debug?.. Is it also done via those pins? Or via USB?

I have almost exclusive experience with the STM32L476, so I can tell you it's a beast and consumes almost nothing (< 10 mA). And it's running at 80MHz, so it's probably faster than your F0 chip as well...

You should be able to directly re-use the C code directly if you:

  1. don't fiddle directly with registers
  2. don't use HAL functions whose names start with HAL_PPPEx

ST implements a HAL for each family, so you'd use the F0xx hal and the L4xx hal. The functions for e.g. sending uart data has exactly the same names and parameters between the two HAL implementations. They are meant to be interchangeable between families.

However, each family's HAL also contain extension APIs to access each family's advanced/unique features, which has the Ex in the function name. These aren't guaranteed to be portable.

On the Rust side, there exists an embedded-hal crate which defines traits to be implemented by specific libraries. It looks like they are implemented for both (STM32L4 link), so you should be able to swap out chips without problem if you go the Rust route as well.

It is done via the ST-LINK pins as well. I don't know how good the support for debugging is on the Rust side, though. But on the STM32 HAL side and in CubeIDE, you can set breakpoints and step through your code and inspect registers just as easily as you'd do it in a desktop program via a good IDE's GUI debugger.

Give a look at, the embedded rust book, the discovery book and join the matrix channel of embedded rust to ask your questions. All of your goals can be achieved with the Rust HALs we hfalready have (however, as @L0uisc told you already, you'll probably find more informations when using C).

Great to know, I will look into each and every one of the things you pointed to. Before I get on Matrix..

  • what would I base my cooperative multi-tasking on? ? Something else?
  • what should I consider as an IDE under Ubuntu for this? I'd probably prefer something closer to regular GNU or Rust toolchain in preference to STM32Cube and I'm not entirely opposed to vim but still?


I use Emacs, but basically you can use any editor you like. I think VSCode has the best support.
The advantage of STCube is its CubeMX to configure the MCU. I for myself generate the setup using CubeMX and port it then to Rust (e.g. Clock settings, ...), which does not work for all peripherals (but at least for the clock). is in my opinion atm the best framework for multi-tasking using Rust on Embedded.

Take a look at following crates:

Not all of them are developed as far, but I think they are usable. Also look at their examples on github (and the changes on github, sometimes is not updated for quite some time).

Maybe you should take a look on the Rust nRF52-HAL, to see how is integrated.
Then there is an USB-Serial example in the stm32f0xx-hal crate, which you can combine with the example in usbd-hid.

1 Like

You might be interested in GitHub - jannic/pikvm-hid-stm32: A firmware for an alternative HID adapter for PiKVM, using an stm32 microcontroller.
It implements a converter from a Pi-KVM specific serial protocol to a USB keyboard and mouse, using many of the crates suggested in this thread, like stm32f1xx-hal, cortex-m-rtic, usbd-hid-device etc.
(Just a proof of concept - please don't expect too much.)

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.