Bosch BNO055 is 9-axis orientation sensor with 3-axis gyro, 3-axis accelerometer and 3-axis magnetometer. It's smart sensor, that support sensor fusion and self-diagnostics. We made a library to use it with STM32 micro-controllers.
There is official library from Bosch written in C, but it does not play nice with STM32. There are also a lot of C++ libraries, that works well with ESP32, but don't support STM32 (no default C++ support). We decided to write library as platform independent code with addition of STM32 adaptation. Main code based on different libraries, like ShellAddicted's ESP32 BNO055 library, but ported to C language.
We needed only roll, pitch and heading, so we wrote it in the first place, but adding other sensor values are easy. If you want to test the library, you will need STCubeMX and IAR (demo) to build simple project. Here is how to do it.
Open STCubeMX and create new project. Select board or chip. I used STM32F103C8T6 in my avionics project and will show periphery configuration as example. Here is the minimal settings you need to configure:
Optionally you can select clock speed, but it's not required. In Project Manager tab select project name and directory. Select preferred IDE (all of them are bad, even Makefile), I will use EWARM (IAR). Click save and Generate Code and open project.
Go to the github page https://github.com/ivyknob/bno055_stm32 and download 3 files:
Copy all files above to your project. Using IAR as example, you need to copy header files to ./Core/Inc and bno055.c to ./Core/Src and then add file with right click on Application -> User -> Core in project tree and Add -> Add files ... (select bno055.c).
Open main.c and add necessary code:
In USER CODE BEGIN Includes code block add:
#include "bno055_stm32.h"
In USER CODE BEGIN 2 code block add:
bno055_assignI2C(&hi2c1);
bno055_setup();
bno055_setOperationModeNDOF();
After USER CODE END WHILE add:
bno055_vector_t v = bno055_getVectorEuler();
printf("Heading: %.2f Roll: %.2f Pitch: %.2f\r\n", v.x, v.y, v.z);
HAL_Delay(1000);
Build, upload and rock'n'roll. If you set up serial wire debug and have it in you STLink, you will see values from the gyro in Terminal IO.
Feel free to report issues on the github.