对于无操作系统的软件来说,STM32上电后的第一件事,就是系统初始化。
Libaries\CMSIS_MDK\CM3\DeviceSupport\ST\STM32F10x\system_stm32f10x.c 中,官方给出了系统初始化函数 SystemInit(),我添加了一些中文注释,便于学习、模仿。
/**
* @brief Setup the microcontroller system
* Initialize the Embedded Flash Interface, the PLL and update the
* SystemCoreClock variable.
* @note This function should be used only after reset.
* @param None
* @retval None
*/
void SystemInit (void)
{
/* Reset the RCC clock configuration to the default reset state(for debug purpose) */
/* Set HSION bit */
RCC->CR |= (uint32_t)0x00000001; // 打开内部的 8MHz RC 振荡器, 使能内部高速时钟(HSI)
/* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */
#ifndef STM32F10X_CL
RCC->CFGR &= (uint32_t)0xF8FF0000;
#else
// MCO = 000: MCO 引脚设置成