Posts

Showing posts from October, 2022

Mixing C++ and Rust on a small embedded system

  This has been one of my pet project for some times now, mixing lnArduino  drivers ( hardwired to STM32F1 / GD32VF1 *AND* FreeRTOS) with  rust code. Why ? Because rust is fun :). There are a lot of gotchas, your mileage may varies, you may disagree with me. Below is the current status, in case it helps others.  I do not pretend to bring you the "truth"/"the right way to do it", this is just my journey so far. Building with cmake Corrosion  is a very nice project , that makes mixing Cargo based project and cmake project a breeze.  . Really no problem here. Interworking Calling C++ from rust and conversely is a bit hit & miss. The current setup i'm using is to use bindgen to generate a first layer of rust binding  AND THEN , on top of that, manually write  a very thin rust wrapper to get rid of the unsafe {}, have a cleaner API, and add the missing pieces. For example, bindgen cannot deal with pure virtual c++ function, so you have to add a intermediate layer