在使用Mbed-OS 5的STM32F4上出现间歇性但重复的HAL_RTC_SetDate错误。

问题描述 投票:0回答:1

我一直想弄清楚我的PCB嵌入式代码出了什么问题。PCB是围绕STM32F407VE设计的,set_time()每5102060120秒调用一次。

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次调用会触发系统崩溃。

2) 如果我注释掉set_time(),那么系统就不会崩溃了。但如果注释掉的代码被启用,它将重现问题。

    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()的第一个代码块是通过ticker调用的,ticker从HSE中获取时钟。当我在审查RTC从LSI来源时的控制台输出时(附在下面),我意识到在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
embedded mbed stm32f4
1个回答
2
投票

这个问题最终被追踪到代码库的另一部分,最终在3跳后调用执行。

HAL_PWR_DisableBkUpAccess();

我印象中,这一行只禁止访问RTC备份数据寄存器(在代码库中使用)和备份SRAM。但根据用户手册,尽管它的名字是这样的,但它也禁止访问RTC寄存器,而且在mbed上的RTC初始化过程中也会调用它。

HAL_PWR_EnableBkUpAccess();
© www.soinside.com 2019 - 2024. All rights reserved.