File indexing completed on 2025-05-11 08:23:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef LIBBSP_ARM_STM32F4_STM32F4XXXX_RCC_H
0016 #define LIBBSP_ARM_STM32F4_STM32F4XXXX_RCC_H
0017
0018 #include <bsp/utility.h>
0019
0020
0021
0022
0023
0024
0025
0026
0027 typedef struct {
0028 uint32_t cr;
0029 #define STM32F4_RCC_CR_PLLI2SRDY BSP_BIT32(27)
0030 #define STM32F4_RCC_CR_PLLI2SON BSP_BIT32(26)
0031 #define STM32F4_RCC_CR_PLLRDY BSP_BIT32(25)
0032 #define STM32F4_RCC_CR_PLLON BSP_BIT32(24)
0033 #define STM32F4_RCC_CR_CSSON BSP_BIT32(19)
0034 #define STM32F4_RCC_CR_HSEBYP BSP_BIT32(18)
0035 #define STM32F4_RCC_CR_HSERDY BSP_BIT32(17)
0036 #define STM32F4_RCC_CR_HSEON BSP_BIT32(16)
0037 #define STM32F4_RCC_CR_HSIRDY BSP_BIT32(1)
0038 #define STM32F4_RCC_CR_HSION BSP_BIT32(0)
0039
0040 uint32_t pllcfgr;
0041 #define STM32F4_RCC_PLLCFGR_PLLQ(val) BSP_FLD32(val, 24, 27)
0042 #define STM32F4_RCC_PLLCFGR_PLLQ_GET(reg) BSP_FLD32GET(reg, 24, 27)
0043 #define STM32F4_RCC_PLLCFGR_PLLQ_SET(reg, val) BSP_FLD32SET(reg, val, 24, 27)
0044 #define STM32F4_RCC_PLLCFGR_SRC BSP_BIT32(22)
0045 #define STM32F4_RCC_PLLCFGR_SRC_HSE STM32F4_RCC_PLLCFGR_SRC
0046 #define STM32F4_RCC_PLLCFGR_SRC_HSI 0
0047 #define STM32F4_RCC_PLLCFGR_PLLP(val) BSP_FLD32(val, 16, 17)
0048 #define STM32F4_RCC_PLLCFGR_PLLP_GET(reg) BSP_FLD32GET(reg, 16, 17)
0049 #define STM32F4_RCC_PLLCFGR_PLLP_SET(reg, val) BSP_FLD32SET(reg, val, 16, 17)
0050 #define STM32F4_RCC_PLLCFGR_PLLP_2 STM32F4_RCC_PLLCFGR_PLLP(0)
0051 #define STM32F4_RCC_PLLCFGR_PLLP_4 STM32F4_RCC_PLLCFGR_PLLP(1)
0052 #define STM32F4_RCC_PLLCFGR_PLLP_6 STM32F4_RCC_PLLCFGR_PLLP(2)
0053 #define STM32F4_RCC_PLLCFGR_PLLP_8 STM32F4_RCC_PLLCFGR_PLLP(3)
0054 #define STM32F4_RCC_PLLCFGR_PLLN(val) BSP_FLD32(val, 6, 14)
0055 #define STM32F4_RCC_PLLCFGR_PLLN_GET(reg) BSP_FLD32GET(reg, 6, 14)
0056 #define STM32F4_RCC_PLLCFGR_PLLN_SET(reg, val) BSP_FLD32SET(reg, val, 6, 14)
0057 #define STM32F4_RCC_PLLCFGR_PLLM(val) BSP_FLD32(val, 0, 5)
0058 #define STM32F4_RCC_PLLCFGR_PLLM_GET(reg) BSP_FLD32GET(reg, 0, 5)
0059 #define STM32F4_RCC_PLLCFGR_PLLM_SET(reg, val) BSP_FLD32SET(reg, val, 0, 5)
0060
0061 uint32_t cfgr;
0062 #define STM32F4_RCC_CFGR_MCO2(val) BSP_FLD32(val, 30, 31)
0063 #define STM32F4_RCC_CFGR_MCO2_GET(reg) BSP_FLD32GET(reg, 30, 31)
0064 #define STM32F4_RCC_CFGR_MCO2_SET(reg, val) BSP_FLD32SET(reg, val, 30, 31)
0065 #define STM32F4_RCC_CFGR_MCO2_SYSCLK STM32F4_RCC_CFGR_MCO2(0)
0066 #define STM32F4_RCC_CFGR_MCO2_PLLI2S STM32F4_RCC_CFGR_MCO2(1)
0067 #define STM32F4_RCC_CFGR_MCO2_HSE STM32F4_RCC_CFGR_MCO2(2)
0068 #define STM32F4_RCC_CFGR_MCO2_PLL STM32F4_RCC_CFGR_MCO2(3)
0069 #define STM32F4_RCC_CFGR_MCO2_PRE(val) BSP_FLD32(val, 27, 29)
0070 #define STM32F4_RCC_CFGR_MCO2_PRE_GET(reg) BSP_FLD32GET(reg, 27, 29)
0071 #define STM32F4_RCC_CFGR_MCO2_PRE_SET(reg, val) BSP_FLD32SET(reg, val, 27, 29)
0072 #define STM32F4_RCC_CFGR_MCO2_DIV1 STM32F4_RCC_CFGR_MCO2_PRE(0)
0073 #define STM32F4_RCC_CFGR_MCO2_DIV2 STM32F4_RCC_CFGR_MCO2_PRE(4)
0074 #define STM32F4_RCC_CFGR_MCO2_DIV3 STM32F4_RCC_CFGR_MCO2_PRE(5)
0075 #define STM32F4_RCC_CFGR_MCO2_DIV4 STM32F4_RCC_CFGR_MCO2_PRE(6)
0076 #define STM32F4_RCC_CFGR_MCO2_DIV5 STM32F4_RCC_CFGR_MCO2_PRE(7)
0077 #define STM32F4_RCC_CFGR_MCO1_PRE(val) BSP_FLD32(val, 24, 26)
0078 #define STM32F4_RCC_CFGR_MCO1_PRE_GET(reg) BSP_FLD32GET(reg, 24, 26)
0079 #define STM32F4_RCC_CFGR_MCO1_PRE_SET(reg, val) BSP_FLD32SET(reg, val, 24, 26)
0080 #define STM32F4_RCC_CFGR_MCO1_DIV1 STM32F4_RCC_CFGR_MCO1_PRE(0)
0081 #define STM32F4_RCC_CFGR_MCO1_DIV2 STM32F4_RCC_CFGR_MCO1_PRE(4)
0082 #define STM32F4_RCC_CFGR_MCO1_DIV3 STM32F4_RCC_CFGR_MCO1_PRE(5)
0083 #define STM32F4_RCC_CFGR_MCO1_DIV4 STM32F4_RCC_CFGR_MCO1_PRE(6)
0084 #define STM32F4_RCC_CFGR_MCO1_DIV5 STM32F4_RCC_CFGR_MCO1_PRE(7)
0085 #define STM32F4_RCC_CFGR_I2SSCR BSP_BIT32(23)
0086 #define STM32F4_RCC_CFGR_MCO1(val) BSP_FLD32(val, 21, 22)
0087 #define STM32F4_RCC_CFGR_MCO1_GET(reg) BSP_FLD32GET(reg, 21, 22)
0088 #define STM32F4_RCC_CFGR_MCO1_SET(reg, val) BSP_FLD32SET(reg, val, 21, 22)
0089 #define STM32F4_RCC_CFGR_MCO1_HSI STM32F4_RCC_CFGR_MCO1(0)
0090 #define STM32F4_RCC_CFGR_MCO1_LSE STM32F4_RCC_CFGR_MCO1(1)
0091 #define STM32F4_RCC_CFGR_MCO1_HSE STM32F4_RCC_CFGR_MCO1(2)
0092 #define STM32F4_RCC_CFGR_MCO1_PLL STM32F4_RCC_CFGR_MCO1(3)
0093 #define STM32F4_RCC_CFGR_RTCPRE(val) BSP_FLD32(val, 16, 20)
0094 #define STM32F4_RCC_CFGR_RTCPRE_GET(reg) BSP_FLD32GET(reg, 16, 20)
0095 #define STM32F4_RCC_CFGR_RTCPRE_SET(reg, val) BSP_FLD32SET(reg, val, 16, 20)
0096 #define STM32F4_RCC_CFGR_PPRE2(val) BSP_FLD32(val, 13, 15)
0097 #define STM32F4_RCC_CFGR_PPRE2_GET(reg) BSP_FLD32GET(reg, 13, 15)
0098 #define STM32F4_RCC_CFGR_PPRE2_SET(reg, val) BSP_FLD32SET(reg, val, 13, 15)
0099 #define STM32F4_RCC_CFGR_PPRE2_DIV1 STM32F4_RCC_CFGR_PPRE2(0)
0100 #define STM32F4_RCC_CFGR_PPRE2_DIV2 STM32F4_RCC_CFGR_PPRE2(4)
0101 #define STM32F4_RCC_CFGR_PPRE2_DIV4 STM32F4_RCC_CFGR_PPRE2(5)
0102 #define STM32F4_RCC_CFGR_PPRE2_DIV8 STM32F4_RCC_CFGR_PPRE2(6)
0103 #define STM32F4_RCC_CFGR_PPRE2_DIV16 STM32F4_RCC_CFGR_PPRE2(7)
0104 #define STM32F4_RCC_CFGR_PPRE1(val) BSP_FLD32(val, 10, 12)
0105 #define STM32F4_RCC_CFGR_PPRE1_GET(reg) BSP_FLD32GET(reg, 10, 12)
0106 #define STM32F4_RCC_CFGR_PPRE1_SET(reg, val) BSP_FLD32SET(reg, val, 10, 12)
0107 #define STM32F4_RCC_CFGR_PPRE1_DIV1 STM32F4_RCC_CFGR_PPRE1(0)
0108 #define STM32F4_RCC_CFGR_PPRE1_DIV2 STM32F4_RCC_CFGR_PPRE1(4)
0109 #define STM32F4_RCC_CFGR_PPRE1_DIV4 STM32F4_RCC_CFGR_PPRE1(5)
0110 #define STM32F4_RCC_CFGR_PPRE1_DIV8 STM32F4_RCC_CFGR_PPRE1(6)
0111 #define STM32F4_RCC_CFGR_PPRE1_DIV16 STM32F4_RCC_CFGR_PPRE1(7)
0112 #define STM32F4_RCC_CFGR_HPRE(val) BSP_FLD32(val, 4, 15)
0113 #define STM32F4_RCC_CFGR_HPRE_GET(reg) BSP_FLD32GET(reg, 4, 7)
0114 #define STM32F4_RCC_CFGR_HPRE_SET(reg, val) BSP_FLD32SET(reg, val, 4, 7)
0115 #define STM32F4_RCC_CFGR_HPRE_DIV1 STM32F4_RCC_CFGR_HPRE(0)
0116 #define STM32F4_RCC_CFGR_HPRE_DIV2 STM32F4_RCC_CFGR_HPRE(8)
0117 #define STM32F4_RCC_CFGR_HPRE_DIV4 STM32F4_RCC_CFGR_HPRE(9)
0118 #define STM32F4_RCC_CFGR_HPRE_DIV8 STM32F4_RCC_CFGR_HPRE(10)
0119 #define STM32F4_RCC_CFGR_HPRE_DIV16 STM32F4_RCC_CFGR_HPRE(11)
0120 #define STM32F4_RCC_CFGR_HPRE_DIV64 STM32F4_RCC_CFGR_HPRE(12)
0121 #define STM32F4_RCC_CFGR_HPRE_DIV128 STM32F4_RCC_CFGR_HPRE(13)
0122 #define STM32F4_RCC_CFGR_HPRE_DIV256 STM32F4_RCC_CFGR_HPRE(14)
0123 #define STM32F4_RCC_CFGR_HPRE_DIV512 STM32F4_RCC_CFGR_HPRE(15)
0124 #define STM32F4_RCC_CFGR_SWS(val) BSP_FLD32(val, 2, 3)
0125 #define STM32F4_RCC_CFGR_SWS_GET(reg) BSP_FLD32GET(reg, 2, 3)
0126 #define STM32F4_RCC_CFGR_SWS_SET(reg, val) BSP_FLD32SET(reg, val, 2, 3)
0127 #define STM32F4_RCC_CFGR_SWS_HSI STM32F4_RCC_CFGR_SWS(0)
0128 #define STM32F4_RCC_CFGR_SWS_HSE STM32F4_RCC_CFGR_SWS(1)
0129 #define STM32F4_RCC_CFGR_SWS_PLL STM32F4_RCC_CFGR_SWS(2)
0130 #define STM32F4_RCC_CFGR_SW(val) BSP_FLD32(val, 0, 1)
0131 #define STM32F4_RCC_CFGR_SW_GET(reg) BSP_FLD32GET(reg, 0, 1)
0132 #define STM32F4_RCC_CFGR_SW_SET(reg, val) BSP_FLD32SET(reg, val, 0, 1)
0133 #define STM32F4_RCC_CFGR_SW_HSI STM32F4_RCC_CFGR_SW(0)
0134 #define STM32F4_RCC_CFGR_SW_HSE STM32F4_RCC_CFGR_SW(1)
0135 #define STM32F4_RCC_CFGR_SW_PLL STM32F4_RCC_CFGR_SW(2)
0136
0137 uint32_t cir;
0138
0139 uint32_t ahbrstr [3];
0140
0141 uint32_t reserved_1c;
0142
0143 uint32_t apbrstr [2];
0144
0145 uint32_t reserved_28 [2];
0146
0147 uint32_t ahbenr [3];
0148
0149 uint32_t reserved_3c;
0150
0151 uint32_t apbenr [2];
0152
0153 uint32_t reserved_48 [2];
0154
0155 uint32_t ahblpenr [3];
0156
0157 uint32_t reserved_5c;
0158
0159 uint32_t apblpenr [2];
0160
0161 uint32_t reserved_68 [2];
0162
0163 uint32_t bdcr;
0164
0165 uint32_t csr;
0166
0167 uint32_t reserved_78 [2];
0168
0169 uint32_t sscgr;
0170
0171 uint32_t plli2scfgr;
0172
0173 } stm32f4_rcc;
0174
0175
0176
0177 #define RCC_CR_HSION BSP_BIT32( 0 )
0178 #define RCC_CR_HSIRDY BSP_BIT32( 1 )
0179 #define RCC_CR_HSITRIM( val ) BSP_FLD32( val, 3, 7 )
0180 #define RCC_CR_HSITRIM_MSK BSP_MSK32( 3, 7 )
0181 #define RCC_CR_HSICAL( val ) BSP_FLD32( val, 8, 15 )
0182 #define RCC_CR_HSICAL_MSK BSP_MSK32( 8, 15 )
0183 #define RCC_CR_HSEON BSP_BIT32( 16 )
0184 #define RCC_CR_HSERDY BSP_BIT32( 17 )
0185 #define RCC_CR_HSEBYP BSP_BIT32( 18 )
0186 #define RCC_CR_CSSON BSP_BIT32( 19 )
0187 #define RCC_CR_PLLON BSP_BIT32( 24 )
0188 #define RCC_CR_PLLRDY BSP_BIT32( 25 )
0189 #define RCC_CR_PLLI2SON BSP_BIT32( 26 )
0190 #define RCC_CR_PLLI2SRDY BSP_BIT32( 27 )
0191
0192 #define RCC_PLLCFGR_PLLM( val ) BSP_FLD32( val, 0, 5 )
0193 #define RCC_PLLCFGR_PLLM_MSK BSP_MSK32( 0, 5 )
0194 #define RCC_PLLCFGR_PLLN( val ) BSP_FLD32( val, 6, 14 )
0195 #define RCC_PLLCFGR_PLLN_MSK BSP_MSK32( 6, 14 )
0196
0197 #define RCC_PLLCFGR_PLLP 16
0198 #define RCC_PLLCFGR_PLLP_MSK BSP_MSK32( 16, 17 )
0199 #define RCC_PLLCFGR_PLLP_BY_2 0
0200 #define RCC_PLLCFGR_PLLP_BY_4 BSP_FLD32( 1, 16, 17 )
0201 #define RCC_PLLCFGR_PLLP_BY_6 BSP_FLD32( 2, 16, 17 )
0202 #define RCC_PLLCFGR_PLLP_BY_8 BSP_FLD32( 3, 16, 17 )
0203
0204 #define RCC_PLLCFGR_PLLSRC_HSE BSP_BIT32( 22 )
0205 #define RCC_PLLCFGR_PLLSRC_HSI 0
0206
0207 #define RCC_PLLCFGR_PLLQ( val ) BSP_FLD32( val, 24, 27 )
0208 #define RCC_PLLCFGR_PLLQ_MSK BSP_MSK32( 24, 27 )
0209
0210 #define RCC_CFGR_SW 0
0211 #define RCC_CFGR_SW_MSK BSP_MSK32( 0, 1 )
0212 #define RCC_CFGR_SW_HSI 0
0213 #define RCC_CFGR_SW_HSE 1
0214 #define RCC_CFGR_SW_PLL 2
0215
0216 #define RCC_CFGR_SWS 2
0217 #define RCC_CFGR_SWS_MSK BSP_MSK32( 2, 3 )
0218 #define RCC_CFGR_SWS_HSI 0
0219 #define RCC_CFGR_SWS_HSE BSP_FLD32( 1, 2, 3 )
0220 #define RCC_CFGR_SWS_PLL BSP_FLD32( 2, 2, 3 )
0221
0222 #define RCC_CFGR_HPRE 4
0223 #define RCC_CFGR_HPRE_BY_1 0
0224 #define RCC_CFGR_HPRE_BY_2 BSP_FLD32( 8, 4, 7 )
0225 #define RCC_CFGR_HPRE_BY_4 BSP_FLD32( 9, 4, 7 )
0226 #define RCC_CFGR_HPRE_BY_8 BSP_FLD32( 10, 4, 7 )
0227 #define RCC_CFGR_HPRE_BY_16 BSP_FLD32( 11, 4, 7 )
0228 #define RCC_CFGR_HPRE_BY_64 BSP_FLD32( 12, 4, 7 )
0229 #define RCC_CFGR_HPRE_BY_128 BSP_FLD32( 13, 4, 7 )
0230 #define RCC_CFGR_HPRE_BY_256 BSP_FLD32( 14, 4, 7 )
0231 #define RCC_CFGR_HPRE_BY_512 BSP_FLD32( 15, 4, 7 )
0232
0233 #define RCC_CFGR_PPRE1 10
0234 #define RCC_CFGR_PPRE1_BY_1 0
0235 #define RCC_CFGR_PPRE1_BY_2 BSP_FLD32( 4, 10, 12 )
0236 #define RCC_CFGR_PPRE1_BY_4 BSP_FLD32( 5, 10, 12 )
0237 #define RCC_CFGR_PPRE1_BY_8 BSP_FLD32( 6, 10, 12 )
0238 #define RCC_CFGR_PPRE1_BY_16 BSP_FLD32( 7, 10, 12 )
0239
0240 #define RCC_CFGR_PPRE2 13
0241 #define RCC_CFGR_PPRE2 BSP_MSK32( 13, 15 )
0242 #define RCC_CFGR_PPRE2_BY_1 0
0243 #define RCC_CFGR_PPRE2_BY_2 BSP_FLD32( 4, 13, 15 )
0244 #define RCC_CFGR_PPRE2_BY_4 BSP_FLD32( 5, 13, 15 )
0245 #define RCC_CFGR_PPRE2_BY_8 BSP_FLD32( 6, 13, 15 )
0246 #define RCC_CFGR_PPRE2_BY_16 BSP_FLD32( 7, 13, 15 )
0247
0248 #define RCC_CFGR_RTCPRE( val ) BSP_FLD32( val, 16, 20 )
0249 #define RCC_CFGR_RTCPRE_MSK BSP_MSK32( 16, 20 )
0250
0251 #define RCC_CFGR_MCO1 21
0252 #define RCC_CFGR_MCO1_MSK BSP_MSK32( 21, 22 )
0253 #define RCC_CFGR_MCO1_HSI 0
0254 #define RCC_CFGR_MCO1_LSE BSP_FLD32( 1, 21, 22 )
0255 #define RCC_CFGR_MCO1_HSE BSP_FLD32( 2, 21, 22 )
0256 #define RCC_CFGR_MCO1_PLL BSP_FLD32( 3, 21, 22 )
0257
0258 #define RCC_CFGR_I2SSRC BSP_BIT32( 23 )
0259
0260 #define RCC_CFGR_MCO1PRE 24
0261 #define RCC_CFGR_MCO1PRE_MSK BSP_MSK32( 24, 26 )
0262 #define RCC_CFGR_MCO1PRE_BY_1 0
0263 #define RCC_CFGR_MCO1PRE_BY_2 BSP_FLD32( 4, 24, 26 )
0264 #define RCC_CFGR_MCO1PRE_BY_3 BSP_FLD32( 5, 24, 26 )
0265 #define RCC_CFGR_MCO1PRE_BY_4 BSP_FLD32( 6, 24, 26 )
0266 #define RCC_CFGR_MCO1PRE_BY_5 BSP_FLD32( 7, 24, 26 )
0267
0268 #define RCC_CFGR_MCO2PRE 27
0269 #define RCC_CFGR_MCO2PRE_MSK BSP_MSK32( 27, 29 )
0270 #define RCC_CFGR_MCO2PRE_BY_1 0
0271 #define RCC_CFGR_MCO2PRE_BY_2 BSP_FLD32( 4, 27, 29 )
0272 #define RCC_CFGR_MCO2PRE_BY_3 BSP_FLD32( 5, 27, 29 )
0273 #define RCC_CFGR_MCO2PRE_BY_4 BSP_FLD32( 6, 27, 29 )
0274 #define RCC_CFGR_MCO2PRE_BY_5 BSP_FLD32( 7, 27, 29 )
0275
0276 #define RCC_CFGR_MCO2 30
0277 #define RCC_CFGR_MCO2_MSK BSP_MSK32( 30, 31 )
0278 #define RCC_CFGR_MCO2_SYSCLK 0
0279 #define RCC_CFGR_MCO2_PLLI2S BSP_FLD32( 1, 30, 31 )
0280 #define RCC_CFGR_MCO2_HSE BSP_FLD32( 2, 30, 31 )
0281 #define RCC_CFGR_MCO2_PLL BSP_FLD32( 3, 30, 31 )
0282
0283 #endif