本帖最后由 FSL_TICS_A 于 2014-4-23 10:12 编辑
客户问题介绍:
· 芯片型号:MK60DN512ZVMD10
· 描述:在程序中,连续不断的读取RTC_TSR寄存器值,并将结果传给上位机,但发现连续读出的值出现前后不匹配的问题,从理论上分析,RTC_TSR寄存器内的值应该逐渐递增的,但从打印的输出结果看,存在个别前后不一致的现象(如图1所示),所以怀疑这是不是芯片的Bug呢?
图1 解决过程:
在开始阶段,在确认客户代码(如表1)无误后,在TWR-K60D100开发板上调试,出现了与客户相似的问题,当时怀疑:1.可能这是个芯片的BUG;2。猜测RTC_TSR寄存器的值在递增后的最初阶段是不稳定的,如果刚好这时读取到的RTC_TSR寄存器值,那么得到的值是不准确的。 表1
- #include <stdio.h>
-
- #include <drivers/uart/uart.h>
-
- #include "cmd_rtcdebug.h"
-
- #include "common.h"
-
-
- extern "C"
- {
-
- #include "wdog.h"
- }
-
-
- extern "C"
-
- int cmd_rtcdebug(const char *args)
- {
- uint32_t lowestValue;
- uint32_t lastFailValue = 0;
- uint32_t failCountInRow = 0;
- int wdCount = 0;
-
- lowestValue = RTC_TSR;
-
-
- printf("press any key to exit\r\n");
-
- while(1)
- {
-
- uint32_t nextValue = RTC_TSR;
-
- if (uart_kbhit())
- {
- break;
- }
-
-
- if (nextValue < lowestValue)
- {
-
- if (lastFailValue != nextValue)
- {
-
- printf("RTC fail: lowest value: %u, next value: %u\r\n", lowestValue, nextValue);
- }
-
- lastFailValue = nextValue;
- failCountInRow++;
- }
-
- else if (nextValue == lowestValue)
- {
-
- if (failCountInRow)
- {
-
- printf("RTC fails in row: %u\r\n", failCountInRow);
-
- failCountInRow = 0;
- }
- }
-
- else if (nextValue > lowestValue)
- {
-
- if (failCountInRow)
- {
-
- printf("RTC fails in row: %u\r\n", failCountInRow);
-
- failCountInRow = 0;
- }
-
- if (wdCount > 300)
- {
- wdog_refresh();
- wdCount = 0;
- }
- wdCount++;
-
-
- printf("RTC_TSR: %u\r\n", nextValue);
-
- lowestValue = nextValue;
- }
- }
-
- return 0;
- }
-
针对第一个猜测,在查阅Errata文档后,大致可以排除;至于第二个猜测,我应对的方法是在每次读取RTC_TSR寄存器之前,添加一个延时函数,经过一段时间的测试后,发现出错的频率虽然没有原来那么多,但还是会出现,看来这是个治标不本的方法啊,只能另想方法啊。
各位网友有没有好的想法,欢迎来讨论!
|