Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STM32H7 SPI + Exti fixes + BMI088 driver #1052

Merged
merged 8 commits into from
Oct 5, 2023
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ Please [discover modm's peripheral drivers for your specific device][discover].
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center"></td>
<td align="center"></td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✅</td>
Expand Down Expand Up @@ -723,96 +723,97 @@ your specific needs.
<td align="center"><a href="https://modm.io/reference/module/modm-driver-block-device-spi-flash">SPI Flash</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-bme280">BME280</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-bmi088">BMI088</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-bmp085">BMP085</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-bno055">BNO055</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-cat24aa">CAT24AA</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-cycle_counter">CYCLE-COUNTER</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-drv832x_spi">DRV832X</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-drv832x_spi">DRV832X</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ds1302">DS1302</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ds1631">DS1631</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ds18b20">DS18B20</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ea_dog">EA-DOG</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_input">Encoder Input</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_input-bitbang">Encoder Input BitBang</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_input-bitbang">Encoder Input BitBang</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_output-bitbang">Encoder Output BitBang</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ft245">FT245</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ft6x06">FT6x06</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-gpio_sampler">Gpio Sampler</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hclax">HCLAx</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hd44780">HD44780</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hd44780">HD44780</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hmc58x">HMC58x</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hmc6343">HMC6343</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hx711">HX711</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-i2c-eeprom">I2C-EEPROM</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ili9341">ILI9341</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-is31fl3733">IS31FL3733</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-is31fl3733">IS31FL3733</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-itg3200">ITG3200</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ixm42xxx">IXM42XXX</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-l3gd20">L3GD20</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lan8720a">LAN8720A</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lawicel">LAWICEL</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis302dl">LIS302DL</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis302dl">LIS302DL</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis3dsh">LIS3DSH</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis3mdl">LIS3MDL</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lm75">LM75</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lp503x">LP503x</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lsm303a">LSM303A</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lsm6ds33">LSM6DS33</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lsm6ds33">LSM6DS33</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lsm6dso">LSM6DSO</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ltc2984">LTC2984</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-max31855">MAX31855</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-max31865">MAX31865</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-max6966">MAX6966</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-max7219">MAX7219</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-max7219">MAX7219</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp23x17">MCP23x17</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp2515">MCP2515</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp3008">MCP3008</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp7941x">MCP7941x</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp990x">MCP990X</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mmc5603">MMC5603</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mmc5603">MMC5603</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ms5611">MS5611</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ms5837">MS5837</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-nokia5110">NOKIA5110</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-nrf24">NRF24</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-parallel_tft_display">TFT-DISPLAY</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pat9125el">PAT9125EL</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pat9125el">PAT9125EL</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca8574">PCA8574</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9535">PCA9535</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9548a">PCA9548A</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9685">PCA9685</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-qmc5883l">QMC5883L</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sh1106">SH1106</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sh1106">SH1106</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s65">SIEMENS-S65</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s75">SIEMENS-S75</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sk6812">SK6812</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sk9822">SK9822</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ssd1306">SSD1306</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-st7586s">ST7586S</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-st7586s">ST7586S</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-st7789">ST7789</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-stts22h">STTS22H</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-stusb4500">STUSB4500</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sx1276">SX1276</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sx128x">SX128X</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tcs3414">TCS3414</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tcs3414">TCS3414</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tcs3472">TCS3472</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tlc594x">TLC594x</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp102">TMP102</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp12x">TMP12x</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp175">TMP175</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-touch2046">TOUCH2046</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-touch2046">TOUCH2046</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl53l0">VL53L0</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl6180">VL6180</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ws2812">WS2812</a></td>
Expand Down
102 changes: 102 additions & 0 deletions examples/nucleo_h723zg/bmi088/i2c/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright (c) 2023, Christopher Durand
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#include <modm/driver/inertial/bmi088.hpp>

#include <modm/board.hpp>
#include <atomic>

using namespace Board;

using I2c = I2cMaster1;
using Scl = GpioB8; // D15
using Sda = GpioB9; // D14

using AccInt1 = GpioC6;
using GyroInt3 = GpioB15;

using Transport = modm::Bmi088I2cTransport<I2c>;
using Imu = modm::Bmi088<Transport>;

constexpr uint8_t AccAddress = 0x18;
constexpr uint8_t GyroAddress = 0x68;
Imu imu{AccAddress, GyroAddress};

void initializeImu()
{
AccInt1::setInput(AccInt1::InputType::PullDown);
GyroInt3::setInput(GyroInt3::InputType::PullDown);

constexpr bool selfTest = true;
while (!imu.initialize(selfTest)) {
MODM_LOG_ERROR << "Initialization failed, retrying ...\n";
modm::delay(500ms);
}

bool ok = imu.setAccRate(Imu::AccRate::Rate12Hz_Bw5Hz);
ok &= imu.setAccRange(Imu::AccRange::Range3g);

const auto int1Config = (Imu::AccGpioConfig::ActiveHigh | Imu::AccGpioConfig::EnableOutput);
ok &= imu.setAccInt1GpioConfig(int1Config);
ok &= imu.setAccGpioMap(Imu::AccGpioMap::Int1DataReady);

ok &= imu.setGyroRate(Imu::GyroRate::Rate100Hz_Bw12Hz);
ok &= imu.setGyroRange(Imu::GyroRange::Range250dps);
ok &= imu.setGyroGpioConfig(Imu::GyroGpioConfig::Int3ActiveHigh);
ok &= imu.setGyroGpioMap(Imu::GyroGpioMap::Int3DataReady);

if (!ok) {
MODM_LOG_ERROR << "Configuration failed!\n";
}
}

int main()
{
Board::initialize();
Leds::setOutput();
I2c::connect<Scl::Scl, Sda::Sda>(I2c::PullUps::Internal);
I2c::initialize<Board::SystemClock, 100_kHz, 10_pct>();

MODM_LOG_INFO << "BMI088 I2C Test\n";
initializeImu();

std::atomic_bool accReady = false;
std::atomic_bool gyroReady = false;

Exti::connect<AccInt1>(Exti::Trigger::RisingEdge, [&accReady](auto){
accReady = true;
});

Exti::connect<GyroInt3>(Exti::Trigger::RisingEdge, [&gyroReady](auto){
gyroReady = true;
});

while (true)
{
while(!accReady or !gyroReady);

const std::optional accResult = imu.readAccData();
accReady = false;
const std::optional gyroResult = imu.readGyroData();
gyroReady = false;

if (accResult) {
const modm::Vector3f data = accResult->getFloat();
MODM_LOG_INFO.printf("Acc [mg]\tx:\t%5.1f\ty: %5.1f\tz: %5.1f\n", data[0], data[1], data[2]);
}
if (gyroResult) {
const modm::Vector3f data = gyroResult->getFloat();
MODM_LOG_INFO.printf("Gyro [deg/s]\tx:\t%5.2f\ty: %5.2f\tz: %5.2f\n", data[0], data[1], data[2]);
}
}

return 0;
}
14 changes: 14 additions & 0 deletions examples/nucleo_h723zg/bmi088/i2c/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<library>
<extends>modm:nucleo-h723zg</extends>
<options>
<option name="modm:build:build.path">../../../../build/nucleo_h723zg/bmi088_i2c</option>
<option name="modm:processing:protothread:use_fiber">yes</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:processing:fiber</module>
<module>modm:platform:exti</module>
<module>modm:platform:i2c:1</module>
<module>modm:driver:bmi088</module>
</modules>
</library>
103 changes: 103 additions & 0 deletions examples/nucleo_h723zg/bmi088/spi/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright (c) 2023, Christopher Durand
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#include <modm/driver/inertial/bmi088.hpp>

#include <modm/board.hpp>
#include <atomic>

using namespace Board;

using Spi = SpiMaster2_Dma<Dma1::Channel0, Dma1::Channel1>;
using CsGyro = GpioC0;
using CsAcc = GpioD6;
using Mosi = GpioC3;
using Miso = GpioC2;
using Sck = GpioD3;

using AccInt1 = GpioC8;
using GyroInt3 = GpioC9;

using Transport = modm::Bmi088SpiTransport<Spi, CsAcc, CsGyro>;
using Imu = modm::Bmi088<Transport>;
Imu imu;

void initializeImu()
{
AccInt1::setInput(AccInt1::InputType::PullDown);
GyroInt3::setInput(GyroInt3::InputType::PullDown);

constexpr bool selfTest = true;
while (!imu.initialize(selfTest)) {
MODM_LOG_ERROR << "Initialization failed, retrying ...\n";
modm::delay(500ms);
}
chris-durand marked this conversation as resolved.
Show resolved Hide resolved

bool ok = imu.setAccRate(Imu::AccRate::Rate12Hz_Bw5Hz);
ok &= imu.setAccRange(Imu::AccRange::Range3g);

const auto int1Config = (Imu::AccGpioConfig::ActiveHigh | Imu::AccGpioConfig::EnableOutput);
ok &= imu.setAccInt1GpioConfig(int1Config);
ok &= imu.setAccGpioMap(Imu::AccGpioMap::Int1DataReady);

ok &= imu.setGyroRate(Imu::GyroRate::Rate100Hz_Bw12Hz);
ok &= imu.setGyroRange(Imu::GyroRange::Range250dps);
ok &= imu.setGyroGpioConfig(Imu::GyroGpioConfig::Int3ActiveHigh);
ok &= imu.setGyroGpioMap(Imu::GyroGpioMap::Int3DataReady);

if (!ok) {
MODM_LOG_ERROR << "Configuration failed!\n";
}
}

int main()
{
Board::initialize();
Leds::setOutput();
Dma1::enable();
Spi::connect<Sck::Sck, Mosi::Mosi, Miso::Miso>();
Spi::initialize<Board::SystemClock, 9_MHz, 10_pct>();

MODM_LOG_INFO << "BMI088 SPI Test\n";
initializeImu();

std::atomic_bool accReady = false;
std::atomic_bool gyroReady = false;

Exti::connect<AccInt1>(Exti::Trigger::RisingEdge, [&accReady](auto){
accReady = true;
});

Exti::connect<GyroInt3>(Exti::Trigger::RisingEdge, [&gyroReady](auto){
gyroReady = true;
});

while (true)
{
while(!accReady or !gyroReady);

const std::optional accResult = imu.readAccData();
accReady = false;
const std::optional gyroResult = imu.readGyroData();
gyroReady = false;

if (accResult) {
const modm::Vector3f data = accResult->getFloat();
MODM_LOG_INFO.printf("Acc [mg]\tx:\t%5.1f\ty: %5.1f\tz: %5.1f\n", data[0], data[1], data[2]);
}
if (gyroResult) {
const modm::Vector3f data = gyroResult->getFloat();
MODM_LOG_INFO.printf("Gyro [deg/s]\tx:\t%5.2f\ty: %5.2f\tz: %5.2f\n", data[0], data[1], data[2]);
}
}

return 0;
}
15 changes: 15 additions & 0 deletions examples/nucleo_h723zg/bmi088/spi/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<library>
<extends>modm:nucleo-h723zg</extends>
<options>
<option name="modm:build:build.path">../../../../build/nucleo_h723zg/bmi088_spi</option>
<option name="modm:processing:protothread:use_fiber">yes</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:processing:fiber</module>
<module>modm:platform:dma</module>
<module>modm:platform:exti</module>
<module>modm:platform:spi:2</module>
<module>modm:driver:bmi088</module>
</modules>
</library>
Loading
Loading