Other Parts Discussed in Thread: UNIFLASH
在使用CC2340R5时,使用了一个按键实现开关机(shutdown和wakeup),当我长按按键时,实现为关机,此时进入shutdown模式,当我按键唤醒后,仅CC2340在广播,其他都没有正常工作,请问此时唤醒后,程序时从哪执行,看手册上是说整个程序完整的重启,是重新从main开始运行吗?但似乎不是这样的。也没有从shutdown的位置开始。求解。
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
您好,
CC2340R5从shutdown状态唤醒的话会导致系统复位。这意味着程序应该是从main函数 开始执行的。
同时应该考虑硬件设计、固件实现以及代码逻辑。
您这种情况产生的原因可能有:
1.跳转进入保存的状态或者寄存器
2.启动bootloader
3.硬件复位不完全
4.中断向量表配置不正确,中断服务程序没有能够正确处理唤醒事件
提供的建议:
使用CCS的调试工具,进行逐步调试或者打断点调试
我尝试过debug,但是每次当我进入shutdown时,便会断开debug,
Cortex_M0P: JTAG Communication Error: (Error -615 @ 0x0) The target failed to see a correctly formatted SWD header. The connection to the target may be unreliable. Try lowering the TCLK setting before trying again. (Emulation package 9.12.0.00150) Cortex_M0P: Failed to remove the debug state from the target before disconnecting. There may still be breakpoint op-codes embedded in program memory. It is recommended that you reset the emulator before you connect and reload your program before you continue debugging
对,所以无法继续调试。当我唤醒时,也不知道程序是从哪开始运行。经过我不严谨的测试,唤醒后即没有从mian重新开始,也没有从shutdown的后一句开始。但是CC2340可以广播,然后我i测试在Application main loop里面增加我的语句似乎也没有运行。
Shutdown mode, 器件完全关闭(包括 AON 域),并且 I/O 被锁存他们在进入关闭模式之前的值。
任何 I/O 引脚上的状态更改定义为唤醒,Shutdown pin唤醒器件并用作复位触发器。
CPU 可以区分复位通过这种方式,通过复位引脚或上电复位或thermal Shutdown reset,通过读取复位状态来复位登记。
The only state retained in this mode are the latched I/O state, 3V register bank, and the flash memory
contents.
所以我认为是复位后跳转到 flash保存的您之前的程序 或者是 寄存器中
我新建了一个basic_ble工程,让设备进入shutdown后,再唤醒,结果还是一样的,只有模块在广播,其他的似乎没有工作起来,我需要在唤醒后拉低IO24。如果唤醒后程序从main重新执行,我在main里面拉低的IO24并没有生效,可以看出此时并没有从main开始执行。我又尝试了在shutdown的后一条语句拉低IO24,其也没有执行。最后我在任务主循里面拉低IO24,也没有执行。只有模块在广播。不知道从哪里下手了
这一项能直观的看到MCU有没有复位,IO24接有一个LED。进入shutdown后IO会锁存,我在进入shutdown之前禁用了IO锁存。
GPIO_write(CONFIG_GPIO_24, 1); GPIO_setConfig(CONFIG_GPIO_KEY_INPUT, GPIO_CFG_IN_PU | GPIO_CFG_SHUTDOWN_WAKE_LOW); /* Application code must always disable the IO latches when coming out of shutdown */ PowerLPF3_releaseLatches(); /* Go to shutdown */ Power_shutdown(Power_ENTERING_SHUTDOWN,0); /* Should never get here, since shutdown will reset. */ //while (1) {} Power_reset(); GPIO_write(CONFIG_GPIO_24, 0);
在进入shutdown之前我把IO24拉高,以降低功耗,唤醒后再拉低,使LED工作。
唤醒前后 LED状态都是什么样?亮着吗
设置的是1灭 0亮吗?实际效果是
Power_reset();
GPIO_write(CONFIG_GPIO_24, 0);
你这个代码的位置可能不对,
上面有提示Should never get here, since shutdown will reset.
1.现测试 唤醒前后 LED状态都是什么样?
您预期的LED状态前后是什么样
2.您的需求是在从shutdown模式唤醒后,从main函数出发,然后拉低IO24,使LED工作
这样理解是否正确
我认为
您是进入main函数的,只不过是IO24没有被运行
理论上从shutdown模式都是进入main函数的
除非是唤醒就进入了中断会不从main函数开始运行,但根据您描述使用的例程,应该不存在这种情况
建议您考虑一下IO24的代码逻辑或者引用
唤醒后可以debug一下试试
添加打印似乎不生效,现在似乎解决了。不过遇到了新的问题,不能长按开机,也就是长按从shutdown唤醒并重新工作。实现了长按开机,我需要在松开按键后再退出shutdown模式,但是现在是我一直长按就会进入开机,然后又关机的状态。当我在唤醒的时候加入引脚电平检测检测后,长按只能开启广播,必须第二次长按才会进入正常工作。去掉电平检测后又恢复正常,只需要一次长按就可以开机。
好的,代码如下,这一段代码实现长按开机,但是长按后不松开程序跑起来后会进入shutdown,同一个按键实现的开关机。位置放在Board_init();完成后。
void Power_on_self_Test() //开机检测 { //while(1) //{ count = 0; while(GPIO_read(CONFIG_GPIO_KEY_INPUT) == 0) { count++; delayMS(10); // vTaskDelay(10); if(count >= 100) { return ; // while(1) // { // if(GPIO_read(CONFIG_GPIO_KEY_INPUT) == 1) // { // return ; // } // } } } count = 0; GPIO_write(CONFIG_GPIO_VCCON, 1); GPIO_setConfig(CONFIG_GPIO_KEY_INPUT, GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_FALLING| GPIO_CFG_SHUTDOWN_WAKE_LOW); GPIO_setConfig(CONFIG_GPIO_ADC_BAT_AIN, GPIO_CFG_IN_PD ); /* Application code must always disable the IO latches when coming out of shutdown */ PowerLPF3_releaseLatches(); /* Enable interrupts */ GPIO_enableInt(CONFIG_GPIO_KEY_INPUT); /* Go to shutdown */ Power_shutdown(0,0); /* Should never get here, since shutdown will reset. */ while (1) {} //} }
下面这各是加了按键松开检测的,当我长按后,只开启了广播,第二次长按才能松开后才能return;
void Power_on_self_Test() //开机检测 { //while(1) //{ count = 0; while(GPIO_read(CONFIG_GPIO_KEY_INPUT) == 0) { count++; delayMS(10); // vTaskDelay(10); if(count >= 100) { // return ; while(1) { if(GPIO_read(CONFIG_GPIO_KEY_INPUT) == 1) { return ; } } } } count = 0; GPIO_write(CONFIG_GPIO_VCCON, 1); GPIO_setConfig(CONFIG_GPIO_KEY_INPUT, GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_FALLING| GPIO_CFG_SHUTDOWN_WAKE_LOW); GPIO_setConfig(CONFIG_GPIO_ADC_BAT_AIN, GPIO_CFG_IN_PD ); /* Application code must always disable the IO latches when coming out of shutdown */ PowerLPF3_releaseLatches(); /* Enable interrupts */ GPIO_enableInt(CONFIG_GPIO_KEY_INPUT); /* Go to shutdown */ Power_shutdown(0,0); /* Should never get here, since shutdown will reset. */ while (1) {} //} }
我观察您这两段代码是无差的,
我会将您的问题升级到英文team那边,我也会继续跟进的,您可以参考两边建议结合一下
由于时差存在,大约今晚或者明早会有回复
英文team那边经常问到以下问题,希望您回答一下,这样会更快一些
1.您使用的SDK版本
2.您使用的例程名称