MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / MSC_Init

Function MSC_Init

bsp/efm32/Libraries/emlib/src/em_msc.c:61–102  ·  view source on GitHub ↗

/ * @brief * Enables the flash controller for writing. * @note * IMPORTANT: This function must be called before flash operations when * AUXHFRCO clock has been changed from default 14MHz band. ******************************************************************************/

Source from the content-addressed store, hash-verified

59 * AUXHFRCO clock has been changed from default 14MHz band.
60 ******************************************************************************/
61void MSC_Init(void)
62{
63#if defined (_EFM32_TINY_FAMILY) || defined(_EFM32_GIANT_FAMILY)
64 uint32_t freq, cycles;
65#endif
66 /* Enable writing to the MSC */
67 MSC->WRITECTRL |= MSC_WRITECTRL_WREN;
68 /* Unlock the MSC */
69 MSC->LOCK = MSC_UNLOCK_CODE;
70 /* Disable writing to the MSC */
71 MSC->WRITECTRL &= ~MSC_WRITECTRL_WREN;
72
73#if defined (_EFM32_TINY_FAMILY) || defined(_EFM32_GIANT_FAMILY)
74 /* Configure MSC->TIMEBASE according to selected frequency */
75 freq = CMU_ClockFreqGet(cmuClock_AUX);
76
77 if( freq > 7000000)
78 {
79 /* Calculate number of clock cycles for 1us as base period */
80 freq = (freq * 11) / 10;
81 cycles = (freq / 1000000) + 1;
82
83 /* Configure clock cycles for flash timing */
84 MSC->TIMEBASE = (MSC->TIMEBASE & ~(_MSC_TIMEBASE_BASE_MASK|
85 _MSC_TIMEBASE_PERIOD_MASK))|
86 MSC_TIMEBASE_PERIOD_1US|
87 (cycles << _MSC_TIMEBASE_BASE_SHIFT);
88 }
89 else
90 {
91 /* Calculate number of clock cycles for 5us as base period */
92 freq = (freq * 5 * 11) / 10;
93 cycles = (freq / 1000000) + 1;
94
95 /* Configure clock cycles for flash timing */
96 MSC->TIMEBASE = (MSC->TIMEBASE & ~(_MSC_TIMEBASE_BASE_MASK|
97 _MSC_TIMEBASE_PERIOD_MASK))|
98 MSC_TIMEBASE_PERIOD_5US|
99 (cycles << _MSC_TIMEBASE_BASE_SHIFT);
100 }
101#endif
102}
103
104/***************************************************************************//**
105 * @brief

Callers 2

TRACE_ProfilerEnableFunction · 0.85
TRACE_ProfilerEnableFunction · 0.85

Calls 1

CMU_ClockFreqGetFunction · 0.85

Tested by

no test coverage detected