This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 60364d7c72d80aa9a91211aeafd0bd312e3b1dd4
Author: SPRESENSE <[email protected]>
AuthorDate: Tue Aug 29 19:55:23 2023 +0900

    drivers/sensors/bmi270: Enable to select config memory
    
    Allow to transfer the BMI270 configuration data directly, and
    provide an option to use the heap memory if it cannot transfer
    directly.
---
 drivers/sensors/Kconfig  |  8 ++++++++
 drivers/sensors/bmi270.c | 16 +++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)

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);

Reply via email to