1 #include "build/debug.h"
5 #define RCC_BIT_CMD(ptr, mask, state) do { if (state != DISABLE) { ptr |= mask; } else { ptr &= ~mask; } } while(0)
8 void RCC_ClockCmd(rccPeriphTag_t periphTag
, FunctionalState NewState
)
10 int tag
= periphTag
>> 5;
11 uint32_t mask
= 1 << (periphTag
& 0x1f);
15 #if defined(STM32F4) || defined(STM32F7) || defined(STM32H7)
17 RCC_BIT_CMD(RCC
->AHB1ENR
, mask
, NewState
);
21 RCC_BIT_CMD(RCC
->AHB2ENR
, mask
, NewState
);
27 RCC_BIT_CMD(RCC
->AHB3ENR
, mask
, NewState
);
31 RCC_BIT_CMD(RCC
->AHB4ENR
, mask
, NewState
);
35 RCC_BIT_CMD(RCC
->APB1LENR
, mask
, NewState
);
39 RCC_BIT_CMD(RCC
->APB1HENR
, mask
, NewState
);
43 RCC_BIT_CMD(RCC
->APB3ENR
, mask
, NewState
);
47 RCC_BIT_CMD(RCC
->APB4ENR
, mask
, NewState
);
53 RCC_BIT_CMD(CRM
->ahben1
, mask
, NewState
);
57 RCC_BIT_CMD(CRM
->ahben2
, mask
, NewState
);
61 RCC_BIT_CMD(CRM
->apb1en
, mask
, NewState
);
65 RCC_BIT_CMD(CRM
->apb2en
, mask
, NewState
);
68 #if !(defined(STM32H7) || defined(STM32G4))
70 RCC_BIT_CMD(RCC
->APB1ENR
, mask
, NewState
);
75 RCC_BIT_CMD(RCC
->APB2ENR
, mask
, NewState
);
82 void RCC_ResetCmd(rccPeriphTag_t periphTag
, FunctionalState NewState
)
84 int tag
= periphTag
>> 5;
85 uint32_t mask
= 1 << (periphTag
& 0x1f);
90 #if defined(STM32F4) || defined(STM32F7) || defined(STM32H7)
92 RCC_BIT_CMD(RCC
->AHB1RSTR
, mask
, NewState
);
96 RCC_BIT_CMD(RCC
->AHB2RSTR
, mask
, NewState
);
102 RCC_BIT_CMD(RCC
->AHB3RSTR
, mask
, NewState
);
106 RCC_BIT_CMD(RCC
->AHB4RSTR
, mask
, NewState
);
110 RCC_BIT_CMD(RCC
->APB1LRSTR
, mask
, NewState
);
114 RCC_BIT_CMD(RCC
->APB1HRSTR
, mask
, NewState
);
118 RCC_BIT_CMD(RCC
->APB3RSTR
, mask
, NewState
);
122 RCC_BIT_CMD(RCC
->APB4RSTR
, mask
, NewState
);
126 #if defined(AT32F43x)
128 RCC_BIT_CMD(CRM
->ahbrst1
, mask
, NewState
);
131 RCC_BIT_CMD(CRM
->ahbrst2
, mask
, NewState
);
134 RCC_BIT_CMD(CRM
->apb1rst
, mask
, NewState
);
137 RCC_BIT_CMD(CRM
->apb2rst
, mask
, NewState
);
141 #if !(defined(STM32H7) || defined(STM32G4))
143 RCC_BIT_CMD(RCC
->APB1RSTR
, mask
, NewState
);
149 RCC_BIT_CMD(RCC
->APB2RSTR
, mask
, NewState
);