diff --git a/drivers/sensors/Kconfig b/drivers/sensors/Kconfig index d31a500d7c..3cd778d530 100644 --- a/drivers/sensors/Kconfig +++ b/drivers/sensors/Kconfig @@ -232,6 +232,14 @@ config SENSORS_BMI270_SPI endchoice +config SENSORS_BMI270_LOAD_FROM_HEAP + bool "BMI270 config loading from heap memory" + default n + ---help--- + Enable support to load the configuration data from heap memory. + Some chips can not do DMA transfer from FLASH and therefore + it is necessary to transfer the configuration file to RAM. + endif config SENSORS_BMP180 diff --git a/drivers/sensors/bmi270.c b/drivers/sensors/bmi270.c index 59686150e4..cbaf5de2f5 100644 --- a/drivers/sensors/bmi270.c +++ b/drivers/sensors/bmi270.c @@ -1258,9 +1258,11 @@ static int bmi270_init_seq(FAR struct bmi270_dev_s *priv) bmi270_putreg8(priv, BMI270_INIT_CTRL, 0); +#ifdef CONFIG_SENSORS_BMI270_LOAD_FROM_HEAP + /* Copy configuration to RAM */ - tmp = malloc(sizeof(g_bmi270_config_file)); + tmp = kmm_malloc(sizeof(g_bmi270_config_file)); if (tmp == NULL) { snerr("Failed to allocate memory for configuration file\n"); @@ -1269,12 +1271,24 @@ static int bmi270_init_seq(FAR struct bmi270_dev_s *priv) memcpy(tmp, g_bmi270_config_file, sizeof(g_bmi270_config_file)); +#else + + /* Transfer directly from const data memory */ + + tmp = (FAR uint8_t *)&g_bmi270_config_file; + +#endif + /* Load configuration - start with byte 0 */ bmi270_putregs(priv, BMI270_INIT_DATA, tmp, sizeof(g_bmi270_config_file)); +#ifdef CONFIG_SENSORS_BMI270_LOAD_FROM_HEAP + kmm_free(tmp); +#endif + /* Complete config load INIT_CTRL=0x01 */ bmi270_putreg8(priv, BMI270_INIT_CTRL, 1);