We are using device nrf52840 with sdk 15.0.0
The problem is: High current consumption, typically around 2 mA. But over time drifts up to 9 mA in a period of 12 hrs.
1.- How to know the MCU is in Debug Interface Mode from code?
I have not found any documented source other than comments in the forums such as:
"if (DWT->CYCCNT != 0)" Does not work for me. This is always true in my case. debugging or not debugging. Trapped in this mode or not.
"if(dgb->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk)" Works OK; if the J-Link is attached is true, false if its not attached. But the MCU can still be trapped in high power consumption (debug interface mode). Even that this register is false. So this proves that the debugger is attached, but not that the MCU is in debug interface mode.
2.- I need a reliable way to get the MCU out of Debug Interface Mode from code. (In my scenario we don't have means to power cycle it).
We need to force an exit from debug interface mode at startup, this will ensure after reset (software reset) we will not be using more power than necessary.
3.- Can we go into this mode by doing something wrong in Code? (with out debugger).
Reasoning:
We have seen in very few occasions, that our product consumes ~2mA constantly, (where it should be under 80 uA). This drains batteries really fast.
Observations:
Software reset (NVIC or SCB->AIRCR) does not get it out of this mode.
PIN Reset does not get it out of this mode.
Using the nrjprog + J-Link to force a --reset, fixes the issue
Using the IAR IDE to connect to target and disconnect from target fixes this issue.
Power Cycle fixes this issue, however power cycling is not what I am looking for.
We can "reproduce" this issue by debugging a target, then disconnecting the debugger (j Link) with out stopping it in the IDE. It stays in this mode after resets..
In a longer overnight test, our products goes into SD_POWER_SYSTEM_OFF, which appears to get worse over time. up to 9mA. This last could be related to a component in our board, but if we were to leave the unit when NOT trapped in this debug interface mode, then the power consumption is about 17uA. (expected)
Our quality team has seen twice this issue. They don't even have debuggers such as the JLink, They do replace batteries and claim that it happens even after swapping to new batteries too.
Please Help
Thanks.!