3.11 HAL system peripheral handling
บทนี้ให้ภาพรวมของวิธีที่ the system peripherals ถูกจัดการโดย the HAL drivers. The full API list ถูกจัดให้มีภายในแต่ละ peripheral driver description section.
3.11.1 Clock
Two main functions สามารถถูกใช้เพื่อกำหนดค่า the system clock:
• HAL_RCC_OscConfig (RCC_OscInitTypeDef *RCC_OscInitStruct). ฟังชั่นนี้กำหนดค่า/เปิดใช้งานหลาย clock sources
(HSE, HSI, LSE, LSI, PLL).
• HAL_RCC_ClockConfig (RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency). ฟังชั่นนี้
– เลือก the system clock source
– กำหนดค่า AHB, APB1 and APB2 clock dividers
– กำหนดค่า the number of Flash memory wait states
– อัฟเดต the SysTick configuration เมื่อ HCLK clock เปลี่ยน.
บาง peripheral clocks ไม่ได้มาจาก the system clock (อย่างเช่น RTC, USB). ในกรณีนี้, the clock configuration ถูกกระทำโดย an extended API ที่กำหนดใน stm32f1xx_hal_rcc_ex.c: HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit).
Additional RCC HAL driver functions มีให้ใช้ประโยชน์:
• HAL_RCC_DeInit() Clock de-initialization function ที่คืนกลับ clock configuration ไปเป็น reset state
• ได้รับ clock functions ที่ยอมให้ดึง various clock configurations (system clock, HCLK, PCLK1, PCLK2, …)
• MCO and CSS configuration functions
A set of macros ถูกกำหนดใน stm32f1xx_hal_rcc.h and stm32f1xx_hal_rcc_ex.h. พวกมันอนุญาตให้ปฏิบัติการทำงานเบื้องต้นใน RCC block registers, อย่างเช่น peripherals clock gating/reset control:
• __HAL_PPP_CLK_ENABLE/__HAL_PPP_CLK_DISABLE to enable/disable the peripheral clock
• __HAL_PPP_FORCE_RESET/__HAL_PPP_RELEASE_RESET to force/release peripheral reset
• __HAL_PPP_CLK_SLEEP_ENABLE/__HAL_PPP_CLK_SLEEP_DISABLE to enable/disable the peripheral clock ใน
ระหว่าง Sleep mode.