I posted the same question in the STM32 community forum as well, but didn't receive an answer.
I am using stm32 HAL library in a project with C++14 enabled. It issues me the following warning which I can't get rid of.
../platform/stm32/l4/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_rcc.h:735:57:
warning: conversion to void will not access object of type 'volatile uint32_t {aka volatile long unsigned int}' UNUSED(tmpreg); \
This happens, when a call to __GPIOX_CLK_ENABLE() or __HAL_RCC_GPIOX_CLK_ENABLE is called.
Has anyone been able to get rid of the above warning leaving the HAL source code intact.
Or any ideas as what is possible to be done.
The current warning level is -Wall.
I've experienced the above issue with both l4 & f4 series code.
An Example code:
int main(void)
{
HAL_Init();
__GPIOB_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.Pin = GPIO_PIN_7;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
GPIO_InitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
for (;;)
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_SET);
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_RESET);
HAL_Delay(500);
}
}
The culprit is __GPIOB_CLK_ENABLE()
, which gets expanded to the following(in ST drivers).
#define __HAL_RCC_GPIOB_CLK_ENABLE() do { \
__IO uint32_t tmpreg; \
SET_BIT(RCC->AHB2ENR, RCC_AHB2ENR_GPIOBEN); \
/* Delay after an RCC peripheral clock enabling */ \
tmpreg = READ_BIT(RCC->AHB2ENR, RCC_AHB2ENR_GPIOBEN); \
UNUSED(tmpreg); \
} while(0)
My original question is intended to find out a solution, leaving the underlying ST driver intact. One possible solution would be to use the direct register access without going through the library provided convenient macro.
Thank you in advance.
UNUSED
macro, which is part of the mentioned macros, cast a volatile reference tovoid
. It is not related to C++14 nor -Wall, but all g++ versions give the same diagnostic. The reason why can be found in the linked duplicate. The solution would be not to use volatile references, which is fishy practice when writing hardware-related code - use volatile pointers instead. Perhaps you are using a reference by accident? – Lundin-Wall
. It is definitely notall g++
compiler versions. That is the reason behind this question. – aepduplicate
. I would urge you to download the STM32 CubeMX HAL source code and compile it both in C++11 & C++14. The warning becomes evident in C++14 but never in C++11. – aep