2024-04-05 05:57 AM
Hi,
I am getting the below warning when I compile my application. However, HAL_RTC_GetTime API expects the first argument of type pointer to a RTC_HandleTypeDef structure, thats what I provide, but I get this warning as highlighted below.
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
arm-none-eabi-size RTC.elf
arm-none-eabi-objdump -h -S RTC.elf > "RTC.list"
text data bss dec hex filename
16684 112 2408 19204 4b04 RTC.elf
Finished building: default.size.stdout
Finished building: RTC.list
15:34:19 Build Finished. 0 errors, 2 warnings. (took 2s.589ms)
Could anyone please help me resolve ?
Thank you.
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <string.h>
#include <stdio.h>
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
RTC_HandleTypeDef hrtc;
UART_HandleTypeDef huart2;
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_RTC_Init(void);
static void MX_USART2_UART_Init(void);
/* USER CODE BEGIN PFP */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
char* getDayofWeek(uint8_t number);
char msg[200] ={0};
char msg2[200]={0};
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_RTC_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = 8;
RCC_OscInitStruct.PLL.PLLN = 50;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
RCC_OscInitStruct.PLL.PLLQ = 7;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief RTC Initialization Function
* @PAram None
* @retval None
*/
static void MX_RTC_Init(void)
{
/* USER CODE BEGIN RTC_Init 0 */
/* USER CODE END RTC_Init 0 */
RTC_TimeTypeDef sTime = {0};
RTC_DateTypeDef sDate = {0};
RTC_AlarmTypeDef sAlarm = {0};
/* USER CODE BEGIN RTC_Init 1 */
/* USER CODE END RTC_Init 1 */
/** Initialize RTC Only
*/
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = 127;
hrtc.Init.SynchPrediv = 255;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN Check_RTC_BKUP */
/* USER CODE END Check_RTC_BKUP */
/** Initialize RTC and set the Time and Date
*/
sTime.Hours = 0x12;
sTime.Minutes = 0x0;
sTime.Seconds = 0x15;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
{
Error_Handler();
}
sDate.WeekDay = RTC_WEEKDAY_FRIDAY;
sDate.Month = RTC_MONTH_APRIL;
sDate.Date = 0x12;
sDate.Year = 0x24;
if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK)
{
Error_Handler();
}
/** Enable the Alarm A
*/
sAlarm.AlarmTime.Hours = 0x12;
sAlarm.AlarmTime.Minutes = 0x0;
sAlarm.AlarmTime.Seconds = 0x15;
sAlarm.AlarmTime.SubSeconds = 0x0;
sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY;
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
sAlarm.AlarmDateWeekDay = 0x31;
sAlarm.Alarm = RTC_ALARM_A;
if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BCD) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN RTC_Init 2 */
/* USER CODE END RTC_Init 2 */
}
/**
* @brief USART2 Initialization Function
* @PAram None
* @retval None
*/
static void MX_USART2_UART_Init(void)
{
/* USER CODE BEGIN USART2_Init 0 */
/* USER CODE END USART2_Init 0 */
/* USER CODE BEGIN USART2_Init 1 */
/* USER CODE END USART2_Init 1 */
huart2.Instance = USART2;
huart2.Init.BaudRate = 115200;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART2_Init 2 */
/* USER CODE END USART2_Init 2 */
}
/**
* @brief GPIO Initialization Function
* @PAram None
* @retval None
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15, GPIO_PIN_RESET);
/*Configure GPIO pin : PA0 */
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pins : PD12 PD13 PD14 PD15 */
GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
/* USER CODE BEGIN MX_GPIO_Init_2 */
/* USER CODE END MX_GPIO_Init_2 */
}
/* USER CODE BEGIN 4 */
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
{
printf("Alarm is triggered\n\r");
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_14);
RTC_TimeTypeDef RTC_TimeRead;
RTC_DateTypeDef RTC_DateRead;
HAL_RTC_GetTime(&hrtc, &RTC_TimeRead, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &RTC_DateRead,RTC_FORMAT_BIN);
if(RTC_TimeRead.TimeFormat == 0)
{
printf("current time is: %02d:%02d:%02d AM\r\n",RTC_TimeRead.Hours,RTC_TimeRead.Minutes,RTC_TimeRead.Seconds);
}
else
{
printf("current time is: %02d:%02d:%02d PM\r\n",RTC_TimeRead.Hours,RTC_TimeRead.Minutes,RTC_TimeRead.Seconds);
}
// sprintf(msg,"current time is: %02d:%02d:%02d\r\n",RTC_TimeRead.Hours,RTC_TimeRead.Minutes,RTC_TimeRead.Seconds);
HAL_UART_Transmit(&huart2, (uint8_t*)msg,1,1000);
//sprintf(msg2,"current date is:%02d-%02d-%02d-%s\r\n",RTC_DateRead.Month,RTC_DateRead.Date, RTC_DateRead.Year,getDayofWeek(RTC_DateRead.WeekDay));
printf("current date is: %02d-%02d-%02d-%s\r\n",RTC_DateRead.Month,RTC_DateRead.Date,RTC_DateRead.Year,getDayofWeek(RTC_DateRead.WeekDay));
HAL_UART_Transmit(&huart2, (uint8_t*)msg2,20,1000);
HAL_Delay(2000);
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_14);
}
char* getDayofWeek(uint8_t number)
{
char* weekday[] = {"monday","tuesday","wednesday","thursday","friday","saturday","sunday"};
return weekday[number-1];
}
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART1 and Loop until the end of transmission */
HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
RTC_TimeTypeDef RTC_TimeRead;
RTC_DateTypeDef RTC_DateRead;
HAL_RTC_GetTime(&hrtc, &RTC_TimeRead, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &RTC_DateRead,RTC_FORMAT_BIN);
if(RTC_TimeRead.TimeFormat == 0)
{
printf("current time is: %02d:%02d:%02d AM\r\n",RTC_TimeRead.Hours,RTC_TimeRead.Minutes,RTC_TimeRead.Seconds);
}
else
{
printf("current time is: %02d:%02d:%02d PM\r\n",RTC_TimeRead.Hours,RTC_TimeRead.Minutes,RTC_TimeRead.Seconds);
}
// sprintf(msg,"current time is: %02d:%02d:%02d\r\n",RTC_TimeRead.Hours,RTC_TimeRead.Minutes,RTC_TimeRead.Seconds);
HAL_UART_Transmit(&huart2, (uint8_t*)msg,1,1000);
//sprintf(msg2,"current date is:%02d-%02d-%02d-%s\r\n",RTC_DateRead.Month,RTC_DateRead.Date, RTC_DateRead.Year,getDayofWeek(RTC_DateRead.WeekDay));
printf("current date is: %02d-%02d-%02d-%s\r\n",RTC_DateRead.Month,RTC_DateRead.Date,RTC_DateRead.Year,getDayofWeek(RTC_DateRead.WeekDay));
HAL_UART_Transmit(&huart2, (uint8_t*)msg2,20,1000);
}
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @PAram file: pointer to the source file name
* @PAram line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
Solved! Go to Solution.
2024-04-05 06:06 AM - edited 2024-04-05 06:23 AM
Hello,
It seems a conflict between the first input argument of the callback and the definition of the global rtc handle declared in the top of your main.c:
/* Private variables ---------------------------------------------------------*/
RTC_HandleTypeDef hrtc;
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
{
printf("Alarm is triggered\n\r");
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_14);
RTC_TimeTypeDef RTC_TimeRead;
RTC_DateTypeDef RTC_DateRead;
HAL_RTC_GetTime(&hrtc, &RTC_TimeRead, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &RTC_DateRead,RTC_FORMAT_BIN);
So remove & before hrtc from here:
HAL_RTC_GetTime(&hrtc, &RTC_TimeRead, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &RTC_DateRead,RTC_FORMAT_BIN);
Does it resolve your issue?
2024-04-05 06:06 AM - edited 2024-04-05 06:23 AM
Hello,
It seems a conflict between the first input argument of the callback and the definition of the global rtc handle declared in the top of your main.c:
/* Private variables ---------------------------------------------------------*/
RTC_HandleTypeDef hrtc;
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
{
printf("Alarm is triggered\n\r");
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_14);
RTC_TimeTypeDef RTC_TimeRead;
RTC_DateTypeDef RTC_DateRead;
HAL_RTC_GetTime(&hrtc, &RTC_TimeRead, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &RTC_DateRead,RTC_FORMAT_BIN);
So remove & before hrtc from here:
HAL_RTC_GetTime(&hrtc, &RTC_TimeRead, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &RTC_DateRead,RTC_FORMAT_BIN);
Does it resolve your issue?
2024-04-05 06:15 AM - edited 2024-04-05 06:17 AM
input handle hrtc is already a pointer, so only remove the "&" for hrtc.
HAL_RTC_GetTime(hrtc, &RTC_TimeRead, RTC_FORMAT_BIN);
That is why I don't like HAL, as hrtc might be a handle, or a pointer to a handle.
In my C sources, pointers always start with "p", like phRtc, or pu32Var.
It really helps to avoid these problems.
2024-04-05 06:25 AM - edited 2024-04-05 06:44 AM
Note that the compiler was telling you that you were providing a pointer-to-pointer (double indirection):
2024-04-05 06:48 AM
@LCE wrote:That is why I don't like HAL, as hrtc might be a handle, or a pointer to a handle.
In my C sources, pointers always start with "p", like phRtc, or pu32Var.
It's not really the fault of HAL here.
This is in user code - so the user could have (should have?) chosen to use such a naming convention; eg,
void HAL_RTC_AlarmAEventCallback( RTC_HandleTypeDef *pHrtc )
{
printf( "Alarm is triggered\n\r" );
HAL_GPIO_TogglePin( GPIOD, GPIO_PIN_14 );
RTC_TimeTypeDef RTC_TimeRead;
RTC_DateTypeDef RTC_DateRead;
HAL_RTC_GetTime( pHrtc, &RTC_TimeRead, RTC_FORMAT_BIN );
HAL_RTC_GetDate( pHrtc, &RTC_DateRead, RTC_FORMAT_BIN );
2024-04-07 10:42 PM
Using the same name for a handle and a pointer as a function call argument - I've seen that in many Cube / HAL sources.