STM32F1 RCC

Started by tha, November 07, 2020, 08:35:59 AM

Previous topic - Next topic

tha

7.2.4 LSE clock
The LSE crystal คือ a 32.768 kHz Low Speed External crystal หรือ ceramic resonator.มันมีข้อได้เปรียบการจัดให้มี a low-power แต่ highly accurate clock source ไปยัง the real-time clock peripheral (RTC) สำหรับ clock/calendar หรือ timing functions อื่นๆ.

The LSE crystal ถูก switched on และ off โดยใช้ the LSEON bit ใน Backup domain control register (RCC_BDCR).

The LSERDY flag ใน the Backup domain control register (RCC_BDCR) แสดงถ้า the LSE crystal มีความเสถียรหรือไม่. ที่ startup, the LSE crystal output clock signal จะไม่ถูกปล่อยออกมาจนกว่าบิตนี้ถูกเซ็ตโดย hardware. An interrupt สามารถถูกสร้างขึ่นถ้าเปิดการใช้งานใน the Clock interrupt register (RCC_CIR).

External source (LSE bypass)
ในโหมดนี้, an external clock source ต้องถูกจัดให้มี. มันสามารถมีความถี่ขึ้นไปถึง 1 MHz. คุณเลือกโหมดนี้โดยการเซ็ต the LSEBYP และ LSEON bits ใน the Backup domain control register (RCC_BDCR). The external clock signal (square, sinus หรือ triangle) ด้วยประมาณ ~50% duty cycle ต้องขับ  the OSC32_IN pin ในขณะที่ the OSC32_OUT pin ควรถูกปล่อยให้เป็นอิมพิแด๊นท์สูง (hi-Z). ดู Figure 9.

tha

7.2.5 LSI clock
The LSI RC ทำหน้าที่เป็น an low-power clock source ที่สามารถทำงานต่อไปใน Stop และ Standby mode สำหรับ the independent watchdog (IWDG) และ Auto-wakeup unit (AWU). The clock frequency อยู่ที่ประมาณ 40 kHz (ระหว่าง 30 kHz และ 60 kHz). สำหรับรายละเอียดที่มากขึ้น, อ้างอิงถึง the electrical characteristics section ของ the datasheets.

The LSI RC สามารถถูก switched on และ off โดยใช้ the LSION bit ใน the Control/status register (RCC_CSR).

The LSIRDY flag ใน the Control/status register (RCC_CSR) แสดงถ้า the low-speed internal oscillator มีความเสถียรหรือไม่. ที่ startup, the clock จะไม่ถูกปล่อยออกมาจนกว่าบิตนี้ถูกเซ็ตโดย hardware. An interrupt สามารถถูกสร้างขึ่นถ้าเปิดการใช้งานใน the Clock interrupt register (RCC_CIR).

Note: LSI calibration มีให้ใช้เพียงบน high-density, XL-density และ connectivity line devices เท่านั้น.

LSI calibration
The frequency dispersion ของ the Low Speed Internal RC (LSI) oscillator สามารถถูก calibrated ให้มี accurate RTC time base และ/หรือ IWDG timeout (เมื่อ LSI ถูกใช้เป็น clock source สำหรับ peripherals เหล่านี้)  ด้วยความแม่นยำที่ยอมรับได้

calibration นี้ถูกดำเนินการโดยการวัด the LSI clock frequency ตาม TIM5 input clock (TIM5CLK). สอดคล้องกับการวัดนี้ทำที่ความแม่นยำของ the HSE oscillator, the software สามารถปรับ the programmable 20-bit prescaler ของ the RTC เพื่อให้ได้ an accurate time base หรือสามารถคำนวณ accurate IWDG timeout

ใช้ขั้นตอนต่อไปนี้เพื่อปรับเทียบ LSI :
1. เปิดการใช้งาน TIM5 timer และกำหนด channel4 ใน input capture mode
2. เซ็ต the TIM5CH4_IREMAP bit ใน the AFIO_MAPR register เพื่อต่อ the LSI clock ภายในไปยัง TIM5 channel4 input
    capture สำหรับ calibration purpose.
3. วัดความถี่ของ LSI clock โดยใช้ the TIM5 Capture/compare 4 event หรือ interrupt.
4. ใช้ the measured LSI frequency เพื่ออัปเดต the 20-bit prescaler ของ the RTC ขึ้นอยู่กับ the desired time base และ/
    หรือเพื่อคำนวณ the IWDG timeout

tha

7.2.6 System clock (SYSCLK) selection
หลังจาก a system reset, the HSI oscillator ถูกเลือกเป็น system clock. เมื่อ a clock source ถูกใช้โดยตรงหรือผ่านทาง the PLL เป็น system clock, เป็นไปไม่ได้ที่จะหยุดมัน.

การสวิทช์จาก clock source หนึ่งไปยังจะเกิดขึ้นเพียงถ้า the target clock source พร้อมแล้วเท่านั้น (clock มีเสถียรหลังจาก startup delay หรือ PLL locked). หาก a clock source ซึ่งยังไม่พร้อมถูกเลือก, การสวิทช์จะเกิดขึ้นเมื่อ the clock source จะพร้อม. Status bits ใน the Clock control register (RCC_CR) แสดงว่า clock(s) พร้อมแล้วและว่า clock ถูกใช้ในขณะนี้เป็น system clock


tha

7.2.7 Clock security system (CSS)
Clock Security System สามารถถูกทำให้ทำงานโดย. ในกรณีนี้, the clock detector ถูกเปิดการใช้งานหลังจาก the HSE oscillator startup delay, และปิดการใช้งานเมื่อ oscillator นี้ถูกหยุด.

ถ้าความล้มเหลวถูกตรวจจับได้บน the HSE clock, the HSE oscillator ถูกปิดการใช้งานโดยอัตโนมัติ, a clock failure event ถูกส่งไปยัง the break input ของ the advanced-control timers (TIM1 and TIM8) และ an interrupt ถูกสร้างขึ้นเพื่อแจ้ง the software เกี่ยวกับความล้มเหลวนี้ (Clock Security System Interrupt CSSI), ยอมให้ the MCU ดำเนินการ rescue operations. The CSSI ถูกเชื่อมต่อถึง the Cortex®-M3 NMI (Non-Maskable Interrupt) exception vector.

Note: เมื่อ the CSS ถูกเปิดการใช้งานและถ้า the HSE clock ล้มเหลว, the CSS interrupt เกิดขึ้นและ an NMI ถูกสร้างขึ้นโดยอัตโนมัติ. The NMI จะถูกดำเนินการต่อไปอย่างไม่มีกำหนดเว้นแต่ the CSS interrupt pending bit ถูก cleared. เป็นผลให้, ใน the NMI ISR ผู้ใช้ต้องเคลียร์ the CSS interrupt โดยการเซ็ต the CSSC bit ใน the Clock interrupt register (RCC_CIR).

ถ้า the HSE oscillator ถูกใช้โดยตรงหรือโดยอ้อมเป็น the system clock (โดยอ้อมหมายถึง : มันถูกใช้เป็น PLL input clock, และ the PLL clock ถูกใช้เป็น system clock), a detected failure เป็นเหตุให้เกิดการสวิทช์ของ the system clock ไปยัง the HSI oscillator และปิดการใช้งานของ the HSE oscillator. ถ้า the HSE clock (หารหรือไม่หาร) เป็น the clock entry ของ the PLL ที่ใช้เป็น system clock เมื่อ the failure เกิดขึ้น, the PLL ก็ถูกปิดการใช้งานด้วย.

tha

7.2.8 RTC clock
The RTCCLK clock source สามารถเป็น the HSE/128, LSE หรือ LSI clocks อย่างใดอย่างหนึ่ง. นี้ถูกเลือกโดยการโปรแกรม the RTCSEL[1:0] bits ใน the Backup domain control register (RCC_BDCR). การเลือกนี้ไม่สามารถถูกเปลี่ยนแปลงได้โดยปราศจากการรีเซ็ต the Backup domain.

The LSE clock อยู่ใน the Backup domain, ในขณะที่ the HSE และ LSI clocks ไม่ได้อยู่. ด้วยเหตุนี้ :
•    ถ้า LSE ถูกเลือกเป็น RTC clock:
      – The RTC ยังคงทำงานต่อไปแม้ว่า the VDD supply ถูก switched off, การจัดให้มี the VBAT supply ถูกค้ำจุนไว้.
•    ถ้า LSI ถูกเลือกเป็น Auto-Wakeup unit (AWU) clock:
      – The AWU state ไม่ถูกรับประกันถ้า the VDD supply ถูก powered off. อ้างอิงถึง Section 7.2.5: LSI clock สำหรับราย
      ละเอียดที่มากขึ้นบน LSI calibration
•    ถ้า the HSE clock หารด้วย 128 ถูกใช้เป็น the RTC clock:
      – The RTC state ไม่ถูกรับประกันถ้า the VDD supply ถูก powered off หรือถ้า the internal voltage regulator ถูก
      powered off (การถอดไฟออกจาก the 1.8 V domain).
      – The DPB bit (disable backup domain write protection) ใน the Power controller register ต้องถูกเซ็ตเป็น 1 (อ้างอิง
      ถึง Section 5.4.1: Power control register (PWR_CR)).

tha

7.2.9 Watchdog clock
ถ้า the Independent watchdog (IWDG) ถูก started โดยอย่างใดอย่างหนึ่ง hardware option หรือ software access , the LSI oscillator ถูกบังคับให้ ON และไม่สามารถถูกปิดการใช้งาน. หลังจาก the LSI oscillator temporization, the clock ถูกจัดให้กับ the IWDG.

tha

7.2.10 Clock-out capability
The microcontroller clock output (MCO) capability ยอมให้ the clock ถูก output ไปบน the external MCO pin. The configuration registers ของ the corresponding GPIO port ต้องถูกโปรแกรมใน alternate function mode. หนึ่งของ 4 clock signals สามารถถูกเลือกเป็น the MCO clock.
• SYSCLK
• HSI
• HSE
• PLL clock หารด้วย 2
การเลือกนี้ถูกควบคุมโดย the MCO[2:0] bits ของ the Clock configuration register (RCC_CFGR).

tha

7.3 RCC registers
อ้างอิงถึง Section 2.2 on page 45 สำหรับรายการตัวย่อที่ใช้ใน register descriptions



Bits 31:26 Reserved, must be kept at reset value.

Bit 25 PLLRDY: PLL clock ready flag
เซ็ตโดย hardware เพื่อแสดงว่า the PLL ถูก locked.
     0: PLL unlocked
     1: PLL locked

Bit 24 PLLON: PLL enable
เซ็ตและเคลียร์โดย software เพื่อเปิดการใช้งาน PLL.
เคลียร์โดย hardware เมื่อเข้าสู่ Stop หรือ Standby mode. บิตนี้ไม่สมารถถูก reset ถ้า the PLL clock ถูกใช้เป็น system clock หรือถูกเลือกให้เป็น the system clock.
     0: PLL OFF
     1: PLL ON

Bits 23:20 Reserved, must be kept at reset value.

Bit 19 CSSON: Clock security system enable
เซ็ตและเคลียร์โดย software เพื่อเปิดการใช้งาน the clock security system. เมื่อ CSSON ถูก set, the clock detector ถูก enabled โดย hardware เมื่อ the HSE oscillator พร้อมแล้ว, และ disabled โดย hardware ถ้า a HSE clock failure ถูกตรวจจับได้.
     0: Clock detector OFF
     1: Clock detector ON (Clock detector ON ถ้า the HSE oscillator พร้อมแล้ว , OFF ถ้าไม่พร้อม).

Bit 18 HSEBYP: External high-speed clock bypass
เซ็ตและเคลียร์โดย software เพื่อข้ามผ่าน the oscillator ด้วย an external clock. The external clock ต้องถูก enabled ด้วย the HSEON bit เซ็ต, เพื่อถูกใช้โดย the device. The HSEBYP bit สามารถถูกเขียนได้เพียงถ้า the HSE oscillator ถูก disabled เท่านั้น.
     0: external 4-16 MHz oscillator not bypassed
     1: external 4-16 MHz oscillator bypassed with external clock

Bit 17 HSERDY: External high-speed clock ready flag
เซ็ตโดย hardware เพื่อแสดงว่า the HSE oscillator มีความเสถียร. บิตนี้ต้องการ 6 cycles ของ the HSE oscillator clock เพื่อตกลงหลังจาก HSEON reset.
     0: HSE oscillator not ready
     1: HSE oscillator ready

Bit 16 HSEON: HSE clock enable
เซ็ตและเคลียร์โดย software.
เคลียร์โดย hardware เพื่อหยุด the HSE oscillator เมื่อเข้าสู่ Stop หรือ Standby mode. บิตนี้ไม่สามารถถูกรีเซ็ตถ้า the HSE oscillator ถูกใช้โดยตรงหรือโดยอ้อมเป็น the system clock.
     0: HSE oscillator OFF
     1: HSE oscillator ON

Bits 15:8 HSICAL[7:0]: Internal high-speed clock calibration
บิตเหล่านี้ถูกเริ่มต้นโดยอัตโนมัติที่ startup.

Bits 7:3 HSITRIM[4:0]: Internal high-speed clock trimming
บิตเหล่านี้จัดให้มี an additional user-programmable trimming value ที่ถูกเพิ่มไปยัง the HSICAL[7:0] bits. มันสามารถถูกโปรแกรมเพื่อปรับการเปลี่ยนแปลงใน voltage และ temperature ที่มีผลต่อ the frequency ของ the internal HSI RC.
ค่าเริ่มต้นคือ 16 ซึ่งเมื่อเพิ่มเข้าไปใน the HSICAL value, ควรตัดแต่ง the HSI เป็น 8 MHz ? 1%. The trimming step (Fhsitrim) อยู่ที่ประมาณ 40 kHz ระหว่าง 2 HSICALsteps ซึ่งต่อเนื่องกันมา.

Bit 2 Reserved, must be kept at reset value.

Bit 1 HSIRDY: Internal high-speed clock ready flag
เซ็ตโดย hardware เพื่อแสดงว่า internal 8 MHz RC oscillator มีความเสถียร. หลังจาก the HSION bit ถูก cleared, HSIRDY ลงไป low หลังจาก 6 internal 8 MHz RC oscillator clock cycles.
     0: internal 8 MHz RC oscillator not ready
     1: internal 8 MHz RC oscillator ready

Bit 0 HSION: Internal high-speed clock enable
เซ็ตและเคลียร์โดย software.
เซ็ตโดย hardware เพื่อบังคับ the internal 8 MHz RC oscillator ON เมื่อออกจาก Stop หรือ Standby mode หรือในกรณีของความล้มเหลวของ the external 4-16 MHz oscillator ใช้โดยตรงหรือโดยอ้อมเป็น system clock. บิตนี้ไม่สามารถถูก reset ถ้า the internal 8 MHz RC ถูกใช้โดยตรงหรือโดยอ้อมเป็น system clock หรือถูกเลือกให้เป็น the system clock.
     0: internal 8 MHz RC oscillator OFF
     1: internal 8 MHz RC oscillator ON