你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

向 “HAL_RTC_GetTime” 函数传递的第一个参数出现指针类型不兼容警告

[复制链接]
patch1582 提问时间:2026-5-19 17:26 / 未解决

我在编译应用程序时出现以下警告。HAL_RTC_GetTime 函数要求第一个参数是 RTC_HandleTypeDef 结构体指针,我认为传入的正是这个类型,但仍然收到类型不兼容警告。

15:34:16 Incremental Build of configuration Debug for project RTC

make -j8 all

arm-none-eabi-gcc "../Core/Src/main.c" -mcpu=cortex-m4 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F407xx -c -I../Core/Inc -I../Drivers/STM32F4xx_HAL_Driver/Inc -I../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32F4xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Core/Src/main.d" -MT"Core/Src/main.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Core/Src/main.o"

../Core/Src/main.c: In function 'HAL_RTC_AlarmAEventCallback':

../Core/Src/main.c:337:49: warning: passing argument 1 of 'HAL_RTC_GetTime' from incompatible pointer type [-Wincompatible-pointer-types]

337 | HAL_RTC_GetTime(&hrtc, &RTC_TimeRead, RTC_FORMAT_BIN);

| ^~~~~

| |

| RTC_HandleTypeDef ** In file included from ../Core/Inc/stm32f4xx_hal_conf.h:391,

         from ../Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.h:29,

         from ../Core/Inc/main.h:30,

         from ../Core/Src/main.c:20:

../Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rtc.h:714:54: note: expected 'RTC_HandleTypeDef *' but argument is of type 'RTC_HandleTypeDef **'

714 | HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef hrtc, RTC_TimeTypeDef sTime, uint32_t Format);

| ~~~~~^~ ../Core/Src/main.c:338:49: warning: passing argument 1 of 'HAL_RTC_GetDate' from incompatible pointer type [-Wincompatible-pointer-types]

338 | HAL_RTC_GetDate(&hrtc, &RTC_DateRead,RTC_FORMAT_BIN);

| ^~~~~

| |

| RTC_HandleTypeDef ** In file included from ../Core/Inc/stm32f4xx_hal_conf.h:391,

         from ../Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.h:29,

         from ../Core/Inc/main.h:30,

         from ../Core/Src/main.c:20:

../Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rtc.h:716:54: note: expected 'RTC_HandleTypeDef *' but argument is of type 'RTC_HandleTypeDef **'

716 | HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef hrtc, RTC_DateTypeDef sDate, uint32_t Format);

| ~~~~~^~ arm-none-eabi-gcc -o "RTC.elf" @"objects.list" -mcpu=cortex-m4 -T"C:\Users\bjvyhb\OneDrive - PHINIA\Desktop\MCU\Workspace\RTOS_Workspace\RTC\STM32F407VGTX_FLASH.ld" --specs=nosys.specs -Wl,-Map="RTC.map" -Wl,--gc-sections -static --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -Wl,--start-group -lc -lm -Wl,--end-group

Finished building target: RTC.elf

函数调用如下

HAL_RTC_GetTime(&hrtc, &RTC_TimeRead, RTC_FORMAT_BIN);

    HAL_RTC_GetDate(&hrtc, &RTC_DateRead,RTC_FORMAT_BIN);
收藏 评论1 发布时间:2026-5-19 17:26

举报

1个回答
STM1024 回答时间:2 小时前
看这里:
RTC_HandleTypeDef *' but argument is of type 'RTC_HandleTypeDef **'
你看看你的hrtc的定义,是一个结构体,还是一个结构体指针?
关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版