/ * @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. ******************************************************************************/
| 59 | * AUXHFRCO clock has been changed from default 14MHz band. |
| 60 | ******************************************************************************/ |
| 61 | void 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 |
no test coverage detected