Reducing power consumption when sd card is unmounted

Our custom development board uses an nrf52840 chip together with attached sensors. The data from sensors are stored in sd card. For this purpose, the Zephyr fs library is used. In general, sensors' data are written into sd card successfully. The sd card is unmounted after the writing procedure by calling the fs_unmount function. I would assume that the power consumption should be reduced to a level equal to the initial value but this does not happen. It seems that sd card pins remain in the high state.

I found a similar problem (devzone.nordicsemi.com/.../383088but in this case, nrfx SPIM driver was used instead of Zephyr.

I was trying to define the spi instance based on sdhc0 node and then I could call the spi_release method. The spi release method seems to not work as an uninitialized method in nrfx SPIM driver. To conclude, I would like to turn off FS driver without extra power consumption after the writing procedure is completed.

Samo

Parents
  • I try to implement your suggestion by using device runtime API. Here is my overlay file:

    &spi0 {
    
        compatible = "nordic,nrf-spi";  
        status = "okay";
       
        pinctrl-0 = <&spi0_default>;
        pinctrl-1 = <&spi0_sleep>;
        pinctrl-names = "default", "sleep";   
        cs-gpios = <&gpio0 13 GPIO_ACTIVE_LOW>,
                   <&gpio1 6 GPIO_ACTIVE_LOW>,
                   <&gpio0 12 GPIO_ACTIVE_LOW>,
                   <&gpio0 15 GPIO_ACTIVE_LOW>;
       
       ...
        sdhc0: sdhc@3 {        
            compatible = "zephyr,sdhc-spi-slot";
            reg = <3>;
            status = "okay";
           
            mmc {
                compatible = "zephyr,sdmmc-disk";
                status = "okay";
            };
            spi-max-frequency = <1000000>;
        };    
    };

     in sd_card.h I have the following define:
    #define SPI0_DEVICE_ID  DT_NODELABEL(spi0)
    and in sd_card.c
    struct device* spi0_device = DEVICE_DT_GET(SPI0_DEVICE_ID);
    bool sd_card_ctor(void)
    {
    
     return pm_device_runtime_enable(spi0_device) == 0;
    }
    void sd_card_init(void)
    {  
        if(pm_device_runtime_get(spi0_device) == 0)
            printk("OK PM\n");
    
        int res = fs_mount(&mp);    
    
        if (res == FR_OK)
        {      
            printk("Disk mounted.\n");
            fs_file_t_init(&fs_file);      
        }
        else
        {
            printk("Error mounting disk.\n");        
        }
    }
    
    void sd_card_close_file(void)
    {
        int res = fs_close(&fs_file);
    
        if (res == FR_OK)
        {
            //printk("FS close.\n");        
        }
        else
        {
            printk("FS close error\n");        
        }
    
        res = fs_unmount(&mp);  
    
        if (res == FR_OK)
        {
            printk("Disk unmounted.\n");        
               
        }
        else
        {
            printk("Error unmounting disk.\n");        
        }
       
       
        if(pm_device_runtime_put(spi0_device) == 0)
            printk("OK PM\n");
    }
    When sd_card_close_file is called the power consumption does not decrease to the initial value but starts even increasing.
    I do not know what I am doing wrong. I would appreciate any help.
  • Hi!

    control said:
    When sd_card_close_file is called the power consumption does not decrease to the initial value but starts even increasing.

    Do you have any logs from this?

    Did pm_device_runtime_put(spi0_device) return 0 ?

    What does pm_device_runtime_is_enabled(spi0_device) return ?

Reply Children
Related