Skip to content

Commit 9acdfb3

Browse files
committed
fix(bmi270): make burst write size configurable to prevent stack overflow
1 parent ea6e470 commit 9acdfb3

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

components/bmi270/include/bmi270.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ class Bmi270 : public espp::BasePeripheral<uint8_t, Interface == bmi270::Interfa
8585
nullptr; ///< Read function
8686
ImuConfig imu_config; ///< IMU configuration
8787
filter_fn orientation_filter = nullptr; ///< Filter function for orientation
88+
/**
89+
* @brief Maximum number of bytes to write in a single burst during config upload.
90+
* Default is 128 bytes. Decrease this if you encounter stack overflow.
91+
*/
92+
uint16_t burst_write_size = 128;
8893
bool auto_init{true}; ///< Automatically initialize the BMI270
8994
Logger::Verbosity log_level{Logger::Verbosity::WARN}; ///< Log level
9095
};
@@ -94,7 +99,8 @@ class Bmi270 : public espp::BasePeripheral<uint8_t, Interface == bmi270::Interfa
9499
explicit Bmi270(const Config &config)
95100
: BasePeripheral<uint8_t, Interface == bmi270::Interface::I2C>({}, "Bmi270", config.log_level)
96101
, orientation_filter_(config.orientation_filter)
97-
, imu_config_(config.imu_config) {
102+
, imu_config_(config.imu_config)
103+
, burst_write_size_(config.burst_write_size) {
98104
if constexpr (Interface == bmi270::Interface::I2C) {
99105
set_address(config.device_address);
100106
}
@@ -567,7 +573,7 @@ class Bmi270 : public espp::BasePeripheral<uint8_t, Interface == bmi270::Interfa
567573
// upload config file:
568574
// - burst write 8 kB init data to INIT_DATA, using 128-byte writes
569575
const uint8_t *config_data = config_file;
570-
size_t burst_size = config_file_size;
576+
size_t burst_size = burst_write_size_;
571577
size_t config_size = config_file_size;
572578
size_t offset = 0;
573579
while (offset < config_size) {
@@ -706,6 +712,7 @@ class Bmi270 : public espp::BasePeripheral<uint8_t, Interface == bmi270::Interfa
706712
// Member variables
707713
filter_fn orientation_filter_{nullptr};
708714
ImuConfig imu_config_{};
715+
uint16_t burst_write_size_{128};
709716
Value accel_values_{};
710717
Value gyro_values_{};
711718
float temperature_{0.0f};

0 commit comments

Comments
 (0)