DA14681 goes into hibernation but after 2 wakeups it do not go again?

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.xmece.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
16 posts / 0 new
Last post
mahmed106
Offline
Last seen:2 weeks 6 days ago
Joined:2019-05-03 17:28
DA14681 goes into hibernation but after 2 wakeups it do not go again?

Hi dialog

I am working on custom board based on DA1468x i am using command

pm_resume_sleep();
pm_set_sleep_mode(pm_mode_hibernation);

to put it in hibernation. It goes into hiberanation and wakeups with external GPIO interrupt but after waking up 2 times it do not go into hibernation.

Is it related to that logic that hibernation mode is for ship devices to customer . When customer on the device then this piecce of code is disabled?

Is my understanding right?

Keywords:
Device:
PM_Dialog
Offline
Last seen:22 hours 20 min ago
Staff
Joined:2018-02-08 11:03
Hi mahmed106,

Hi mahmed106,

Can you please indicate where you are using the pm_resume_sleep() and the pm_set_sleep_mode() APIs? In order to put the device in hibernation mode, you should use the pm_set_sleep_mode(pm_mode_hibernation). Be aware that hibernation mode is a special mode to be used for shipping the final product to market without draining the battery. This is what is used for shipping and storing the final product and I would not recommend you the hibernation for development or debugging scopes. So, if your product is not for shipping, g I would suggest you to use the sleep mode as extended sleep into the system_init() and the reason is that when the system wakes up from the hibernation, the system resets and runs from the start. This is not a software reset, it’s like a hardware reset, so the system will run the code from the start and the system_init() will be executed again (every time that the 680 wakes up from the hibernation. Also, the pm_resume_sleep will Restore the sleep mode of the system, which has been blocked via a call to pm_stay_alive()If you could provide more inputs regarding this issue, it would be very helpful.

Thanks, PM_Dialog

mahmed106
Offline
Last seen:2 weeks 6 days ago
Joined:2019-05-03 17:28
I have understood that

我已经明白producti冬眠on shipping purposes , but i want to add a feature in my device to hibernate it when battery reaches a certain voltage and then wakes it up when charger is connected, which can be detected via GPIO.

I just want the method to implement this.

Thanks

PM_Dialog
Offline
Last seen:22 hours 20 min ago
Staff
Joined:2018-02-08 11:03
Hi mahmed106,

Hi mahmed106,

Can you please indicate where in you code you are using the pm_set_sleep_mode(pm_mode_hibernation)? As you mentioned in your initial post, the device can enter the hibernation mode. But what is happening after the 2 wakes up? Can you please provide me some extra inputs?

Thanks, PM_Dialog

mahmed106
Offline
Last seen:2 weeks 6 days ago
Joined:2019-05-03 17:28
Right after i enter pxp

我使用pxp_reporter和后进入pxp_reporter task ,, i check the VBAT voltage using ADC and then i use these two commands.

pm_resume_sleep();
pm_set_sleep_mode(pm_mode_hibernation);

And i need to ask that for entering hibernation mode two conditions need to met

1 - System must enter sleep mode

2 - VBAT must be low than dg_configBATTERY_LOW_LEVEL

?

PM_Dialog
Offline
Last seen:22 hours 20 min ago
Staff
Joined:2018-02-08 11:03
Hi mahmed106,

Hi mahmed106,

Since you are using battery in you design, if the voltage underflow, the system will automatically go into the hibernation mode. Looking at the SDK, the only place where the voltage level of the attached battery in monitored, is in apply_wifi() routine in sys_power_mgr.c file. Please search for the “Voltage underflow check” comment. If the battery voltage is too low (under dg_configBATTERY_LOW_LEVEL), the usb_charger_is_battery_low() will return true. To do so, if low_vbat is true, the current sleep mode will be changed to hibernation. Looking at the FreeRTOSConfig.h file the configPRE_STOP_PROCESSING() macro is empty, so you can hook you own functionality here. Please check the following implementation in order to declare a hook function:

In custom_config_qspi.h file, declare the battery voltage threshold as well as the battery type:

#define dg_configBATTERY_LOW_LEVEL (4000) // Set a threshold higher to power supply

#define dg_configBATTERY_TYPE (BATTERY_TYPE_CUSTOM)

In FreeRTOSConfig.h file declare your hook function. For instance:

#define configPRE_STOP_PROCESSING( x ) my_custom_callback_low_battery( x )

In the file of your choice, for instance in main.c, declare your hook function.

In apply_wifi() routine in sys_power_mgr.c file, modify the configPRE_STOP_PROCESSING macro accordingly:

if (sleep_period == 0) {

// A user definable macro that allows application code to be added.

configPRE_STOP_PROCESSING(pm_current_sleep_mode); // Pass in the argument(s) of your choice

} else {

// A user definable macro that allows application code to be added.

configPRE_SLEEP_PROCESSING( sleep_period );

}

The condition (vbat_level < dg_configBATTERY_LOW_LEVEL) is true and thus, the device enters hibernation mode. Please note that there should not be any charger plugged-in (on VBUS) in order for the device to enter hibernation mode. If you are using the hibernation mode by yourself, if you have BLE activity or any other pending interrupts, the system will not be able to go into hibernation.

Thanks, PM_Dialog

mahmed106
Offline
Last seen:2 weeks 6 days ago
Joined:2019-05-03 17:28
Thanks alot dialog.

Thanks alot dialog.

I ll implement it , if any problem comes i ll reply to this post.

mahmed106
Offline
Last seen:2 weeks 6 days ago
Joined:2019-05-03 17:28
I have tried above method but

I have tried above method but system is not entering sleep.

So what i have done is that i have used this piece of code which check VBAT after every 6 sec and if VBAT is low that recommended voltage. It enters sleep.

Problem with this method was that i need to wait 2-3 secs to put system in hibernaton else it goes into hibernation and restarts.

g_VBAT_check_counter++;
if(g_VBAT_check_counter>=10)
{
battery_source bat = ad_battery_open();
raw_vbat = ad_battery_raw_to_mvolt(bat, ad_battery_read(bat));
if(raw_vbat<=3000)
{
printf("\nHibernating\n");
fflush(stdout);

sys_watchdog_notify(wdog_id);
OS_DELAY_MS(2000); // Do everything and get free
pm_resume_sleep();
pm_set_sleep_mode(pm_mode_hibernation);
}
g_VBAT_check_counter=0;
}

PM_Dialog
Offline
Last seen:22 hours 20 min ago
Staff
Joined:2018-02-08 11:03
Hi mahmed106,

Hi mahmed106,

Can you please remove the battery reading every 6 sec and test again the above implementation? The voltage underflow check will be down in apply_wfi() by default. Which SDK are you using?

Thanks, PM_Dialog

PM_Dialog
Offline
Last seen:22 hours 20 min ago
Staff
Joined:2018-02-08 11:03
Hi mahmed106,

Hi mahmed106,

Can you please remove the battery reading every 6 sec and test again the above implementation? The voltage underflow check will be down in apply_wfi() by default.

Thanks, PM_Dialog

mahmed106
Offline
Last seen:2 weeks 6 days ago
Joined:2019-05-03 17:28
Yes i have tested this and

Yes i have tested this and now it is working perfectly.

Thanks dialog

PM_Dialog
Offline
Last seen:22 hours 20 min ago
Staff
Joined:2018-02-08 11:03
Hi mahmed106,

Hi mahmed106,

Glad that the provided implementation is working and thanks for accepting my answer.

Thanks, PM_Dialog

mahmed106
Offline
Last seen:2 weeks 6 days ago
Joined:2019-05-03 17:28
I have another problem that

I have another problem that with any approach, DA14681 goes into hibernation and stay in hibernation if it has been in normal for loop of PXP Reporter. Before that loop at startup while entering 1st time in PXP reporter, if i try to make it hibernate, It hibernates and then restarts again. Do know the reason of this,

PXP Reporter is same as in example FW. I am using that project as base project for my project.

PM_Dialog
Offline
Last seen:22 hours 20 min ago
Staff
Joined:2018-02-08 11:03
Hi mahmed106,

Hi mahmed106,

Can you please clarify what you mean with “in normal for loop of PXP Reporter”?

Thanks, PM_Dialog

mahmed106
Offline
Last seen:2 weeks 6 days ago
Joined:2019-05-03 17:28
In pxp_reporter_task function

In pxp_reporter_task function

for (;;)

This is the main loop which i am talking about

PM_Dialog
Offline
Last seen:22 hours 20 min ago
Staff
Joined:2018-02-08 11:03
Hi mahmed106,

Hi mahmed106,

I assume the you are putting explicitly the DA14681 and the pm_set_sleep_mode(pm_mode_hibernation) is called out of mail loop. I f yes, can you please indicate where are you using this API? Probably the system cannot hibernate due to a pending interrupt.

Thanks, PM_Dialog