T1被不同GPIO唤醒后,调用tkl_wakeup_source_type_get获取到的gpio_num相同

Wi-Fi 设备、蜂窝设备、WuKongAI、开发板、TuyaOS 移植等


Post Reply
moehentai
Posts: 2

版本:3.11.11
平台:T1
问题描述:T1有两个GPIO唤醒源P8和P9,唤醒后tkl_wakeup_source_type_get获取到的gpio_num均为8,应该怎么区分唤醒的gpio?
是否必现:是

Attachments
Serial Debug 2025-07-17 145625.txt
(57.58 KiB) Downloaded 15 times
JSHANG
Posts: 75

Re: T1被不同GPIO唤醒后,调用tkl_wakeup_source_type_get获取到的gpio_num相同

在3.11.11版本上验证,通过tkl_wakeup_source_type_get可以区分是gpio8, 还是gpio9唤醒的,请检查自己设置唤醒的gpio配置,和gpio接的对不对, 本地测试如下:
配置gpio8和gpio9唤醒, tkl_wakeup.c 里面的测试代码:
#if 1
void wakeup_unit_test(void)
{
TUYA_WAKEUP_SOURCE_BASE_CFG_T cfg;

Code: Select all

memset(&cfg, 0, sizeof(cfg));

#if 0
cfg.source = TUYA_WAKEUP_SOURCE_TIMER;
cfg.wakeup_para.timer_param.ms = 60000;

Code: Select all

tkl_wakeup_source_set(&cfg);

#endif
cfg.source = TUYA_WAKEUP_SOURCE_GPIO;
cfg.wakeup_para.gpio_param.gpio_num = 8;
cfg.wakeup_para.gpio_param.level = TUYA_GPIO_WAKEUP_HIGH;
tkl_wakeup_source_set(&cfg);

Code: Select all

cfg.wakeup_para.gpio_param.gpio_num = 9;
cfg.wakeup_para.gpio_param.level = TUYA_GPIO_WAKEUP_HIGH;
tkl_wakeup_source_set(&cfg);

//cfg.source = TUYA_WAKEUP_SOURCE_GPIO;
//tkl_wakeup_source_clear(&cfg);

//cfg.source = TUYA_WAKEUP_SOURCE_TIMER;
//tkl_wakeup_source_clear(&cfg);

tkl_cpu_sleep_mode_set(1, TUYA_CPU_DEEP_SLEEP);

}
#endif

gpio8 触发唤醒:
hal_machw_enter_monitor_mode
[01-01 00:00:01 ty D][4119][prod_test.c:172] prodtest_listen_start success
[01-01 00:00:01 ty D][41fe][prod_test.c:77] beacon ssid error:0
[01-01 00:00:01 ty D][4119][prod_test.c:274] -------------ssid filter-------------
[01-01 00:00:01 ty N][4119][prod_test.c:352] cannot found prod ssid,ret:-6
[01-01 00:00:01 ty D][4119][tuya_app_main.c:212] device_init in
[01-01 00:00:01 ty I][4119][tal_thread.c:200] thread_create name:gfw_core,stackDepth:5120,totalstackDepth:29696,priority:3
[01-01 00:00:01 ty I][4119][tal_thread.c:200] thread_create name:lp_irq_task,stackDepth:2048,totalstackDepth:31744,priority:3
tkl_wakeup_source_type_get: source 0 gpio 8
tkl_wakeup_source_set: wake_up_way 0x1 sleep_time 0 gpio_index_map 0x100 gpio_edge_map 0x0 gpio_last_index_map 0x0 gpio_last_edge_map 0x0
tkl_wakeup_source_set: wake_up_way 0x1 sleep_time 0 gpio_index_map 0x300 gpio_edge_map 0x0 gpio_last_index_map 0x0 gpio_last_edge_map 0x0
*******************************tuya_os_adapt_set_cpu_lp_mode,en = 1, mode = 1
deep sleep enable

gpio9触发唤醒:
update_ongoing_1_bcn_update
hal_machw_enter_monitor_mode
[01-01 00:00:01 ty D][4119][prod_test.c:172] prodtest_listen_start success
[01-01 00:00:01 ty D][4119][prod_test.c:274] -------------ssid filter-------------
[01-01 00:00:01 ty N][4119][prod_test.c:352] cannot found prod ssid,ret:-6
[01-01 00:00:01 ty D][4119][tuya_app_main.c:212] device_init in
[01-01 00:00:01 ty I][4119][tal_thread.c:200] thread_create name:gfw_core,stackDepth:5120,totalstackDepth:29696,priority:3
[01-01 00:00:01 ty I][4119][tal_thread.c:200] thread_create name:lp_irq_task,stackDepth:2048,totalstackDepth:31744,priority:3
tkl_wakeup_source_type_get: source 0 gpio 9
tkl_wakeup_source_set: wake_up_way 0x1 sleep_time 0 gpio_index_map 0x100 gpio_edge_map 0x0 gpio_last_index_map 0x0 gpio_last_edge_map 0x0
tkl_wakeup_source_set: wake_up_way 0x1 sleep_time 0 gpio_index_map 0x300 gpio_edge_map 0x0 gpio_last_index_map 0x0 gpio_last_edge_map 0x0
*******************************tuya_os_adapt_set_cpu_lp_mode,en = 1, mode = 1
deep sleep enable

icemanhh
Posts: 20

Re: T1被不同GPIO唤醒后,调用tkl_wakeup_source_type_get获取到的gpio_num相同

您好!遇到相同的问题,唤醒源设置了gpio23和gpio26,折腾了挺久还是只显示gpio_num:23,两个唤醒gpio能单独唤醒模组,程序详见附件,请帮忙解惑,谢谢!

Attachments
app_deep_sleep.txt
(2.16 KiB) Downloaded 8 times
Last edited by icemanhh on 2025年 Jul 26日 20:33, edited 2 times in total.
icemanhh
Posts: 20

Re: T1被不同GPIO唤醒后,调用tkl_wakeup_source_type_get获取到的gpio_num相同

反复测试后发现点问题,需要大佬们解决:
1、用于唤醒的GPIO设置为高电平唤醒(TUYA_GPIO_WAKEUP_HIGH)的话,能区分是哪个GPIO唤醒;
2、用于唤醒的GPIO设置为低电平唤醒(TUYA_GPIO_WAKEUP_LOW)的话,查询到的唤醒GPIO一直是引脚号最小的那个;

通过往上排查,锁定在sys_ctrl.c文件的gpio_0_31_status这个变量,变量值在bk_init_deep_wakeup_gpio_status函数中通过读取芯片特定寄存器获得,而该函数在初始化时被调用,通过让gpio_0_31_status变量输出到模组串口log中观测,发现低电平唤醒时只要设置为唤醒源的GPIO对应的bit都是1,因此无论按哪个按键唤醒,返回的gpio_num值都是引脚号最小的数值,如果让一个唤醒源GPIO一直保持低电平,通过另外一个唤醒源GPIO唤醒模组,gpio_0_31_status变量对应保持低电平的那个GPIO对应的bit则为0

具体为什么不清楚,还需要大佬们帮解决

JSHANG
Posts: 75

Re: T1被不同GPIO唤醒后,调用tkl_wakeup_source_type_get获取到的gpio_num相同

您好,打上这个patch再试试:
T1_os/T1/driver/sys_ctrl/sys_ctrl.c
@@ -2253,10 +2253,10 @@ void sctrl_enter_rtos_deep_sleep(PS_DEEP_CTRL_PARAM *deep_param)
continue;
}
#endif
if(((i < BITS_INT)&&(deep_param->gpio_stay_lo_map & (0x01UL << i)))
if(((i < BITS_INT)&&((deep_param->gpio_stay_lo_map deep_param->gpio_stay_hi_map) & (0x01UL << i)))
((deep_param->gpio_index_map & (0x01UL << i)))
((deep_param->gpio_last_index_map & (0x01UL << i)))
((i >= BITS_INT)&&(deep_param->gpio_stay_hi_map & (0x01UL << (i - BITS_INT)))) )
((i >= BITS_INT)&&((deep_param->gpio_stay_lo_map deep_param->gpio_stay_hi_map) & (0x01UL << (i - BITS_INT)))) )
{
continue;
}

Attachments
屏幕截图 2025-07-28 100750.png
icemanhh
Posts: 20

Re: T1被不同GPIO唤醒后,调用tkl_wakeup_source_type_get获取到的gpio_num相同

修改后似乎没有变化,获取的还是最小的GPIO数值

Attachments
微信截图_20250728153445.jpg
Post Reply