我一直在尝试找出我的PCB/嵌入式代码出了什么问题。印刷电路板是围绕STM32F407VE设计的。每隔5/10/20/60/120秒调用一次set_time()。
time_t et = time(NULL);
debug("%d: NTP sync started\r\n", et);
set_time(et);在第一次调用代码600秒后,我将看到类似以下内容:
1587754882: NTP sync started
1587754902: NTP sync started
1587754922: NTP sync started
1587754942: NTP sync started
1587754962: NTP sync started
1587754982: NTP sync started
1587755002: NTP sync started
1587755022: NTP sync started
1587755042: NTP sync started
1587755062: NTP sync started
1587755082: NTP sync started
1587755102: NTP sync started
1587755122: NTP sync started
1587755142: NTP sync started
1587755162: NTP sync started
1587755182: NTP sync started
1587755202: NTP sync started
1587755222: NTP sync started
1587755242: NTP sync started
1587755262: NTP sync started
1587755282: NTP sync started
1587755302: NTP sync started
1587755322: NTP sync started
1587755342: NTP sync started
1587755362: NTP sync started
1587755382: NTP sync started
1587755402: NTP sync started
1587755422: NTP sync started
1587755442: NTP sync started
1587755462: NTP sync started
1587755482: NTP sync started
++ MbedOS Error Info ++
Error Status: 0x80FF0100 Code: 256 Module: 255
Error Message: Fatal Run-time error
Location: 0x8022591
Error Value: 0x0
Current Thread: main Id: 0x20005B8C Entry: 0x801A273 StackSize: 0x2000 StackMem: 0x2000B4C0 SP: 0x2000D270
For more info, visit: https://mbed.com/s/error?error=0x80FF0100&tgt=ARCH_MAX
-- MbedOS Error Info --
HAL_RTC_SetDate error如果间隔为5秒,则第121次调用将触发系统崩溃。如果间隔为2分钟,则第6次调用将触发崩溃。
其他一些观察结果: 1)无论使用LSI或LSE作为RTC时钟源,都会发生这种情况。2)如果我注释掉了set_time(),那么系统就不会崩溃。3)下面的简单测试代码不会在同一个PCB上崩溃。但是如果启用了注释掉的代码,它将重现问题。
time_t et;
printf("%d: system started\r\n", time(NULL));
uint8_t toResetRTC = 0, toSaveFooIntoBackupRegister = 0;
uint32_t foo = 12345;
while (1)
{
toResetRTC++;
if(toResetRTC > 4)
{
et = time(NULL);
printf("%d: RTC reset started\r\n", et);
set_time(et);
toResetRTC = 0;
}
toSaveFooIntoBackupRegister++;
if(toSaveFooIntoBackupRegister > 59)
{
RTC_HandleTypeDef RtcHandle;
RtcHandle.Instance = RTC;
HAL_PWR_EnableBkUpAccess();
HAL_RTCEx_BKUPWrite(&RtcHandle, 0, foo);
// This following line messes up HAL_RTC_SetDate() and HAL_RTC_SetTime() when called by set_time();
// If the following line is enabled, system crashes every 1 minute
//HAL_PWR_DisableBkUpAccess();
toSaveFooIntoBackupRegister = 0;
}
ThisThread::sleep_for(1000);
}我认为代码库的其他部分会周期性地干扰RTC。有没有人能提供一些关于如何解决问题的建议?
谢谢。
更新:包含set_time()的第一个代码块是通过从HSE获取时钟的报价器调用的。当我查看来自LSI的RTC的控制台输出时(附在下面),我意识到在第一次使系统崩溃的31次运行中,间隔已更改为570。很明显,崩溃的发生并不是因为RTC内在的某种神秘节奏,而是RTC之外的某种东西。有一段代码在系统启动后执行600秒。此块代码最终导致在答案中查找。
RTC源自LSI时的崩溃日志。
1587760500: NTP sync started
1587760519: NTP sync started
1587760538: NTP sync started
1587760557: NTP sync started
1587760576: NTP sync started
1587760595: NTP sync started
1587760614: NTP sync started
1587760633: NTP sync started
1587760652: NTP sync started
1587760671: NTP sync started
1587760690: NTP sync started
1587760709: NTP sync started
1587760728: NTP sync started
1587760747: NTP sync started
1587760766: NTP sync started
1587760785: NTP sync started
1587760804: NTP sync started
1587760823: NTP sync started
1587760842: NTP sync started
1587760861: NTP sync started
1587760880: NTP sync started
1587760899: NTP sync started
1587760918: NTP sync started
1587760937: NTP sync started
1587760956: NTP sync started
1587760975: NTP sync started
1587760994: NTP sync started
1587761013: NTP sync started
1587761032: NTP sync started
1587761051: NTP sync started
1587761070: NTP sync started
++ MbedOS Error Info ++
Error Status: 0x80FF0100 Code: 256 Module: 255
Error Message: Fatal Run-time error
Location: 0x8022591
Error Value: 0x0
Current Thread: main Id: 0x20005B8C Entry: 0x801A273 StackSize: 0x2000 StackMem: 0x2000B4C0 SP: 0x2000D270
For more info, visit: https://mbed.com/s/error?error=0x80FF0100&tgt=ARCH_MAX
-- MbedOS Error Info --
HAL_RTC_SetDate error发布于 2020-04-26 00:04:41
问题最终被追踪到另一个部分,即代码库,最终在3跳之后调用以下代码的执行:
HAL_PWR_DisableBkUpAccess();我的印象是,这一行只禁止访问RTC备份数据寄存器(在代码库中使用)和备份SRAM。但是根据用户手册,不管它的名字是什么,它也禁止访问RTC寄存器,在mbed上的RTC初始化期间,它的对应部分被调用。
HAL_PWR_EnableBkUpAccess();https://stackoverflow.com/questions/61419541
复制相似问题