cancel
Showing results for 
Search instead for 
Did you mean: 

Reset keeps occuring after program started.

laxer3a
Associate
Posted on May 20, 2012 at 09:43

Hi,

I have just received my discovery board and started to port my code over it but encountered the following problem : if I put a breakpoint at the entry point (first line of code of ''main'' function), I noticed that the breakpoint is hit more than once.

Step by step works fine, but breakpoint + fail show this behavior.

=> So my only conclusion is that a RESET occurs when running.

So I wrote the following little code to try to find out when and how it is reset :

===============================================

#include ''stm8s.h''

void main(void) {

    u16 cnt = 0;    // Counter

    

    CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);

    GPIO_DeInit(GPIOD);

    GPIO_Init(GPIOD, GPIO_PIN_0, GPIO_MODE_OUT_PP_LOW_FAST);

    // Disable WWDG to provoke reset.

    WWDG->CR = 0x7F;     // Disable WWDG reset mecanism. (Bit 6 is set to avoid software reset right away.) and counter set to 0x3F, Bit 7=0 Disabled

    WWDG->WR = 0;        // Comparison to occur when reach 0, in case.

    

    // IWDG Setup

    IWDG_SetPrescaler(IWDG_Prescaler_256);    // Reduce to minimum speed.

    IWDG_Enable(); // No disable found in the library...

    IWDG_SetReload(0xFF);                    // Reload counter to max to avoid reset.

    

    for (;;) {

        GPIO_WriteReverse(GPIOD, GPIO_PIN_0);

        IWDG_SetReload(0xFF); // Reload counter to avoid reset.

        cnt++;

        if (cnt > 7000) {

            GPIO_WriteReverse(GPIOD, GPIO_PIN_0); // Put breakpoint HERE

        }

    }

}

===============================================

As you can see, it is a very basic program that :

- Setup the clock

- Initialize the port for the LED

- Disable the Window WatchDog (WWDG)

- Set the IWDG regularly to avoid reset.

Now the interesting thing is that if I set up a breakpoing inside the IF condition, if I setup a value like 6000, I can reach the breakpoint.

If the value is set to 6500, the breakpoint is never reachable = the cpu has reset before reaching that value.

As I tried to control the only TWO sources that could generate a RESET, I am stuck and have no idea why the reset still keep occuring.

Any idea or hint would be a really really big help.

Regards,

Romain

2 REPLIES 2
jdf25252
Associate II
Posted on May 21, 2012 at 17:27

A couple things.  WWDG - I wouldn't try to initialize things I'm not using. Especially a watchdog since once you start it there's absolutely no going back.  You don't seem to be doing any harm there but you're doing no good either.

IWDG - Both the prescaler and reloadregister are write protected so you must do a IWDG_WriteAccessCmd( IWDG_WriteAccess_Enable ) before writing to either.

To update the counter you should use the IWDG_ReloadCounter() function.

See my updated --->

    // IWDG Setup

    IWDG_Enable(); // No disable found in the library...

->    IWDG_WriteAccessCmd( IWDG_WriteAccess_Enable );

    IWDG_SetPrescaler(IWDG_Prescaler_256);    // Reduce to minimum speed.

->    IWDG_WriteAccessCmd( IWDG_WriteAccess_Enable );

    IWDG_SetReload(0xFF);                    // Reload counter to max to avoid reset.

    IWDG_ReloadCounter();

        

    for (;;) {

        GPIO_WriteReverse(GPIOD, GPIO_PIN_0);

//        IWDG_SetReload(0xFF); // Reload counter to avoid reset.

->        IWDG_ReloadCounter();

        cnt++;

        if (cnt > 7000) {

            GPIO_WriteReverse(GPIOD, GPIO_PIN_0); // Put breakpoint HERE

        }

You should also verify that the OptionBits are not specifying hardware control of the WWDG.

pedro23
Senior
Posted on May 29, 2012 at 18:12

I had exactly the same problem and it is a problem with STVD IDE, the problem is the button

Run, in all ides until now, RUN continued from the point where you were, not in this IDE (dont ask me why it is different). Just use the Continue button (F5).

Best regards