Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix power consumption #5

Closed
biemster opened this issue Dec 2, 2024 · 8 comments
Closed

Fix power consumption #5

biemster opened this issue Dec 2, 2024 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@biemster
Copy link
Owner

biemster commented Dec 2, 2024

It seems the chip does not sleep between advertisement, as discovered by @atc1441 here: biemster/FindMy#73 (comment)

He also kindly provided a solution in that comment, implement that.

@biemster biemster added the bug Something isn't working label Dec 2, 2024
@biemster biemster self-assigned this Dec 2, 2024
@biemster
Copy link
Owner Author

biemster commented Dec 2, 2024

works! (biemster/FindMy#73 (comment))

@biemster biemster closed this as completed Dec 2, 2024
@biemster
Copy link
Owner Author

biemster commented Dec 3, 2024

Doesn't work! The chip sleeps and wakes up periodically, but does not send the advertisement.

@biemster biemster reopened this Dec 3, 2024
@atc1441
Copy link

atc1441 commented Dec 3, 2024

Oh no, did actually not check that!
Will redo the check! Sorry

@biemster
Copy link
Owner Author

biemster commented Dec 3, 2024

I already noticed I need to add some callbacks when the chip comes out of DEEPSLEEP, because doing only the SUSPENDs in the setSuspendMask actually works (but I guess the power consumption is still significant then)

@atc1441
Copy link

atc1441 commented Dec 3, 2024

Lets do it this way then^^ Here is the working code.
Indeed your latest bin does notadvertise. Most likely because you reinit on each boot and do not take care of the deepsleep retention

#include "tl_common.h"
#include "drivers.h"
#include "stack/ble/ble.h"
#include "app_config.h"

_attribute_ram_code_ void irq_handler(void)
{
	irq_blt_sdk_handler();
}

#define		MY_RF_POWER_INDEX					RF_POWER_P0p04dBm

void task_suspend_exit (u8 e, u8 *p, int n)
{
	(void)e;(void)p;(void)n;
	rf_set_power_level_index (MY_RF_POWER_INDEX);
}

void blt_pm_proc(void)
{
#if(BLE_APP_PM_ENABLE)
		bls_pm_setSuspendMask (SUSPEND_ADV | DEEPSLEEP_RETENTION_ADV | SUSPEND_CONN | DEEPSLEEP_RETENTION_CONN);
#endif  //end of BLE_APP_PM_ENABLE
}

static u8 public_key[] = {
	0xbb,0xbb,0xbb,0xbb,0xbb,0xbb,0xbb,0xbb,0xbb,0xbb,0xbb,0xbb,0xbb,0xbb,
	0xbb,0xbb,0xbb,0xbb,0xbb,0xbb,0xbb,0xbb,0xbb,0xbb,0xbb,0xbb,0xbb,0xbb,
};

static u8 tbl_advData[] = {
	0x1e, /* Length (30) */
	0xff, /* Manufacturer Specific Data (type 0xff) */
	0x4c, 0x00, /* Company ID (Apple) */
	0x12, 0x19, /* Offline Finding type and length */
	0x00, /* State */
	0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
	0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
	0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
	0x00, /* First two bits */
	0x00, /* Hint (0x00) */
};

_attribute_ram_code_ int main (void)    //must run in ramcode
{
	blc_pm_select_internal_32k_crystal();
	cpu_wakeup_init();
	int deepRetWakeUp = pm_is_MCU_deepRetentionWakeup();  //MCU deep retention wakeUp

	rf_drv_ble_init();

	gpio_init(!deepRetWakeUp);  //analog resistance will keep available in deepSleep mode, so no need initialize again

	clock_init(SYS_CLK_TYPE);

	if( deepRetWakeUp ){
	blc_app_loadCustomizedParameters_deepRetn();
	blc_ll_initBasicMCU();   //mandatory
	rf_set_power_level_index (MY_RF_POWER_INDEX);

	blc_ll_recoverDeepRetention();

	irq_enable();
	}
	else{
		random_generator_init();
		blc_readFlashSize_autoConfigCustomFlashSector();
		blc_app_loadCustomizedParameters_normal();
		u8  mac_public[6];
		mac_public[5] = public_key[0] | 0xc0;
		mac_public[4] = public_key[1];
		mac_public[3] = public_key[2];
		mac_public[2] = public_key[3];
		mac_public[1] = public_key[4];
		mac_public[0] = public_key[5];

		blc_ll_initBasicMCU();                      //mandatory
		blc_ll_initStandby_module(mac_public);		//mandatory
		blc_ll_initAdvertising_module(mac_public); 	//legacy advertising module: mandatory for BLE slave

		memcpy(&tbl_advData[7], &public_key[6], 22);
		tbl_advData[29] = public_key[0] >> 6;

		bls_ll_setAdvData( (u8 *)tbl_advData, sizeof(tbl_advData) );
		bls_ll_setAdvParam( ADV_INTERVAL_2S, ADV_INTERVAL_2S, ADV_TYPE_NONCONNECTABLE_UNDIRECTED, OWN_ADDRESS_PUBLIC, 0,  NULL,  BLT_ENABLE_ADV_ALL, ADV_FP_NONE);

		bls_ll_setAdvEnable(BLC_ADV_ENABLE);
		rf_set_power_level_index (MY_RF_POWER_INDEX);
		blc_ll_initPowerManagement_module();
	    blc_app_setDeepsleepRetentionSramSize(); //select DEEPSLEEP_MODE_RET_SRAM_LOW16K or DEEPSLEEP_MODE_RET_SRAM_LOW32K
		bls_pm_setSuspendMask (SUSPEND_ADV | DEEPSLEEP_RETENTION_ADV | SUSPEND_CONN | DEEPSLEEP_RETENTION_CONN);
		blc_pm_setDeepsleepRetentionThreshold(50, 50);
		blc_pm_setDeepsleepRetentionEarlyWakeupTiming(200);
		bls_app_registerEventCallback (BLT_EV_FLAG_SUSPEND_EXIT, &task_suspend_exit);
		blc_app_checkControllerHostInitialization();
	}
    irq_enable();
	while (1) {
		blt_sdk_main_loop();
		blt_pm_proc();
	}
}

@biemster
Copy link
Owner Author

biemster commented Dec 3, 2024

this fw does advertise, could you do one final power check @atc1441 ?

@atc1441
Copy link

atc1441 commented Dec 3, 2024

Works :)
Now also the 9uA are visible again. should have been a hint that the first rev was 6uA but I was testing on a different PCB so thought it was that.

@biemster
Copy link
Owner Author

biemster commented Dec 3, 2024

great! thanks for checking so promptly 👍

@biemster biemster closed this as completed Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants