首页 STM32F2x Clock configuration tool

STM32F2x Clock configuration tool

举报
开通vip

STM32F2x Clock configuration tool April 2011 Doc ID 018603 Rev 1 1/20 AN3362 Application note Clock configuration tool for STM32F2xx microcontrollers Introduction This application note presents the clock system configuration tool for the STM32F2xx microcontroller family. The purpose of t...

STM32F2x Clock configuration tool
April 2011 Doc ID 018603 Rev 1 1/20 AN3362 Application note Clock configuration tool for STM32F2xx microcontrollers Introduction This application note presents the clock system configuration tool for the STM32F2xx microcontroller family. The purpose of this tool is to help the user configure the microcontroller clocks, taking into consideration product parameters such as power supply and Flash access mode. The configuration tool is implemented in the “STM32F2xx_Clock_Configuration_VX.Y.Z.xls” file which is supplied with the STM32F2xx Standard Peripherals Library and can be downloaded from www.st.com. This tool supports the following functionalities for the STM32F2xx: ● Configuration of the system clock, HCLK source and output frequency ● Configuration of the Flash latency (number of wait states depending on the HCLK frequency). ● Setting of the PCLK1, PCLK2, TIMCLK (timer clocks), USBCLK, and I2SCLK frequencies. ● Generation of a ready-to-use system_stm32F2xx.c file with all the above settings (STM32F2xx CMSIS Cortex-M3 Device Peripheral Access Layer System Source File). The STM32F2xx_Clock_Configuration_VX.Y.Z.xls is referred to as “clock tool” throughout this document. Before using the clock tool, it is essential to read the STM32F2xx microcontroller reference manual (RM0033). This application note is not a substitute for the reference manual. This tool supports only revision B and revision Y of the STM32F2xx. Note: For VX.Y.Z, please refer to the tool version, example V1.0.0 www.st.com Contents AN3362 2/20 Doc ID 018603 Rev 1 Contents 1 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2 Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.1 Software requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.2 Hardware requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.2.2 Clock scheme for STM32F2xx microcontrollers . . . . . . . . . . . . . . . . . . . 7 2.2.3 I2S clock generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3 Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.1 Wizard mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.1.1 Step-by-step procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.2 Expert mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 4 Known limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 5 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 6 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 AN3362 List of tables Doc ID 018603 Rev 1 3/20 List of tables Table 1. Definition of terms. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Table 2. Number of wait states according to Cortex-M3 clock frequency. . . . . . . . . . . . . . . . . . . . . . 9 Table 3. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 List of figures AN3362 4/20 Doc ID 018603 Rev 1 List of figures Figure 1. Clock scheme for Silicon revision B and revision Y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Figure 2. I2S clock generator architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Figure 3. Wizard mode user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Figure 4. HSE value out of range. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Figure 5. VDD out of range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Figure 6. HCLK error message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Figure 7. Select the clock source. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Figure 8. File generation error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Figure 9. Expert mode user interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Figure 10. System clock frequency is exceeded . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Figure 11. The PLL input frequency is exceeded . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Figure 12. The I2S frequency is out of range. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 AN3362 Glossary Doc ID 018603 Rev 1 5/20 1 Glossary Table 1. Definition of terms Term Description HCLK AHB clock PCLK1 APB1 clock PCLK2 APB2 clock TIMCLK Timer clock USB OTG FS USB on-the-go at full-speed FCPU Cortex-M3 clock Ext.Clock External clock VDD Power supply HSI High-speed internal clock HSE High-speed external clock MCLK Master clock I2S Integrated interchip sound Fs Sampling frequency I2SCLK I2S clock RNG Random number generator SDIO Secure digital input/output interface Getting started AN3362 6/20 Doc ID 018603 Rev 1 2 Getting started This section describes the requirements and procedures needed to start using the clock tool. 2.1 Software requirements To use the clock tool with Windows operating system, a recent version of Windows, such as Windows XP, Vista or Windows7 must be installed on the PC with at least 256 Mbytes of RAM. Before starting to use the clock tool, make sure that Microsoft Office is installed on your machine and then follow these steps: ● Download the latest version of the clock tool for the STM32F2xx product from www.st.com. ● Enable macros and ActiveX controls: Excel 1997-2003 version 1. Click Tools in the menu bar 2. Click Macro 3. Click Security 4. Click Low (not recommended) Note: If ActiveX controls are not enabled, a warning message is displayed asking you to enable ActiveX. In this case, you should click “OK” to enable it. Excel 2007 version 1. Click the Microsoft Office button and then click Excel options. 2. Click Trust Center, click Trust center settings, and then click Macro settings. 3. Click Enable all macros (not recommended, potentially dangerous code can run). 4. Click Trust Center, click Trust center settings, and then click ActiveX settings. 5. Click Enable all controls without restrictions and without prompting (not recommended; potentiality dangerous controls can run). 6. Click OK. Note: For more information about how to enable macros and ActiveX controls please refer to the Microsoft Office website. AN3362 Getting started Doc ID 018603 Rev 1 7/20 2.2 Hardware requirements 2.2.1 Introduction The clock tool is designed to configure the system clocks and generate the system_stm32f2xx.c file for STM32F2xx microcontrollers. The system_stm32f2xx.c file is provided as a template system clock configuration file which can be easily modified to select the corresponding system clock frequency and to configure the Flash latency. 2.2.2 Clock scheme for STM32F2xx microcontrollers This section describes the system clock scheme that is dependent on the voltage requirements (VDD ) versus the system clock frequency and Flash latency versus the system clock frequency. Three different clock sources can be used to drive the system clock (SYSCLK): 1. HSI (16 MHz) oscillator clock 2. HSE (4 MHz to 26 MHz) oscillator clock 3. Main phase-locked loop (PLL) clock with a PLL voltage-controlled oscillator (PLLVCO) input frequency which must be between1 and 2 MHz (2 MHz is recommended to limit the PLL jitter) and with division factors M, N, P, and Q. All peripheral clocks are derived from the SYSCLK except for: 1. The USB OTG FS clock (48 MHz), the RNG clock (48 MHz), and the SDIO clock (48 MHz) which come from a specific output of PLL (PLL48CLK). 2. The I2S clock. To achieve high-quality audio performance, the I2S clock can be derived either from a specific PLL (PLLI2S) or from an external clock mapped on the I2S_CKIN pin. Getting started AN3362 8/20 Doc ID 018603 Rev 1 Figure 1. Clock scheme for Silicon revision B and revision Y The number of Flash memory wait states (latency) is defined according to the frequency of the CPU (Cortex-M3) and indirectly by the supply voltage of the device (VDD) (see Table 2: Number of wait states according to Cortex-M3 clock frequency). 0,, 6#/ X. ��0 ��1 ��2 ��- ���TO�� 0(9�%THERNET ���TO����-(Z 53"����0(9 ���TO����-(Z ����� -))?2-))?3%,�IN�393#&'?0-# !(" 02%3# ������������ !0"X 02%3# ������������ IF��!0"X�PRESC����X� ���������������������ELSE�X� ,3% %4(?-))?48?#,+?-)) /4'?(3?3#, 0,,)�3#,+ &#,+�#ORTEX FREE RUNNING�CLOCK !0"X� PERIPHERAL� CLOCKS !0"X�TIMER CLOCKS ���-(Z CLOCKS 53"(3 5,0)�CLOCK %THERNET 040�CLOCK -#/� 0ERIPHERAL CLOCK�ENABLE ���TO��-#/� AI�����C %4(?-))?28? #,+?-)) /3#��?). /3#��?/54 ,3%�/3# �������K(Z ,3)�2# ���K(Z TO� INDEPENDENT� WATCHDOG ,3% ,3) TO�24#24##,+ 24#3%,;���=� )7$'#,+ (3%�/3# � ���-(Z /3#?). � /3#?/54 (3)�2# ���-(Z 0,,#,+ (3) (3) (3% 37 393#,+ ����-(Z� MAX � � (#,+ TO�!("�BUS��CORE� MEMORY�AND�$-! ����-(Z�MAX� TO�#ORTEX�3YSTEM TIMER� �� #LOCK� %NABLE � 0ERIPHERAL CLOCK�ENABLE 0,,��#+ )�3�CLOCKS 0ERIPHERAL CLOCK�ENABLE 0ERIPHERAL CLOCK�ENABLE -!#2-))#,+ -!#48#,+ -!#28#,+ TO�%THERNET�-!# 0ERIPHERAL CLOCK�ENABLE 0ERIPHERAL CLOCK�ENABLE 7ATCHDOG ENABLE 24# ENABLE 0ERIPHERAL CLOCK�ENABLE 0ERIPHERAL CLOCK�ENABLE 0ERIPHERAL CLOCK�ENABLE ���TO��� 0,,)�3 6#/ X. ��0 ��1 ��2 393#,+ %XT��CLOCK� �)�3?#+). )�332# (3%?24# (3% AN3362 Getting started Doc ID 018603 Rev 1 9/20 2.2.3 I2S clock generator This section describes the I2S clock generator that is dependent on the master clock MCLK (enable or disable), the frame wide, and the I2S peripheral clock (I2SCLK). Figure 2. I2S clock generator architecture The audio sampling frequency may be 192 kHz, 96 kHz, 48 kHz, 44.1 kHz, 32 kHz, 22.05 kHz, 16 kHz, 11.025 kHz or 8 kHz. To reach the desired frequency, the linear divider (DIV) needs to be programmed according to the formulas below: When the master clock is generated (MCKOE in the SPI_I2SPR register is set): ● Fs = I2SxCLK/[(16*2)*((2*I2SDIV)+ODD)*8)] when the channel frame is 16-bit wide ● Fs = I2SxCLK/[(32*2)*((2*I2SDIV)+ODD)*4)] when the channel frame is 32-bit wide Where ODD is an odd factor for the prescaler. When the master clock is disabled (MCKOE bit cleared): ● FS = I2SxCLK/[(16*2)*((2*I2SDIV)+ODD))] when the channel frame is 16-bit wide ● FS = I2SxCLK/[(32*2)*((2*I2SDIV)+ODD))] when the channel frame is 32-bit wide Table 2. Number of wait states according to Cortex-M3 clock frequency Wait states (WS) (LATENCY) HCLK - Cortex-M3 clock frequency (MHz) 2.7 V  VDD  3.6 V 2.4 V  VDD < 2.7 V 2.1V  VDD < 2.4V 1.8(1) V  VDD < 2.1 V 1. If IRROFF is set to VDD on STM32F20xx devices, this value can be lowered to 1.65 V when the device operates in a reduced temperature range. 0 WS (1 CPU cycle) 0 < HCLK  30 0 < HCLK  24 0 < HCLK  18 0 < HCLK  16 1 WS (2 CPU cycle) 30 < HCLK  60 24 < HCLK  48 18 < HCLK  36 16 < HCLK  32 2 WS (3 CPU cycle) 60 < HCLK  90 48 < HCLK  72 36 < HCLK  54 32 < HCLK  48 3 WS(4 CPU cycle) 90 < HCLK  120 72 < HCLK  96 54 < HCLK  72 48 < HCLK  64 4 WS(5 CPU cycle) 96 < HCLK  120 72 < HCLK  90 64 < HCLK 80 5 WS (6 CPU cycle) 90 < HCLK  108 80 < HCLK  96 6 WS (7 CPU cycle) 108 < HCLK  120 96 < HCLK  112 7 WS (8 CPU cycle) 112 < HCLK 120 8-bit divider + linear CK ODD I2SDIV[7:0] I2SxCLK CHLENI2SMOD reshaping stage Divider by 4 Div2 1 0 MCKOE MCKOE MCK 0 1 Getting started AN3362 10/20 Doc ID 018603 Rev 1 This tool performs the best configuration of the PLLI2S_N and PLLI2S_R with the minimum error on the sampling frequency and according to I2S parameters (frame wide, MCKO, and sampling frequency). Note: Only the PLLI2S_N and PLLI2S_R are configured in the “system_stm32f2xx.c” file. This tool does not configure the I2S register. The sampling frequency error is computed as an indicator according to the I2S parameters which are not configured in the output file “system_stm32f2xx.c”. AN3362 Tutorials Doc ID 018603 Rev 1 11/20 3 Tutorials This section describes step by step how to use the clock tool to configure all system clocks and generate the system_stm32f2xx.c file. Two modes are available: Wizard and Expert. The selection is made in the Configuration mode list box. 3.1 Wizard mode This mode (default mode) guides you through a series of steps to obtain the desired clock system configuration quickly and easily. Figure 3. Wizard mode user interface Note: The ‘View’ button permits viewing of the xls file in full screen to be activated or deactivated. The ‘Reset’ button permits the system clock to the default configuration to be set. 3.1.1 Step-by-step procedure 1. If the HSE is used in your application, set its frequency between: – a minimum of 4 MHz and – a maximum of 26 MHz if a crystal oscillator is used for STM32F2xx Note: The definition, HSE_VALUE, in the STM32f2xx.h file must be modified each time the user changes the HSE oscillator value. Tutorials AN3362 12/20 Doc ID 018603 Rev 1 If the frequency entered is out of range, an error message is displayed, as shown in Figure 4. A valid frequency must be entered. Figure 4. HSE value out of range 2. Enter the VDD power supply voltage range which is between 1.8 V and 3.6 V (refer to Figure 3: Wizard mode user interface). If the VDD voltage is out of range, an error message is displayed as shown in Figure 5. Figure 5. VDD out of range 3. Configure the Prefetch buffer, Instruction Cash and the Data cash (select ON or OFF from the list box). 4. Specify if the PLLI2S is needed. If it is needed, enable it and follow step 9, 10, 11 and 12. Otherwise, go to step 5. 5. Specify if a 48 MHz clock is needed for USB OTG FS, RNG or SDIO operations. If it is needed, this adds a constraint to the parameter setting in PLL configuration. If it is not needed, no USB constraint has been added. 6. Set the desired HCLK frequency. The maximum frequency of HCLK must be less than 120 MHz. If the entered value is higher than 120 MHz an error message is displayed as shown in Figure 6. AN3362 Tutorials Doc ID 018603 Rev 1 13/20 Figure 6. HCLK error message 7. Select the PCLK1 and PCLK2 prescaler settings from the list box to obtain the desired PCLK1 and PCLK2 frequencies. The TIMCLK frequencies are configured automatically depending on the PCLK1 and PCLK2 prescaler settings. 8. See step 7 9. Select the I2S clock source from the I2S source. Ignore steps 10, 11, and 12 if the external clock is selected as the clock source for the I2S peripheral. 10. If the PLLI2S is selected as the I2S clock source, select the frame wide (16 or 32 bits). 11. Specify if the master clock is enabled or disabled (Select ON/OFF from the list box). 12. Select the Fs from the list box. The Fs value can be 192 kHz, 96 kHz, 48 kHz, 44.1 kHz, 32 kHz, 22.05 kHz, 16 kHz, 11.025 kHz, and 8 kHz. 13. Click on the RUN button. A message box is then displayed requesting that the clock source is selected (see Figure 7). Choose HSE, HSI or PLL (which are sourced by the HSI or HSE). Figure 7. Select the clock source Note: Configure the Flash Latency: after running the application, the number of wait states is configured automatically with the best value (lowest possible value) which can be modified by another number higher then the selected one. 14. Finally, click on the Generate button to automatically generate the system_stm32f2xx.c file. The system_stm32f2xx.c is generated in the same location as the clock tool. Display the file to verify the value of the system clock, SystemCoreClock, and the values of HCLK, PCLK1, PCLK2, Flash access mode, and other parameters which are defined in the SetSysClock function. Tutorials AN3362 14/20 Doc ID 018603 Rev 1 The system_stm32f2xx.c file must be added to the working project to be built. If the file is not generated, an error message is displayed as shown Figure 8. Figure 8. File generation error 3.2 Expert mode This mode provides more flexibility regarding the configuration setup but, it is up to the user to ensure that configuration is correct. Figure 9. Expert mode user interface Note: The ‘View’ button permits viewing of the xls file in full screen to be activated or deactivated. The ‘Reset’ button permits the system clock to the default configuration to be set. AN3362 Tutorials Doc ID 018603 Rev 1 15/20 1. Configure the SYSCLK frequency as follows: a) If the HSE is used in your application, set its frequency between: – a minimum of 4 MHz and – a maximum of 26 MHz if a crystal oscillator is used for STM32F2xx. Note: The definition, HSE_VALUE, in the STM32f2xx.h file must be modified each time the user changes the HSE oscillator value. If the frequency entered is out of range, an error message is displayed, as shown in Figure 4. A valid frequency must be entered. b) Enter the VDD power supply voltage range which is between 1.8 V and 3.6 V (refer to Figure 9: Expert mode user interface). c) Configure the SYSCLK source (PLL, HSE or HSI). If the clock source selection is invalid (the HCLK frequency is too high) an error message is displayed as shown in Figure 10. Figure 10. System clock frequency is exceeded d) If PLL is selected as the SYSCLK source, it is necessary to select the source clock for the PLL (HSE or HSI). e) If the PLL is selected as the SYSCLK source, configure the main PLL(M) division factor to acheive a PLLVCO frequency between 1 MHz and 2 MHz. If the selected division factor is invalid, an error message is displayed as shown in Figure 11. If the I2S frequency is higher than 192 MHz an error message is displayed as shown in Figure 12. Figure 11. The PLL input frequency is exceeded Tutorials AN3362 16/20 Doc ID 018603 Rev 1 Figure 12. The I2S frequency is out of range f) Set the HCLK prescaler using the AHBPrescaler list box to obtain the desired HCLK frequency. g) Select the PCLK1 prescaler settings from the list box to obtain the desired PCLK1 frequency. The TIMCLK frequencies are configured automatically depending on the PCLK1 prescaler settings. h) Select the PCLK2 prescaler settings from the list box to obtain the desired PCLK2 frequency. The TIMCLK frequencies are configured automatically depending on the PCLK2 prescaler settings. i) Configure the Flash Latency: after setting the HCLK prescaler, the number of Flash wait states is configured automatically with the best value (lowest possible value) which can be modified by another number higher then the selected one. j) Generate the clock configuration files by clicking on the Generate button. 2. Configure the I2S clock frequency as follows: a) If the PLLI2S is needed, enable it and fellow the steps below. b) If the external clock source is selected as the I2S clock source, the following steps can be ignored. c) If the PLLI2S is selected as the clock source for the I2S peripheral, configure the PLLI2S(N) multiplication factor. d) If the PLLI2S is selected as the clock sourc
本文档为【STM32F2x Clock configuration tool】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_818609
暂无简介~
格式:pdf
大小:448KB
软件:PDF阅读器
页数:20
分类:互联网
上传时间:2012-08-30
浏览量:8