11 posts / 0 new
Last post
DrNick1
Offline
Last seen: 5 years 1 month ago
Joined: 2014-07-01 11:55
Testing watchdog

How can I check correct operation of my code using the watchdog from within Keil.
I can step everything through to the NMI handler, but when it gets to the end of the routine it executes the software reset
SetWord16(SYS_CTRL_REG, (GetWord16(SYS_CTRL_REG) & ~REMAP_ADR0) | SW_RESET );
and then it reports that it cannot start the core. I assume that the software reset has occurred but I have no way of getting control back without disconnecting the development board.

If I try to run the program outside the debugger (by stopping the debugger before it gets to this point) it still doesn't reset correctly.

So how do I get to run my program with WDOG enabled to reset the device and check its working ok without burning the OTP. Is it possible?

I'm running beacon3.40.6 as a basis.

Is it straightforward to use the WDOG to force a device reset?

Device: 
DrNick1
Offline
Last seen: 5 years 1 month ago
Joined: 2014-07-01 11:55
When the watchdog fires, it

When the watchdog fires, it eventually gets to the following line in the NMI handler routine (Beacon3.40.6)
SetWord16(SYS_CTRL_REG, (GetWord16(SYS_CTRL_REG) & ~REMAP_ADR0) | SW_RESET );
This is the instruction that resets the system. Nothing happens after this code is executed.
What does ~REMAP_ADR0 actually mean. There are 4 possible values for this given in the datasheet - the default is 00 (ROM) which implies that it will start execution from location 0 in the ROM.
My limited understanding says I should restart from the system RAM as this is where my program resides (assuming I havn't lost power or gone into deep sleep mode.)
Can anybody confirm I need to change REMAP_ADR0 away from its default setting, and when do I not need to do this?

DrNick1
Offline
Last seen: 5 years 1 month ago
Joined: 2014-07-01 11:55
SetWord16(SYS_CTRL_REG,

SetWord16(SYS_CTRL_REG, (GetWord16(SYS_CTRL_REG) & ~REMAP_ADR0) | SW_RESET );
SO the purpose of this line is to effectively make the bits corresponding to REMAP_ADR0 be zero, ie it forces the default value.
If I change the line to
SetWord16(SYS_CTRL_REG, (GetWord16(SYS_CTRL_REG)) | SW_RESET );
and make REMAP_ADR0 =0x02 (SysRAM) before this is called, then the watchdog timer expiring causes a "correct" reset and the code runs again from the beginning.
I can also still set breakpoints that work, so all seems well!

I'm still not sure what happens when I go to OTP with the watchdog. Is the default setting ok for that scenario?

MT_dialog
Offline
Last seen: 9 months 2 weeks ago
Staff
Joined: 2015-06-08 11:34
Hi DrNick1,

Hi DrNick1,

Yes that right the REMAP_ADR0 is to make sure that the REMAP_ADR0 is set to the default address. The default setting should force the bootloader to run and eventualy will read from OTP.

Thanks MT_dialog

kobyfr_mag
Offline
Last seen: 5 years 9 months ago
Joined: 2015-06-02 12:48
Hello.

Hello.
I've tried using the sdk_driver watchdog API for initializing the watchdog.
1. I have enabled watchdog //#undef CFG_WDOG
2. I've tried wdg_init(1) and wdg_init(0)
My software doesn't seem to restart, even though I don't reset the watchdog:
1. It doesn't light up the LEDs again (I have an LED flashing on startup)
2. My Keil IDE debugging session doesn't hit NMI_HandlerC
Adding code to test the watchdog counter, states its stuck at 0x00FF

MT_dialog
Offline
Last seen: 9 months 2 weeks ago
Staff
Joined: 2015-06-08 11:34
Hi kobyfr_mag,

Hi kobyfr_mag,

Are you emulating a condition that eventually will crash your software and trigger the watchdog (meaning stuck in an endless loop for example)? Are you in sleep mode when using the watchdog, the watchdog resets every time you wake up from sleep. You dont have to explicitly enable it, just define it and the SDK will take care of the initializations. Also besides the fact that when in sleep mode the watchdog reloads in every wake up it also reloads in the arch_main.c file in the bottom of the main_func() function, you can comment out the below snippet and test it:

     if (USE_WDOG)
         wdg_reload(WATCHDOG_DEFAULT_PERIOD);

Thanks MT_dialog 

kobyfr_mag
Offline
Last seen: 5 years 9 months ago
Joined: 2015-06-02 12:48
1. Yes I'm trying to cause a

1. Yes I'm trying to cause a watchdog to fire, in order to test it is operational. I had no idea if I did all that is required in order to activate it.
2. I commented out arch_main.c wdg_reload(WATCHDOG_DEFAULT_PERIOD)
3. my init sequence is 3 fast LED flashes. (600 mSec total duration)
4. my endless loop is slow LED flashes (should cause the watchdog do fire after ~2 seconds)
5. I loaded my program to RAM from uVision, via JLink debugger.
6. I allowed it to free run
7. I observed the fast LED flash sequence once, and then the slow LED flash sequence uninterrupted. ==> no SW reset ==> no watchdog occurred

Is there anything more I need to do in order for the watchdog to fire, and cause a reset?

MT_dialog
Offline
Last seen: 9 months 2 weeks ago
Staff
Joined: 2015-06-08 11:34
Hi kobyfr_mag,

Hi kobyfr_mag,

I 've just noticed in post number 5, did you commented out the watchdog definition ? Try to #define CFG_WDG dont comment it out, if you comment it out the SDK will not enable it.

Please try to disable sleep mode and leave the wdg_reload(WATCHDOG_DEFAULT_PERIOD) commented, run it by using keil enviroment in a fresh template. If you do that, your code will go to the NMI_Handler().

Thanks MT_dialog

kobyfr_mag
Offline
Last seen: 5 years 9 months ago
Joined: 2015-06-02 12:48
Thank you.

Thank you.
adding #define CGF_WDOG did the trick.
due to the while(1) I inserted, I hit NMI_Handler and the watchdog keeps firing every 2.5 seconds.

chen123
Offline
Last seen: 10 months 2 weeks ago
Joined: 2021-01-07 01:43
Could you please tell me how
  • Could you please tell me how to do the software reset operation for DA14580
PM_Dialog
Offline
Last seen: 2 days 10 hours ago
Staff
Joined: 2018-02-08 11:03
Hi chen123,

Hi chen123,

Thanks for your comment. This forum thread is very old and closed, so can you please raise a new one?

Thanks, PM_Dialog