You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

STM32L072 timeLimit类时间转换嵌套调用异常求助

Weird Wrong Value When Nesting HW_RTC_Tick2ms in PPRINTF Calls (STM32L072, I-CUBE-LRWAN v1.2.1)

Let me break down what's happening here—your issue has nothing to do with the HW_RTC_Tick2ms function itself or nesting calls to it. The problem is a mismatch between format specifiers and the number of arguments you're passing to PPRINTF.

The Root Cause

Look closely at your SEMI and ORI section PPRINTF calls, for example:

PPRINTF("\t current time: %i\r\n", __PRETTY_FUNCTION__, HW_RTC_Tick2ms(subdiv));

You're using a single %i format specifier, but passing two arguments: __PRETTY_FUNCTION__ (a string pointer) and the result of HW_RTC_Tick2ms(subdiv).

Since PPRINTF works like standard printf (it uses format specifiers to know how many values to pull from the stack), it only reads the first argument as the %i value. That first argument is the memory address of the __PRETTY_FUNCTION__ string constant (stored in your STM32's Flash, which starts at 0x8000000). The value 134318771 is exactly 0x8018AB3—that's the pointer value being interpreted as an integer!

Your earlier calls (like PPRINTF("now: %i\r\n",HW_RTC_Tick2ms(now));) work because they have one format specifier and one argument—no mismatch, so the stack is parsed correctly.

Fix Steps

You need to align your format specifiers with the number of arguments you're passing. Here are two ways to fix this:

  1. Remove the extra __PRETTY_FUNCTION__ argument if you don't need to print it in those lines:
// SEMI section fixed
PPRINTF("\t current time: %i\r\n", HW_RTC_Tick2ms(subdiv));
PPRINTF("\t timeout time: %i\r\n", HW_RTC_Tick2ms(between));
PPRINTF("\t time to send: %i\r\n", HW_RTC_Tick2ms(between - subdiv));

// ORI section fixed
PPRINTF("\t current time: %i\r\n", HW_RTC_Tick2ms(HW_RTC_GetTimerValue() - startTime));
PPRINTF("\t timeout time: %i\r\n", HW_RTC_Tick2ms(sendDelayTime));
PPRINTF("\t time to send: %i\r\n", HW_RTC_Tick2ms(sendDelayTime - (HW_RTC_GetTimerValue() - startTime)));
  1. Add a %s specifier if you do want to include the function name in the output:
PPRINTF("%s: current time: %i\r\n", __PRETTY_FUNCTION__, HW_RTC_Tick2ms(subdiv));

Verification

Once you fix the format specifier/argument mismatch, the nested calls to HW_RTC_Tick2ms will return the correct values, matching what you see when you store the result in a variable first. The __nop() calls you added for Keil's stack viewer aren't related to this issue—they can stay if you need them for that purpose.

内容的提问来源于stack exchange,提问作者Trick

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:26:09