Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the volatile qualifier deprecated in c++20?

I just downloaded GCC 10 with c++20 on my embedded project.

However in embedded applications it's quite common to use volatile for Register Struct Mappers.

Since the compiler does not know if the Register value was changed externally by a DMA, it makes sense to "force" a reload of this register.

To increase performance some of these volatiles are placed in C Header files. When I include these headers in a cpp file, i get lot's of volatile deprecation errors.

Is there any way to disable these errors?

@Edit As requested some example code.

/*!
 * @brief Enable the clock for specific IP.
 *
 * @param name  Which clock to enable, see \ref clock_ip_name_t.
 */
static inline void CLOCK_EnableClock(clock_ip_name_t name)
{
    uint32_t regAddr = SIM_BASE + CLK_GATE_ABSTRACT_REG_OFFSET((uint32_t)name);
    (*(volatile uint32_t *)regAddr) |= (1UL << CLK_GATE_ABSTRACT_BITS_SHIFT((uint32_t)name));
}
C:/xxx/kinetisSDK/2.7.0/devices/MK64F12/drivers/fsl_clock.h:671:37: error: compound assignment with 'volatile'-qualified left operand is deprecated [- Werror=volatile] 
671 |     (*(volatile uint32_t *)regAddr) |= (1UL << CLK_GATE_ABSTRACT_BITS_SHIFT((uint32_t)name));      |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Since these defines are spread throughout NXP SDK I tried to extract only the necessary parts.

https://godbolt.org/z/WKzj5j

However Godbolt seems to be fine. Maybe it's because I'm using gcc 10 for arm eabi.

like image 797
JHeni Avatar asked Mar 01 '23 19:03

JHeni


1 Answers

You can't use |= anymore, but you can use =, so change this:

(*(volatile uint32_t *)regAddr) |= (1UL << CLK_GATE_ABSTRACT_BITS_SHIFT((uint32_t)name));

To this:

*(volatile uint32_t *)regAddr = *(volatile uint32_t *)regAddr | (1UL << CLK_GATE_ABSTRACT_BITS_SHIFT((uint32_t)name));
like image 107
John Zwinck Avatar answered Mar 08 '23 01:03

John Zwinck