Skip to content

Commit 242d690

Browse files
Concode0finger563Copilot
authored
fix(bmi270): make burst write size configurable (#566)
* fix(bmi270): make burst write size configurable to prevent stack overflow * fix: change default burst size to 0 * Update components/bmi270/include/bmi270.hpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update components/bmi270/include/bmi270.hpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @finger563 --------- Co-authored-by: William Emfinger <waemfinger@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent ea6e470 commit 242d690

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

components/bmi270/include/bmi270.hpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ 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. If 0 will use full config file size of 8192 bytes.
90+
* Default is 0 (uses full config file size of 8192 bytes).
91+
* Set this to a small non-zero value (e.g., 128) if you encounter stack overflow or want to decrease memory usage.
92+
*/
93+
uint16_t burst_write_size = 0;
8894
bool auto_init{true}; ///< Automatically initialize the BMI270
8995
Logger::Verbosity log_level{Logger::Verbosity::WARN}; ///< Log level
9096
};
@@ -94,7 +100,8 @@ class Bmi270 : public espp::BasePeripheral<uint8_t, Interface == bmi270::Interfa
94100
explicit Bmi270(const Config &config)
95101
: BasePeripheral<uint8_t, Interface == bmi270::Interface::I2C>({}, "Bmi270", config.log_level)
96102
, orientation_filter_(config.orientation_filter)
97-
, imu_config_(config.imu_config) {
103+
, imu_config_(config.imu_config)
104+
, burst_write_size_(config.burst_write_size == 0 ? config_file_size : config.burst_write_size) {
98105
if constexpr (Interface == bmi270::Interface::I2C) {
99106
set_address(config.device_address);
100107
}
@@ -565,9 +572,9 @@ class Bmi270 : public espp::BasePeripheral<uint8_t, Interface == bmi270::Interfa
565572
}
566573

567574
// upload config file:
568-
// - burst write 8 kB init data to INIT_DATA, using 128-byte writes
575+
// - burst write init data to INIT_DATA, using configurable chunk size (defaults to 8 kB)
569576
const uint8_t *config_data = config_file;
570-
size_t burst_size = config_file_size;
577+
size_t burst_size = burst_write_size_;
571578
size_t config_size = config_file_size;
572579
size_t offset = 0;
573580
while (offset < config_size) {
@@ -706,6 +713,7 @@ class Bmi270 : public espp::BasePeripheral<uint8_t, Interface == bmi270::Interfa
706713
// Member variables
707714
filter_fn orientation_filter_{nullptr};
708715
ImuConfig imu_config_{};
716+
uint16_t burst_write_size_{0};
709717
Value accel_values_{};
710718
Value gyro_values_{};
711719
float temperature_{0.0f};

0 commit comments

Comments
 (0)