MCPcopy Create free account
hub / github.com/DISTORTEC/distortos / configureApbClockDivider

Function configureApbClockDivider

source/chip/STM32/STM32F1/STM32F1-RCC.cpp:127–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125}
126
127int configureApbClockDivider(const bool ppre2, const uint8_t ppre)
128{
129 static const std::pair<decltype(ppre), std::array<decltype(RCC_CFGR_PPRE1_DIV1), 2>> associations[]
130 {
131 {ppreDiv1, {RCC_CFGR_PPRE1_DIV1, RCC_CFGR_PPRE2_DIV1}},
132 {ppreDiv2, {RCC_CFGR_PPRE1_DIV2, RCC_CFGR_PPRE2_DIV2}},
133 {ppreDiv4, {RCC_CFGR_PPRE1_DIV4, RCC_CFGR_PPRE2_DIV4}},
134 {ppreDiv8, {RCC_CFGR_PPRE1_DIV8, RCC_CFGR_PPRE2_DIV8}},
135 {ppreDiv16, {RCC_CFGR_PPRE1_DIV16, RCC_CFGR_PPRE2_DIV16}},
136 };
137
138 for (auto& association : associations)
139 if (association.first == ppre)
140 {
141 static const decltype(RCC_CFGR_PPRE1) masks[] {RCC_CFGR_PPRE1, RCC_CFGR_PPRE2};
142 RCC->CFGR = (RCC->CFGR & ~masks[ppre2]) | association.second[ppre2];
143 return 0;
144 }
145
146 return EINVAL;
147}
148
149int configurePrediv1(const uint8_t prediv1)
150{

Callers 1

chipLowLevelInitializerFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected