今天使用STM8S003K3芯片调试的时候发现总是看门狗复位,然后把所有不想干的语句全部删除掉了,然后硬件调试,发现在写入WWDG->CR这条语句的时候直接产生了复位。
而且更加奇怪的是如果我调试是在C语言这边单步调试,那么就发生复位,如果我在汇编这边按F11把这条语句的汇编过了就不会发生复位。
另外还有一种情况,我现在的分频都是 /1, /1,CPU时钟是16M,会产生这个复位问题,但是如果我修改HSI分频改为2就不会复位,或者CPU分频改为8也不会复位。
另外我已经关掉优化了,还是不行。
具体语句是 stm8s_wwdg.c 中的 WWDG_Init.c 中的 WWDG->CR这一条。
void WWDG_Init(uint8_t Counter, uint8_t WindowValue)
{
/* Check the parameters */
assert_param(IS_WWDG_WINDOWLIMITVALUE_OK(WindowValue));
WWDG->WR = WWDG_WR_RESET_VALUE;
WWDG->CR = (uint8_t)((uint8_t)(WWDG_CR_WDGA | WWDG_CR_T6) | (uint8_t)Counter);
WWDG->WR = (uint8_t)((uint8_t)(~WWDG_CR_WDGA) & (uint8_t)(WWDG_CR_T6 | WindowValue));
}
下面是 main.c 文件。
#include "stm8s.h"
#include "stm8s_wwdg.h"
#define WINDOW_VALUE 97
#define COUNTER_INIT 104
/**
* @brief wwdg config
*/
void WWDG_Config(void)
{
/* WWDG configuration: WWDG is clocked by SYSCLK = 2MHz */
/* WWDG timeout is equal to 251,9 ms */
/* Watchdog Window = (COUNTER_INIT - 63) * 1 step
= 41 * (12288 / 2Mhz)
= 251,9 ms
*/
/* Non Allowed Window = (COUNTER_INIT - WINDOW_VALUE) * 1 step
= (104 - 97) * 1 step
= 7 * 1 step
= 7 * (12288 / 2Mhz)
= 43.008 ms
*/
/* So the non allowed window starts from 0.0 ms to 43.008 ms
and the allowed window starts from 43.008 ms to 251,9 ms
If refresh is done during non allowed window, a reset will occur.
If refresh is done during allowed window, no reset will occur.
If the WWDG down counter reaches 63, a reset will occur. */
WWDG_Init(COUNTER_INIT, WINDOW_VALUE);
}
/**
* @brief wwdg refresh
*/
void WWDG_Refresh(void)
{
if ((WWDG_GetCounter() & 0x7F) < WINDOW_VALUE)
{
WWDG_SetCounter(COUNTER_INIT);
}
}
int main( void )
{
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
WWDG_Config();
return 0;
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval : None
*/
void assert_failed(u8* file, u32 line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
这是C的调试
这个是汇编调试的。
|