Ref_Peripheral.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /**************************************************************************************************/
  2. /**
  3. \defgroup peripheral_gr Peripheral Access
  4. \brief Naming conventions and optional features for accessing peripherals.
  5. \details
  6. The section below describes the naming conventions, requirements, and optional features for accessing device specific peripherals.
  7. Most of the rules also apply to the core peripherals. The \ref device_h_pg contains typically these definition and also includes
  8. the core specific header files.
  9. \ifnot FuSaRTS
  10. The definitions for \ref peripheral_gr can be generated using the <a href="../../SVD/html/index.html"><b>CMSIS-SVD</b></a> System View Description for Peripherals.
  11. Refer to <a href="../../SVD/html/svd_SVDConv_pg.html"><b>SVDConv.exe</b></a> for more information.
  12. \endif
  13. Each peripheral provides a data type definition with a name that is composed of:
  14. - an optional prefix <b>&lt;<i>device abbreviation&gt;</i>_</b>
  15. - <b>&lt;<i>peripheral name</i>&gt;</b>
  16. - postfix \b _Type or \b _TypeDef to identify a type definition.
  17. Examples:
  18. - \b UART_TypeDef for the peripheral \b UART.
  19. - \b LPC_UART_TypeDef for the device family \b LPC and the peripheral \b UART.
  20. The data type definition uses standard C data types defined by the ANSI C header file <stdint.h>.
  21. - IO Type Qualifiers are used to specify the access to peripheral variables.
  22. IO Type Qualifier | Type | Description
  23. :------------------|:----------------|:------------
  24. \b __IM | Struct member | Defines 'read only' permissions
  25. \b __OM | Struct member | Defines 'write only' permissions
  26. \b __IOM | Struct member | Defines 'read / write' permissions
  27. \b __I | Scalar variable | Defines 'read only' permissions
  28. \b __O | Scalar variable | Defines 'write only' permissions
  29. \b __IO | Scalar variable | Defines 'read / write' permissions
  30. \note
  31. \b __IM, \b __OM, \b __IOM are added in CMSIS-Core V4.20 to enhance support for C++. Prior version used \b __I, \b __O, \b __IO also for struct member definitions.
  32. The typedef <b>\<<i>device abbreviation</i>\>_UART_TypeDef</b> shown below defines the generic register layout for all UART channels in a device.
  33. \code
  34. typedef struct
  35. {
  36. union {
  37. __IM uint8_t RBR; /* Offset: 0x000 (R/ ) Receiver Buffer Register */
  38. __OM uint8_t THR; /* Offset: 0x000 ( /W) Transmit Holding Register */
  39. __IOM uint8_t DLL; /* Offset: 0x000 (R/W) Divisor Latch LSB */
  40. uint32_t RESERVED0;
  41. };
  42. union {
  43. __IOM uint8_t DLM; /* Offset: 0x004 (R/W) Divisor Latch MSB */
  44. __IOM uint32_t IER; /* Offset: 0x004 (R/W) Interrupt Enable Register */
  45. };
  46. union {
  47. __IM uint32_t IIR; /* Offset: 0x008 (R/ ) Interrupt ID Register */
  48. __OM uint8_t FCR; /* Offset: 0x008 ( /W) FIFO Control Register */
  49. };
  50. __IOM uint8_t LCR; /* Offset: 0x00C (R/W) Line Control Register */
  51. uint8_t RESERVED1[7];
  52. __IM uint8_t LSR; /* Offset: 0x014 (R/ ) Line Status Register */
  53. uint8_t RESERVED2[7];
  54. __IOM uint8_t SCR; /* Offset: 0x01C (R/W) Scratch Pad Register */
  55. uint8_t RESERVED3[3];
  56. __IOM uint32_t ACR; /* Offset: 0x020 (R/W) Autobaud Control Register */
  57. __IOM uint8_t ICR; /* Offset: 0x024 (R/W) IrDA Control Register */
  58. uint8_t RESERVED4[3];
  59. __IOM uint8_t FDR; /* Offset: 0x028 (R/W) Fractional Divider Register */
  60. uint8_t RESERVED5[7];
  61. __IOM uint8_t TER; /* Offset: 0x030 (R/W) Transmit Enable Register */
  62. uint8_t RESERVED6[39];
  63. __IM uint8_t FIFOLVL; /* Offset: 0x058 (R/ ) FIFO Level Register */
  64. } LPC_UART_TypeDef;
  65. \endcode
  66. To access the registers of the UART defined above, pointers to this register structure are defined.
  67. If more instances of a peripheral exist, the variables have a postfix (digit or letter) that identifies the peripheral.
  68. \b Example:
  69. In this example \b LPC_UART2 and \b LPC_UART3 are two pointers to UARTs defined with above register structure.
  70. \n
  71. \code
  72. #define LPC_UART2 ((LPC_UART_TypeDef *) LPC_UART2_BASE )
  73. #define LPC_UART3 ((LPC_UART_TypeDef *) LPC_UART3_BASE )
  74. \endcode
  75. \note
  76. - The prefix <b>LPC</b> is optional.
  77. The registers in the various UARTs can now be referred in the user code as shown below:\n
  78. \code
  79. val = LPC_UART2->DR // is the data register of UART1.
  80. \endcode
  81. <hr>
  82. \section core_cmsis_pal_min_reqs Minimal Requirements
  83. \details
  84. To access the peripheral registers and related function in a device, the files <b><i>device.h</i></b> and <b>core_cm<i>#</i>.h</b> define as a minimum:
  85. \n\n
  86. - The <b>Register Layout Typedef</b> for each peripheral that defines all register names.
  87. RESERVED is used to introduce space into the structure for adjusting the addresses of
  88. the peripheral registers.
  89. \n\n
  90. <b>Example:</b>
  91. \code
  92. typedef struct
  93. {
  94. __IOM uint32_t CTRL; /* Offset: 0x000 (R/W) SysTick Control and Status Register */
  95. __IOM uint32_t LOAD; /* Offset: 0x004 (R/W) SysTick Reload Value Register */
  96. __IOM uint32_t VAL; /* Offset: 0x008 (R/W) SysTick Current Value Register */
  97. __IM uint32_t CALIB; /* Offset: 0x00C (R/ ) SysTick Calibration Register */
  98. } SysTick_Type;
  99. \endcode
  100. - <b>Base Address</b> for each peripheral (in case of multiple peripherals
  101. that use the same <b>register layout typedef</b> multiple base addresses are defined).
  102. \n\n
  103. <b>Example:</b>
  104. \code
  105. #define SysTick_BASE (SCS_BASE + 0x0010) /* SysTick Base Address */
  106. \endcode
  107. - <b>Access Definitions</b> for each peripheral. In case of multiple peripherals that are using the same
  108. <b>register layout typdef</b>, multiple access definitions exist (LPC_UART0, LPC_UART2).
  109. \n\n
  110. <b>Example:</b>
  111. \code
  112. #define SysTick ((SysTick_Type *) Systick_BASE) /* SysTick access definition */
  113. \endcode
  114. These definitions allow accessing peripheral registers with simple assignments.
  115. - <b>Example:</b>
  116. \n
  117. \code
  118. SysTick->CTRL = 0;
  119. \endcode
  120. <hr>
  121. \section core_cmsis_pal_opts Optional Features
  122. \details
  123. Optionally, the file <b><i>device</i>.h</b> may define:
  124. - \ref core_cmsis_pal_bitfields and \#define constants that simplify access to peripheral registers.
  125. These constants may define bit-positions or other specific patterns that are required for
  126. programming peripheral registers. The identifiers should start with
  127. <b>&lt;<i>device abbreviation</i>&gt;_</b> and <b>&lt;<i>peripheral name</i>&gt;_</b>.
  128. It is recommended to use CAPITAL letters for \#define constants.
  129. - More complex functions (i.e. status query before
  130. a sending register is accessed). Again, these functions start with
  131. <b>&lt;<i>device abbreviation</i>&gt;_</b> and <b>&lt;<i>peripheral name</i>&gt;_</b>.
  132. <hr>
  133. \section core_cmsis_pal_bitfields Register Bit Fields
  134. \details
  135. For Core Register, macros define the position and the mask value for a bit field. It is recommended to create such definitions also
  136. for other peripheral registers.
  137. <b>Example:</b>
  138. Bit field definitions for register CPUID in SCB (System Control Block).
  139. \code
  140. /* SCB CPUID Register Definitions */
  141. #define SCB_CPUID_IMPLEMENTER_Pos 24U /*!< SCB CPUID: IMPLEMENTER Position */
  142. #define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */
  143. #define SCB_CPUID_VARIANT_Pos 20U /*!< SCB CPUID: VARIANT Position */
  144. #define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */
  145. #define SCB_CPUID_ARCHITECTURE_Pos 16U /*!< SCB CPUID: ARCHITECTURE Position */
  146. #define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */
  147. #define SCB_CPUID_PARTNO_Pos 4U /*!< SCB CPUID: PARTNO Position */
  148. #define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */
  149. #define SCB_CPUID_REVISION_Pos 0U /*!< SCB CPUID: REVISION Position */
  150. #define SCB_CPUID_REVISION_Msk (0xFUL /*<< SCB_CPUID_REVISION_Pos*/) /*!< SCB CPUID: REVISION Mask */
  151. \endcode
  152. The macros <b>_VAL2FLD(field, value)</b> and <b>_FLD2VAL(field, value)</b> enable access to bit fields.
  153. @{
  154. */
  155. /**
  156. \def _VAL2FLD(field, value)
  157. \param field name of bit field.
  158. \param value value for the bit field. This parameter is interpreted as an uint32_t type.
  159. \brief Mask and shift a bit field value for assigning the result to a peripheral register.
  160. \details
  161. The macro \ref _VAL2FLD uses the \#define's <i>_Pos</i> and <i>_Msk</i> of the related bit field to shift bit-field values for
  162. assigning to a register.
  163. <b>Example:</b>
  164. \code
  165. SCB->CPUID = _VAL2FLD(SCB_CPUID_REVISION, 0x3) | _VAL2FLD(SCB_CPUID_VARIANT, 0x3);
  166. \endcode
  167. */
  168. #define _VAL2FLD(field, value)
  169. /**
  170. \def _FLD2VAL(field, value)
  171. \param field name of bit field.
  172. \param value value of the register. This parameter is interpreted as an uint32_t type.
  173. \brief Extract from a peripheral register value the a bit field value.
  174. \details
  175. The macro \ref _FLD2VAL uses the \#define's <i>_Pos</i> and <i>_Msk</i> of the related bit field to extract the value of a bit field from a register.
  176. <b>Example:</b>
  177. \code
  178. id = _FLD2VAL(SCB_CPUID_REVISION, SCB->CPUID);
  179. \endcode
  180. */
  181. #define _FLD2VAL(field, value)
  182. /**
  183. @}
  184. */