nRF5340 DK: fuel gauge MAX17048 driver

Hi Support team,


I want to try the fuel gauge MAX17048 on nRF5340 DK, and I'm confused with the driver and samples, could you help give me some guidance?


There is a MAX17048 driver in zephyr/drivers/fuel_gauge/max17048. And there is a sample \ncs\v2.5.0\zephyr\samples\fuel_gauge\max17048\. This sample is compliable on my computer, but it did not include the above driver, it included '#include <zephyr/drivers/fuel_gauge.h>', but in the above driver folder, there is no file 'fuel_gauge.h'.

My questions:
1. Does this sample use the driver 'zephyr/drivers/fuel_gauge/max17048', if does, where does it link the specific API like 'max17048_get_prop' to the common API 'fuel_gauge_get_prop()'?
2. If I want to use the driver 'zephyr/drivers/fuel_gauge/max17048', what configuration should be enabled in prj.conf? I see there is below in the documentation:

            

         But in the sample, it only config 'CONFIG_FUEL_GAUGE=y' in prj.conf.
3. I see there is another sample MAX17048 Li-Ion battery fuel gauge, but I can not find the sample code, could you tell me where can I find it?

My purpose is to use the driver 'zephyr/drivers/fuel_gauge/max17048', because I believe it is the latest one and the easiest way to drive MAX17048, is it right? Could you help provide a sample for how to configure and use this driver?

Thank you very much.

Best regards,
Yanpeng Wu

  • Hi.

    The fuel_gauge.h header is generic (not HW specific), it is located in the include folder here:
        zephyr/include/zephyr/drivers/fuel_gauge.h

    1&2. Yes the sample uses the driver.
        To select the correct driver for your HW you need to include the MAX17048 device in your overlay.
        The correct driver will be picked up automatically.
        see the example in the sample here:
        zephyr/samples/fuel_gauge/max17048/boards/nrf52840dk_nrf52840.overlay at 9bfe6efbb5ad7c1d7a7567660c0ba7caaf3ff972 · zephyrproject-rtos/zephyr (github.com)

        I also recommend you familiarise yourself with the device driver model documentation which explains how this works.
        Device Driver Model — Zephyr Project Documentation

    3.  That documentation refers to the same sample, there isn't another one.

    Andy


  • Hi Andy,

    Thanks for your reply, now I understand the driver has the generic layer and the HW-specific implementation, and I will read the device model documentation further.

    The last question is in the zephyr/drivers/fuel_gauge/max17048/max17048.c:

    line 291:
    static const struct fuel_gauge_driver_api max17048_driver_api = {
    	.get_property = &max17048_get_props,
    };

    But in \zephyr\include\zephyr\drivers\fuel_gauge.h:

    line 283:
    __subsystem struct fuel_gauge_driver_api {
    	fuel_gauge_get_property_t get_property;
    	fuel_gauge_set_property_t set_property;
    	fuel_gauge_get_buffer_property_t get_buffer_property;
    	fuel_gauge_battery_cutoff_t battery_cutoff;
    };

    Seems the driver implementation of MAX17048 only provides the get_property method, not the set_property. if need to set something like the ones defined in the generic zephyr/include/zephyr/drivers/fuel_gauge.h as below, what's the best way to do this? Thank you very much.

    struct fuel_gauge_set_property {
    	/** Battery fuel gauge property to set */
    	fuel_gauge_prop_t property_type;
    
    	/** Negative error status set by callee e.g. -ENOTSUP for an unsupported property */
    	int status;
    
    	/** Property field for setting */
    	union {
    		/* Fields have the format: */
    		/* FUEL_GAUGE_PROPERTY_FIELD */
    		/* type property_field; */
    
    		/* Writable Dynamic Battery Info */
    		/** FUEL_GAUGE_SBS_MFR_ACCESS */
    		uint16_t sbs_mfr_access_word;
    		/** FUEL_GAUGE_SBS_REMAINING_CAPACITY_ALARM */
    		uint16_t sbs_remaining_capacity_alarm;
    		/** FUEL_GAUGE_SBS_REMAINING_TIME_ALARM */
    		uint16_t sbs_remaining_time_alarm;
    		/** FUEL_GAUGE_SBS_MODE */
    		uint16_t sbs_mode;
    		/** FUEL_GAUGE_SBS_ATRATE */
    		int16_t sbs_at_rate;
    	} value;
    };

  • Hi.

    set_prop is not currently supported for the MAX17048.
    To add support for this, the driver will need to be updated (new function in max17048.c).

    You can see an example in the sbs driver here:
    sdk-zephyr/drivers/fuel_gauge/sbs_gauge/sbs_gauge.c at e4511cfcb7a672ca1bb0d6296dc257df6af0b12f · nrfconnect/sdk-zephyr (github.com)

    Depending on your use case, it may be easier for you to use a raw register write in your startup code instead, as modifying drivers is pretty complicated, especially if you are unfamiliar with the Zephyr ecosystem.

    Andy

  • Thanks for the suggestion. The sample (\ncs\v2.5.0\zephyr\samples\fuel_gauge\max17048\) is built for nrf52dk_nrf52832, I ported the code and built on nRF5340DK, with the identical code, but read 4 values with 0.

    In the max17048_get_props() in MAX17048.c, only when (crate != 0) the below code was called:

    		for (int i = 0; i < len; i++) {
    			int ret = max17048_get_prop(dev, props + i);
    
    			err_count += ret ? 1 : 0;
    		}


    With this, when my battery is fully charged(crate == 0), the read value of SoC and voltage are zero, but they should not be. Is this a bug? I am just curious if the driver has been fully tested. Thank you very much.

  • Hello,

    We do not have any guidelines how MAX17048 chip works. You need to contact the manufacturer of this chip. 

Related