6 HAL System Driver
6.1 HAL Firmware driver API description
section ต่อไปนี้แสดงรายการ the various functions of the HAL library.
6.1.1 How to use this driver
The common HAL driver บรรจุ a set of generic and common APIs ที่สามารถถูกใช้โดย the PPP peripheral drivers และ the user เพื่อสตาร์ทการใช้ the HAL.
The HAL บรรจุ two APIs' categories:
• Common HAL APIs
• Services HAL APIs
6.1.2 Initialization and de-initialization functions
ส่วนนี้จัดให้มีฟังก์ชันที่ช่วยให้:
• กำหนดค่าเริ่มต้น the Flash interface, the NVIC allocation และกำหนดค่าเริ่มต้น clock configuration. มันกำหนดค่าเริ่มต้น the
systick ด้วยเมื่อ timeout ถูกต้องการและ the backup domain เมื่อถูกเปิดใช้งาน.
• ยกเลิกการกำหนดค่าเริ่มต้น common part of the HAL.
• กำหนดค่า The time base source ให้มี 1ms time base ด้วย a dedicated Tick interrupt priority.
– SysTick timer ถูกใช้โดยเริ่มต้นเป็น source of time base, แต่ในที่สุดผู้ใช้สามารถจัดให้มีใช้ time base source ที่เหมาะสม
ของเขา(ตัวอย่างเช่น a general purpose timer หรือ time source อื่นๆ), โดยคำนึงถึงว่า Time base duration ควรเป็น 1ms
เนื่องจาก PPP_TIMEOUT_VALUEs ถูกกำหนดและถูกจัดการใน milliseconds basis.
– Time base configuration function (HAL_InitTick ()) ถูกเรียกโดยอัตโนมัติที่ the beginning of the program หลังจาก
reset โดย HAL_Init() หรือที่เวลาใดๆเมื่อ clock ถูกกำหนดค่า, โดย HAL_RCC_ClockConfig().
– Source of time base ถูกกำหนดค่าเพื่อสร้าง interrupts ในคาบเวลาที่คงที่. ต้องใช้ความระมัดระวัง ถ้า HAL_Delay() ถูกเรียก
จาก a peripheral ISR process, the Tick interrupt line ต้องมี priority (ตัวเลขน้อยกว่า) สูงกว่า the peripheral
interrupt. มิฉะนั้น the caller ISR process จะถูกบล็อก.
– functions ที่ส่งผลต่อ time base configurations ถูกประกาศเป็น __weak เพื่อให้การแทนที่เป็นไปได้ในกรณีของการจัดให้มีใช้
งานอื่น ๆ ใน user file.
This section บรรจุ the following APIs:
• HAL_Init
• HAL_DeInit
• HAL_MspInit
• HAL_MspDeInit
• HAL_InitTick
6.1.3 HAL Control functions
ส่วนนี้จัดให้มีฟังก์ชันที่ช่วยให้:
• Provide a tick value in millisecond
• Provide a blocking delay in millisecond
• Suspend the time base source interrupt
• Resume the time base source interrupt
• Get the HAL API driver version
• Get the device identifier
• Get the device revision identifier
• Enable/Disable Debug module during SLEEP mode
• Enable/Disable Debug module during STOP mode
• Enable/Disable Debug module during STANDBY mode
ส่วนนี้บรรจุ the following APIs:
• HAL_IncTick
• HAL_GetTick
• HAL_GetTickPrio
• HAL_SetTickFreq
• HAL_GetTickFreq
• HAL_Delay
• HAL_SuspendTick
• HAL_ResumeTick
• HAL_GetHalVersion
• HAL_GetREVID
• HAL_GetDEVID
• HAL_GetUIDw0
• HAL_GetUIDw1
• HAL_GetUIDw2
• HAL_DBGMCU_EnableDBGSleepMode
• HAL_DBGMCU_DisableDBGSleepMode
• HAL_DBGMCU_EnableDBGStopMode
• HAL_DBGMCU_DisableDBGStopMode
• HAL_DBGMCU_EnableDBGStandbyMode
• HAL_DBGMCU_DisableDBGStandbyMode
6.1.4 Detailed description of functions
HAL_Init
Function name
HAL_StatusTypeDef HAL_Init (void )
Function description
This function ถูกใช้เพื่อกำหนดค่าเริ่มต้น the HAL Library; มันต้องเป็น the first instruction ที่จะถูกปฏิบัติใน the main
program (ก่อนที่จะเรียก HAL function อื่นใดๆ), มันดำเนินการต่อไปนี้: กำหนดค่า the Flash prefetch.
Return values
• HAL: status
Notes
• SysTick ถูกใช้เป็น time base สำหรับ the HAL_Delay() function, the application จำเป็นต้องแน่ใจว่า the SysTick
time base ถูกเซ็ตเป็น 1 millisecond เสมอเพื่อให้มี correct HAL operation.
HAL_DeInit
Function name
HAL_StatusTypeDef HAL_DeInit (void )
Function description
ฟังชั่นนี้ยกเลิกการกำหนดค่าเริ่มต้น common part of the HAL และหยุด the systick.
Return values
• HAL: status
Notes
• ฟังชั่นนี้เป็นทางเลือก.
(https://i.imgur.com/uldP1bo.png)
(https://i.imgur.com/Vwzy3ok.png)
HAL_InitTick
Function name
HAL_StatusTypeDef HAL_InitTick (uint32_t TickPriority)
Function description
ฟังชั่นนี้กำหนดค่าแหล่งของ the time base.
Parameters
• TickPriority: Tick interrupt priority.
Return values
• HAL: status
Notes
• function นี้ถูกเรียกโดยอัตโนมัติที่ the beginning of the program หลังจาก reset โดย HAL_Init() หรือที่เวลาใดๆเมื่อ
clock ถูกกำหนดค่าใหม่โดย HAL_RCC_ClockConfig().
• ในการจัดให้มีใช้โดยเริ่มต้น, SysTick timer เป็น the source of time base มันถูกใช้เพื่อสร้าง interrupts ในคาบเวลาที่
คงที่. ต้องใช้ความระมัดระวัง ถ้า HAL_Delay() ถูกเรียกจาก a peripheral ISR process, the SysTick interrupt ต้องมี
priority (ตัวเลขน้อยกว่า) สูงกว่า the peripheral interrupt. มิฉะนั้น the caller ISR process จะถูกบล็อก. The
function ถูกประกาศเป็น __weak ที่จะถูกเขียนทับในกรณีของการจัดให้มีใช้อื่นใน user file.
HAL_IncTick
Function name
void HAL_IncTick (void )
Function description
function นี้ถูกเรียกเพื่อเพิ่ม a global variable "uwTick" ที่ใช้เป็น application time base.
Return values
• None:
Notes
• ในการจัดให้มีใช้โดยเริ่มต้น, ตัวแปรนี้ถูกเพิ่มแต่ละ 1ms ใน SysTick ISR.
• ฟังชั่นนี้ถูกประกาศเป็น __weak ที่จะถูกเขียนทับในกรณีของการจัดให้มีใช้อื่นใน user file.
HAL_Delay
Function name
void HAL_Delay (uint32_t Delay)
Function description
function นี้จัดให้มี minimum delay (in milliseconds) ขึ้นอยู่กับ variable ที่เพิ่ม.
Parameters
• Delay: ระบุ the delay time length, in milliseconds.
Return values
• None:
Notes
• ในการจัดให้มีใช้โดยเริ่มต้น, SysTick timer เป็น the source of time base. มันถูกใช้เพื่อสร้าง interrupts ในคาบเวลาที่
คงที่ที่ๆ uwTick ถูกเพิ่ม.
• ฟังชั่นนี้ถูกประกาศเป็น __weak ที่จะถูกเขียนทับในกรณีของการจัดให้มีใช้อื่นใน user file.
(https://i.imgur.com/29MqItF.png)
(https://i.imgur.com/owtDr6O.png)
(https://i.imgur.com/4WrFGYf.png)
(https://i.imgur.com/OviB4Gh.png)
(https://i.imgur.com/w19CRH1.png)
HAL_SuspendTick
Function name
void HAL_SuspendTick (void )
Function description
Suspend Tick increment.
Return values
• None:
Notes
• ในการจัดให้มีใช้โดยเริ่มต้น, SysTick timer เป็น the source of time base. มันถูกใช้เพื่อสร้าง interrupts ในคาบเวลาที่
คงที่. ทันทีที่ HAL_SuspendTick() ถูกเรียก, the SysTick interrupt จะถูกปิดใช้งานและดังนั้น Tick increment ถูกระงับ
ไว้.
• ฟังชั่นนี้ถูกประกาศเป็น __weak ที่จะถูกเขียนทับในกรณีของการจัดให้มีใช้อื่นใน user file.
HAL_ResumeTick
Function name
void HAL_ResumeTick (void )
Function description
กลับคืนมาทำงานต่อ Tick increment.
Return values
• None:
Notes
• ในการจัดให้มีใช้โดยเริ่มต้น, SysTick timer เป็น the source of time base. มันถูกใช้เพื่อสร้าง interrupts ในคาบเวลาที่
คงที่. ทันทีที่ HAL_ResumeTick() ถูกเรียก, the SysTick interrupt จะถูกเปิดใช้งานและดังนั้น Tick increment ถูกกลับ
คืนมาทำงานต่อ.
• ฟังชั่นนี้ถูกประกาศเป็น __weak ที่จะถูกเขียนทับในกรณีของการจัดให้มีใช้อื่นใน user file.
(https://i.imgur.com/TTZhXQu.png)
(https://i.imgur.com/pRo3QDw.png)
(https://i.imgur.com/th1GhK5.png)
(https://i.imgur.com/Zq5aCvs.png)
(https://i.imgur.com/vidinpX.png)
(https://i.imgur.com/M2rvjmK.png)
(https://i.imgur.com/U65IBks.png)
(https://i.imgur.com/qJNcwbz.png)
(https://i.imgur.com/JEjVCmy.png)
(https://i.imgur.com/z50kFvj.png)
(https://i.imgur.com/D0aRj2N.png)
(https://i.imgur.com/RDx3ZwX.png)
(https://i.imgur.com/PbpTGX1.png)
(https://i.imgur.com/xKnfT3S.png)
(https://i.imgur.com/TxI2Q3p.png)
(https://i.imgur.com/o5UQlM0.png)