I’ve started like this, porting core ODrive algorithm to ivory-tower framework in Haskell which can be used to generate safe C-code. You can find my effort at https://github.com/distrap/lambdadrive/ (I’ve started with early version of ODriveFirmware where it was quite possible to “extract” (or reverse engingeer) the core parts of BLDC firmware. With Oscars help and bunch of time spent studying BLDC control I’ve managed to port parts of the algorithm. My port can only do voltage controlled FOC while current control is still in the works. Compared to where ODrive is/was heading lambdadrive uses CAN bus and CANOpen as a communication protocol and aims to run single motor only.
This “lets-try-to-port-this” project evolved into creating a whole RepRap like project called DistRap for distributed rapid prototyping where nodes use CAN/CANOpen for communication to allow for scalability beyond single microcontroller control boards. I’ve used ODrive as a prototyping platform and now I’m experimenting with my own set of boards based on STM32F7s. Beyond servo control I’m also working on stepper and IO nodes - the very first actually useful DistRap project is a CANOpen driven reflow oven.
I would say that implementing a complete FOC is quite difficult even when porting such code. If you decide to go for it you can start implementing parts of the algorithm and then integrate these into complete FOC. For example you can easily drive BLDC with only advanced timer in 6PWM mode. Add DRV8301 SPI driver and you can test on actual ODrive board. The rest is way harder though and involves encoder, clarke/parke transforms and SVM.
While doing this I’ve realized that this little-known frawework has tons of potential (even compared to the embedded rust) so I’m currently writing book about it and adding a support for whole STM32 family. Sorry for hijacking this thread a bit, I really need to start my own blog|thread :).