微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > SystemInit()函数的结构分析

SystemInit()函数的结构分析

时间:11-23 来源:互联网 点击:
系统函数调用顺序startup_stm32f10x_cl.s→ SystemInit() → SetSysClock()→ SetSysClockTo72()

总结:开始是在keil4里看代码,很混乱,后来把他粘到Notepad编辑器,一点击就可以看出这个子函数到哪结束

[cpp]view plaincopy

  1. #ifdefined(STM32F10X_LD_VL)||(definedSTM32F10X_MD_VL)||(definedSTM32F10X_HD_VL)
  2. /*#defineSYSCLK_FREQ_HSEHSE_VALUE*/
  3. #defineSYSCLK_FREQ_24MHz24000000
  4. #else
  5. /*#defineSYSCLK_FREQ_HSEHSE_VALUE*/
  6. /*#defineSYSCLK_FREQ_24MHz24000000*/
  7. /*#defineSYSCLK_FREQ_36MHz36000000*/
  8. /*#defineSYSCLK_FREQ_48MHz48000000*/
  9. /*#defineSYSCLK_FREQ_56MHz56000000*/
  10. #defineSYSCLK_FREQ_72MHz72000000
  11. #endif

下面定义的SystemCoreClock 变量是为了方便取出几种情况下系统时钟的实际值,例SYSCLK_FREQ_24MHz 也就是24000000。

[cpp]view plaincopy

  1. #ifdefSYSCLK_FREQ_HSE
  2. uint32_tSystemCoreClock=SYSCLK_FREQ_HSE;/*!equency(CoreClock)*/
  3. #elifdefinedSYSCLK_FREQ_24MHz
  4. uint32_tSystemCoreClock=SYSCLK_FREQ_24MHz;/*!
  5. #elifdefinedSYSCLK_FREQ_36MHz
  6. uint32_tSystemCoreClock=SYSCLK_FREQ_36MHz;/*!
  7. #elifdefinedSYSCLK_FREQ_48MHz
  8. uint32_tSystemCoreClock=SYSCLK_FREQ_48MHz;/*!
  9. #elifdefinedSYSCLK_FREQ_56MHz
  10. uint32_tSystemCoreClock=SYSCLK_FREQ_56MHz;/*!
  11. #elifdefinedSYSCLK_FREQ_72MHz
  12. uint32_tSystemCoreClock=SYSCLK_FREQ_72MHz;/*!
  13. #else/*!
  14. uint32_tSystemCoreClock=HSI_VALUE;/*!
  15. #endif

[cpp]view plaincopy

  1. staticvoidSetSysClock(void)
  2. {
  3. #ifdefSYSCLK_FREQ_HSE
  4. SetSysClockToHSE();
  5. #elifdefinedSYSCLK_FREQ_24MHz
  6. SetSysClockTo24();
  7. #elifdefinedSYSCLK_FREQ_36MHz
  8. SetSysClockTo36();
  9. #elifdefinedSYSCLK_FREQ_48MHz
  10. SetSysClockTo48();
  11. #elifdefinedSYSCLK_FREQ_56MHz
  12. SetSysClockTo56();
  13. #elifdefinedSYSCLK_FREQ_72MHz
  14. SetSysClockTo72();
  15. #endif
  16. /*Ifnoneofthedefineaboveisenabled,theHSIisusedasSystemclock
  17. source(defaultafterreset)*/
  18. }


[cpp]view plaincopy

  1. #ifdefSYSCLK_FREQ_HSE
  2. /**
  3. *@briefSelectsHSEasSystemclocksourceandconfigureHCLK,PCLK2
  4. *andPCLK1prescalers.
  5. *@noteThisfunctionshouldbeusedonlyafterreset.
  6. *@paramNone
  7. *@retvalNone
  8. */
  9. staticvoidSetSysClockToHSE(void)
  10. {
  11. ......
  12. }


[cpp]view plaincopy

  1. #elifdefinedSYSCLK_FREQ_24MHz
  2. /**
  3. *@briefSetsSystemclockfrequencyto24MHzandconfigureHCLK,PCLK2
  4. *andPCLK1prescalers.
  5. *@noteThisfunctionshouldbeusedonlyafterreset.
  6. *@paramNone
  7. *@retvalNone
  8. */
  9. staticvoidSetSysClockTo24(void)
  10. {
  11. ........
  12. }


[cpp]view plaincopy

  1. #elifdefinedSYSCLK_FREQ_36MHz
  2. /**
  3. *@briefSetsSystemclockfrequencyto36MHzandconfigureHCLK,PCLK2
  4. *andPCLK1prescalers.
  5. *@noteThisfunctionshouldbeusedonlyafterreset.
  6. *@paramNone
  7. *@retvalNone
  8. */
  9. staticvoidSetSysClockTo36(void)
  10. {
  11. ......
  12. }

省略几个......

[cpp]view plaincopy

  1. #elifdefinedSYSCLK_FREQ_72MHz
  2. /**
  3. *@briefSetsSystemclockfrequencyto72MHzandconfigureHCLK,PCLK2
  4. *andPCLK1prescalers.
  5. *@noteThisfunctionshouldbeusedonlyafterreset.
  6. *@paramNone
  7. *@retvalNone
  8. */
  9. staticvoidSetSysClockTo72(void)
  10. {
  11. .......
  12. }

这样结构就很明晰了。

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top