STMicroelectronics / cmsis_device_f4

Provides the STM32Cube MCU Component "cmsis_device_f4" of the STM32F4 series.
Apache License 2.0
56 stars 24 forks source link

Using '__IOM' for peripheral register definitions #3

Closed utkarshsethi closed 3 years ago

utkarshsethi commented 3 years ago

Additional context

Is there a specific reason to not use 'IO' for peripheral register definitions instead of 'IOM' as per guidelines for versions greater than v4.2?

typedef struct { __IO uint32_t SR; /*!< ADC status register, Address offset: 0x00 */ __IO uint32_t CR1; /*!< ADC control register 1, Address offset: 0x04 */ __IO uint32_t CR2; /*!< ADC control register 2, Address offset: 0x08 */ __IO uint32_t SMPR1; /*!< ADC sample time register 1, Address offset: 0x0C */ __IO uint32_t SMPR2; /*!< ADC sample time register 2, Address offset: 0x10 */ __IO uint32_t JOFR1; /*!< ADC injected channel data offset register 1, Address offset: 0x14 */ __IO uint32_t JOFR2; /*!< ADC injected channel data offset register 2, Address offset: 0x18 */ __IO uint32_t JOFR3; /*!< ADC injected channel data offset register 3, Address offset: 0x1C */ __IO uint32_t JOFR4; /*!< ADC injected channel data offset register 4, Address offset: 0x20 */ __IO uint32_t HTR; /*!< ADC watchdog higher threshold register, Address offset: 0x24 */ __IO uint32_t LTR; /*!< ADC watchdog lower threshold register, Address offset: 0x28 */ __IO uint32_t SQR1; /*!< ADC regular sequence register 1, Address offset: 0x2C */ __IO uint32_t SQR2; /*!< ADC regular sequence register 2, Address offset: 0x30 */ __IO uint32_t SQR3; /*!< ADC regular sequence register 3, Address offset: 0x34 */ __IO uint32_t JSQR; /*!< ADC injected sequence register, Address offset: 0x38*/ __IO uint32_t JDR1; /*!< ADC injected data register 1, Address offset: 0x3C */ __IO uint32_t JDR2; /*!< ADC injected data register 2, Address offset: 0x40 */ __IO uint32_t JDR3; /*!< ADC injected data register 3, Address offset: 0x44 */ __IO uint32_t JDR4; /*!< ADC injected data register 4, Address offset: 0x48 */ __IO uint32_t DR; /*!< ADC regular data register, Address offset: 0x4C */ } ADC_TypeDef;

https://developer.arm.com/documentation/ka002980/latest

Note: Since CMSIS-Core V4.20 the macros I, O and IO should only be used for scalar variables. For peripheral register definitions in structures, the macros IM, OM and IOM should now be used. The definition __IM always contains the const type qualifier because C++ does not optimize struct-members to constants. This way, registers can be write-protected even in C++.

or https://github.com/ARM-software/CMSIS_5/blob/develop/CMSIS/Core/Include/core_cm4.h#L229 `/ following defines should be used for structure members /

define __IM volatile const /! Defines 'read only' structure member permissions /

define __OM volatile /! Defines 'write only' structure member permissions /

define __IOM volatile /! Defines 'read / write' structure member permissions /`

RKOUSTM commented 3 years ago

Hi @utkarshsethi,

Thank you for your contribution.

This request will be forwarded to our technical committee. I will be back to you as soon as they provide me with their answer.

This duplicated issue will remain closed. This pull-request will be kept open to track the point.

Thank you again for your contribution.

With regards,

ALABSTM commented 4 months ago

ST Internal Reference: 109857