Author Topic: [BitCloud] End device's power consumption  (Read 16183 times)

0 Members and 1 Guest are viewing this topic.

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 6234
  • Country: us
    • Personal site
Re: [BitCloud] End device's power consumption
« Reply #25 on: October 30, 2016, 05:55:58 pm »
However, bad luck. Still keeps restarting when calls sleepreq. Unfortunately, I can't examine ZDO_SleepReq function because it's compiled into the libraries of BC. :(
You can step through the assembly code to find out what happens. In this case, the "reset" is a 100% jump to NULL. A bit faster way is to put a breakpoint at address 0 and examine the call stack on reset.

One more thing: in the makefile I have SLEEP_WHEN_IDLE defined.
But in the source code it is not, so in theory, sleeping when idle is turned off, so manual sleep should work.
Can you elaborate? You can't manually remove system defines (things that start and end with '_'). This will break everything. You need to enable and disable things thorough the config server APIs.

Also, an additional note is that I dump MCUSR after restart every time, and it's always 0. So it's not the WDT which resets the CPU, but some SW bug I guess. (Like division by zero, or something similar).
As I said, it is a jump to NULL, 100%.
Alex
 
The following users thanked this post: danergo

Offline danergo

  • Regular Contributor
  • *
  • Posts: 111
  • Country: hu
Re: [BitCloud] End device's power consumption
« Reply #26 on: October 30, 2016, 06:34:18 pm »
You are surely right, Alex.

I'm observing the asm, and I think I got the problem, but not yet the reason:

Code: [Select]
void appPrepareSleep(void)
{
  zdoSleepReq.ZDO_SleepConf = appZdoSleepConf;
  3a: 80 e0        ldi r24, 0x00 ; 0
  3c: 90 e0        ldi r25, 0x00 ; 0
  3e: 90 93 00 00 sts 0x0000, r25
  42: 80 93 00 00 sts 0x0000, r24
  ZDO_SleepReq(&zdoSleepReq);
  46: 80 e0        ldi r24, 0x00 ; 0
  48: 90 e0        ldi r25, 0x00 ; 0
  4a: 0e 94 00 00 call 0 ; 0x0 <APL_TaskHandler>
  4e: 00 c0        rjmp .+0      ; 0x50 <APL_TaskHandler+0x50>

What is your opinion last but one line? Calling 0 looks a bad idea, no?

I also have this one for the appSleep() function. In this, appPostGlobalTask calls also 0, which is somewhat strange for me too.
Code: [Select]
void appSleep(void)
{
  appState = APP_PREPARE_SLEEP;
   0: 85 e0        ldi r24, 0x05 ; 5
   2: 80 93 00 00 sts 0x0000, r24
  appPostGlobalTask();
   6: 0e 94 00 00 call 0 ; 0x0 <appSleep>
   a: 08 95        ret

Seems that calling 0 is present in many times in the assembly, around the sleeping functions. Don't know if this is something wierd, or just normal.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 6234
  • Country: us
    • Personal site
Re: [BitCloud] End device's power consumption
« Reply #27 on: October 30, 2016, 06:38:13 pm »
What is your opinion last but one line? Calling 0 looks a bad idea, no?
It is a jump to the next instruction, not 0.

Seems that calling 0 is present in many times in the assembly, around the sleeping functions. Don't know if this is something wierd, or just normal.
This is wrong.

Are you disassembling the final ELF file? If you are looking at object files before lining, then having 0s is normal, they are just placeholders and linker will fill those out as as it figures out what goes where.
Alex
 

Offline danergo

  • Regular Contributor
  • *
  • Posts: 111
  • Country: hu
Re: [BitCloud] End device's power consumption
« Reply #28 on: October 30, 2016, 06:53:01 pm »
No, I did it with the .o files, sorry.

With the ELF, I don't see all the functions. For example I don't see zdoSleepReq at all.
Command I used is:
Code: [Select]
avr-objdump -d -S main.elf
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 6234
  • Country: us
    • Personal site
Re: [BitCloud] End device's power consumption
« Reply #29 on: October 30, 2016, 06:56:15 pm »
With the ELF, I don't see all the functions. For example I don't see zdoSleepReq at all.
Well, compiler can inline things. In this case zdoSleepReq is only called once, so there is no reason to have as a separate function.

Looking at disassembly won't do anything here. You need to single step though the program and find out what instruction causes jump to 0.

Or, as I said, put a breakpoint at address 0 and wait for it to hit, then look at a call stack.
Alex
 

Offline danergo

  • Regular Contributor
  • *
  • Posts: 111
  • Country: hu
Re: [BitCloud] End device's power consumption
« Reply #30 on: October 30, 2016, 07:09:02 pm »
Alright, thanks.
Will do it later, I need to move back onto XplainedPros and Windows, to speed things up.
 

Offline danergo

  • Regular Contributor
  • *
  • Posts: 111
  • Country: hu
Re: [BitCloud] End device's power consumption
« Reply #31 on: October 31, 2016, 09:58:20 pm »
Hello, Alex,

So I moved to Windows and to XplainedPro256rfr2. I'm just uploaded WSNDemo (original one) to this board, but somewhy, I'm unable to debug this code with the EDBG.
I can step into SYS_RunTask() pretty well, and also, if I put a breakpoint on SYS_RunTask() I get the breakpoint hit each time, so the basic debugging/stepping works fine.
However, I never get a breakpoint hit in APL_TaskHandler or any other functions. So technically, I'm unable to continue my investigation.
Atmel Studio writes: Running, and I can pause is, and see the ASM codes.


Have you experienced something similar?

Of course, I'm compiling with -O0 -g3 switches.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 6234
  • Country: us
    • Personal site
Re: [BitCloud] End device's power consumption
« Reply #32 on: October 31, 2016, 10:03:33 pm »
Well, if it is the default WSNDemo, then it is possible that APL_TaskHandler is not executing.

Try setting CS_UID to a non-zero value and see if that helps.
Alex
 

Offline danergo

  • Regular Contributor
  • *
  • Posts: 111
  • Country: hu
Re: [BitCloud] End device's power consumption
« Reply #33 on: October 31, 2016, 10:08:27 pm »
Yes, I changed CS_UID to some random value, but didn't help. Still not able to hit the breakpoints.
Also, LED0 is not light up on the board (I remember it should visualize something on the Coordinator).

Which other source lines would be worth checking with breakpoints?
HAL is not needed to be compiled/recompiled, right? I just loaded up the makefile, and changed CS_UID, selected Coordinator_StdlinkSec_MegaRf_Atmega256rfr2_16Mhz_Gcc.

Seems processManagerTask is not able to move on. It always processes the first taskId. SYS_taskFlag is always 16. These are in sysTaskManager.c:246.
And also, seems restarting constantly. Just put a breakpoint into SYS_SysInit(), and it gets hit in every half second.  >:(
« Last Edit: October 31, 2016, 10:24:11 pm by danergo »
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 6234
  • Country: us
    • Personal site
Re: [BitCloud] End device's power consumption
« Reply #34 on: October 31, 2016, 10:30:45 pm »
SYS_SysInit(), and it gets hit in every half second.  >:(
Check your fuses and disable WDT there.
Alex
 

Offline danergo

  • Regular Contributor
  • *
  • Posts: 111
  • Country: hu
Re: [BitCloud] End device's power consumption
« Reply #35 on: October 31, 2016, 10:35:37 pm »
Hm, I think it's not enabled by default on these boards, but I've just double-checked:

http://imgur.com/a/aTW22
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 6234
  • Country: us
    • Personal site
Re: [BitCloud] End device's power consumption
« Reply #36 on: October 31, 2016, 10:42:03 pm »
Hm, I think it's not enabled by default on these boards, but I've just double-checked:
BitCloud needs CKDIV8 bit set, but I doubt that it will lead to resets like this.

16 is ZDO_TASK_ID. This task posts APL Task after initialization is done.

I really don't see what else may be wrong.

Also, what do you mean by "It always processes the first taskId. SYS_taskFlag is always 16"? It never actually runs ZDO task?
« Last Edit: October 31, 2016, 10:49:44 pm by ataradov »
Alex
 

Offline danergo

  • Regular Contributor
  • *
  • Posts: 111
  • Country: hu
Re: [BitCloud] End device's power consumption
« Reply #37 on: October 31, 2016, 10:52:50 pm »
I checked in the CKDIV8 but nothing changed.
So the initialization should cause some memory leaks, or something similar, because it has to called many times before the chip reset. I can't even reproduce with stepping, just with continueing.

ZDO's code is closed if I'm not mistaken?
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 6234
  • Country: us
    • Personal site
Re: [BitCloud] End device's power consumption
« Reply #38 on: October 31, 2016, 10:57:07 pm »
ZDO's code is closed if I'm not mistaken?
Yes, it is, but it does not do anything special, just resets some stuff and posts APL task.

But from your description it looks like it never even gets to ZDO, since ZDO task is always posted at initialization and is cleared after the first call.

So it looks like it is busy calling some HAL task handler, which you can debug. Just break in processManagerTask() and step into taskHandlers[taskId]();
Alex
 

Offline danergo

  • Regular Contributor
  • *
  • Posts: 111
  • Country: hu
Re: [BitCloud] End device's power consumption
« Reply #39 on: October 31, 2016, 11:05:09 pm »
So it looks like it is busy calling some HAL task handler, which you can debug. Just break in processManagerTask() and step into taskHandlers[taskId]();

That's the sad thing. I can step into that function but it results in some ASM code.
That could be because taskId there is always 1. It's just can't get out of that. It breaks the loop, and then starts again with taskId == 1 in the next iteration. (which is not the reset yet, anyway).

Maybe the precompiled libs are not matching with these newly compiled components?
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 6234
  • Country: us
    • Personal site
Re: [BitCloud] End device's power consumption
« Reply #40 on: October 31, 2016, 11:12:22 pm »
Ok,  taskId == 1 means that it executes MAC_PHY_HWD_TaskHandler(). See if you have access to a variable called '__handlers' and if you do, what value does it have?

Do you have different hardware? At this point I strongly suspect 16 MHz crystal to be broken somehow.
Alex
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 6234
  • Country: us
    • Personal site
Re: [BitCloud] End device's power consumption
« Reply #41 on: November 01, 2016, 01:43:00 am »
Ok,  taskId == 1 means that it executes MAC_PHY_HWD_TaskHandler().
Actually, I'm wrong here. taskId == 1 is HAL and you have the code for this. I think HAL may be compiled with debug info disabled by default, but even if you don't want to recompile it, you can still look at relevant variables to see if you can spot anything.
Alex
 

Offline danergo

  • Regular Contributor
  • *
  • Posts: 111
  • Country: hu
Re: [BitCloud] End device's power consumption
« Reply #42 on: November 01, 2016, 09:10:17 am »
Hello,

I've recompiled HAL libraries with debug symbols.
Now the processManagerTask is stuck in taskId == 4 which is ZDO layer's task handler.

I'm attaching a screenshot: http://imgur.com/a/5YaVP

  • You can see, taskId is 4, and what are those 0x0 addresses in 9,10,11 slot? I assume they are okay, but everything is suscpicious now for me.
  • Also, taskId 1 is for HAL, why is the Studio not grabbing up the HAL's sources? It should be some magic trick to include them somehow? I added halTaskManager.c as a link.

My result: after taskId#4, next breakpoint is SYS_SysInit();

Tried with a different board with the same results.

How can I detect the last address before reset in AS7 debugger?
 

Offline danergo

  • Regular Contributor
  • *
  • Posts: 111
  • Country: hu
Re: [BitCloud] End device's power consumption
« Reply #43 on: November 01, 2016, 09:57:12 am »
Okay, I have some generic compiler issue, I guess.

On Linux, I build WSNDemo, and it works after uploading to the target.
On Windows same WSNDemo compiled from the same source keeps resetting.

Linux avr-gcc: avr-gcc (AVR_8_bit_GNU_Toolchain_3.4.5_1522) 4.8.1
Windows avr-gcc: avr-gcc (AVR_8_bit_GNU_Toolchain_3.5.4_1709) 4.9.2

I don't think it's worth going further. I installed a brand new fresh AS7, XplainedPros are simply not working with this new compiler. Maybe they are not compatible with AS any more.

Is avr-gdb working under Linux? I don't want to burn more time if it's not possible.
Or where could I download previous version of avr-gcc for Windows? On Atmel's site it's not available.


Thanks!
« Last Edit: November 01, 2016, 10:10:02 am by danergo »
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 6234
  • Country: us
    • Personal site
Re: [BitCloud] End device's power consumption
« Reply #44 on: November 01, 2016, 09:39:04 pm »
I don't think it's worth going further. I installed a brand new fresh AS7, XplainedPros are simply not working with this new compiler. Maybe they are not compatible with AS any more.
I'm not aware of any compiler issues like that, which does not mean that they don't exist.

But that would be something I investigate, because it may be relevant to your problem. On Windows compiler removes something important that WSNDemo works. On Linux it may remove something important that your program does not work.

Is avr-gdb working under Linux?
No idea, never used it.

Or where could I download previous version of avr-gcc for Windows? On Atmel's site it's not available.
Here they are http://www.atmel.com/tools/studioarchive.aspx
Alex
 

Offline danergo

  • Regular Contributor
  • *
  • Posts: 111
  • Country: hu
Re: [BitCloud] End device's power consumption
« Reply #45 on: December 19, 2016, 08:08:05 pm »
Hello!
I'm back from some other activities.

Still struggling with this topic though. Wasn't able to make a solid debuggable configuration either on Win7 (AS6, AS7), either on Linux (avr-gdb, avarice).
This is fair for now, I went back to some 'manual' debugging (measuring voltages, looking on the screen, etc).

So my current state is that I disabled button handling with WDT (buttons are not working at the moment), and I put the device into sleep mode with sleepreq.
However the symptoms are back: after power on, take about 2 secs to go to sleep, this is fine, but while sleeping after 58 minutes seconds(!) the whole device restarts.
It seems something wakes up the device from sleep and then something happens that not handled properly.

What is waking up my device from sleep? AppTimers are stopped, interrupts are not arriving).
« Last Edit: December 19, 2016, 08:45:11 pm by danergo »
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 6234
  • Country: us
    • Personal site
Re: [BitCloud] End device's power consumption
« Reply #46 on: December 19, 2016, 08:44:11 pm »
Start with monitoring the value of HAL_ReadResetReason(). It will tell you the source of reset. Device will have to quickly wake up every 8 seconds to count system time, even if all application timers are stopped (unless you explicitly disabled this functionality).

It is quite possible that you have some NULL pointer that is being called, and it appears as reset.
Alex
 

Offline danergo

  • Regular Contributor
  • *
  • Posts: 111
  • Country: hu
Re: [BitCloud] End device's power consumption
« Reply #47 on: December 19, 2016, 08:47:05 pm »
This looks quite reasonable. Now after I disabled every possible timers, adc-s and everything, interval is 8 seconds exactly (measured with a stopwatch).
I'll try to read HAL_ReadResetReason() and post here. Thanks! (Y)
« Last Edit: December 19, 2016, 09:13:19 pm by danergo »
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 6234
  • Country: us
    • Personal site
Re: [BitCloud] End device's power consumption
« Reply #48 on: December 19, 2016, 08:54:35 pm »
8 second interval is formed by functions in halSleepTimerClock.c. You don't need to change anything there, it all works as expected, but you may start investigations from there.

And I'd say it is almost 100% that you have some NULL pointer called.
Alex
 

Offline danergo

  • Regular Contributor
  • *
  • Posts: 111
  • Country: hu
Re: [BitCloud] End device's power consumption
« Reply #49 on: December 19, 2016, 09:13:26 pm »
Wow, that's kind of interesting! ResetReason is 0x4. Which is BROWN_OUT_RESET.
How is that even possible? Powering via USB.

Extra info: I have an H-bridge around the controller. Similar to this one on the right: http://letsmakerobots.com/files/userpics/u4631/H-bro.jpg
Q1-Q4 are shorted and connected to PB4
Q2-Q3 are shorted and connected to PB5.

Maybe HAL does something at wakeup which causes some short-circuit, and BOD resets the whole stuff?

« Last Edit: December 19, 2016, 09:20:04 pm by danergo »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf