STM32G0 HAL库底层说明

2星(超过40%的资源)
所需积分/C币:40 2019-03-07 11:01:53 8.37MB PDF
241
收藏 收藏
举报

STM32G0的HAL库函数底层驱动说明,有助于使用cube开发G0
UM2319 Acronyms and definitions 2 Acronyms and definitions Table 1. Acronyms and definitions Acronym Definition ADC Analog-to-digital converter AES Advanced encryption standard ANSI American national standards institute API Application programming interface BSP Board support package CAN ontroller area network CMSIS Cortex microcontroller software interface standard COMP Comparator CPU Central processing unit CRC CRC calculation unit CSS Clock security system Digital to analog converter DESDM Digital filter sigma delta modulator DMA Direct memory access EXTI External interrupt/event controller FLASH Flash memory FMC Flexible memory controller FW Firewall GPIO General purpose 1/Os HAL Hardware abstraction layer HCD USB host controller driver Inter-integrated circuit 12S Inter-integrated sound DA Infrared data association IWDG Independent watchdog LCD Liquid crystal display control LPTIM LoW-power timer LPUART LOW-power universal asynchronous receiver/transmitter MCO Microcontroller clock output MPU Memory protection unit MSP MCU specific package NAND NAND Flash memory NOR NOR Flash memory NVIC Nested vectored interrupt controller OPAMP Operational amplifier OTG-FS USB on-the-go full-speed PCD USB peripheral controller driver UM2319-Rey page3/1912 UM2319 Acronyms and definitions Acronym Definition PWR Po ontroller QSP QuadsPI Flash memory RCC Reset and clock controller RNG Random number generator RTC Real-time clock SAL Serial audio interface SD digital SDN SD/SDIO/MultiMedia card card host interface SRAM SRAM external memory SMARTCARD Smartcard Ic SPI Serial peripheral interface SWPMI Serial wire protocol master interface Sys Tick System tick timer TIM Advanced-control, general-purpose or basic tir TSC Touch sensing controller UART Universal asynchronous receiver/transmitter USART Universal synchronous receiver/transmitter WWDG indow watchdog USB Universal serial bus PPP STM32 peripheral or block UM2319-Rey page4/1912 UM2319 Overview of hal drivers Overview of hal drivers The HaL drivers are designed to offer a rich set of APls and to interact easily with the application upper layers Each driver consists of a set of functions covering the most common peripheral features. The development of each driver is driven by a common API which standardizes the driver structure, the functions and the parameter names The HAL drivers include a set of driver modules, each module being linked to a standalone peripheral. However in some cases, the module is linked to a peripheral functional mode. As an example, several modules exist for the USART peripheral: UART driver module, USART driver module, SMARTCARD driver module and IRDa driver module The HAL main features are the following ross-family portable set of APls covering the common peripheral features as well as extension APIs in ase of specific peripheral features Three API programming models: polling, interrupt and DMA APIs are Rtos complia Fully reentrant APIs Systematic usage of timeouts in polling mode Support of peripheral multi-instance allowing concurrent API calls for multiple instances of a given peripheral (USART1, USART2. All HAL APIs implement user-callback functions mechanism Peripheral Init/DeInit HAL APIs can call user-callback functions to perform peripheral system level Initialization/De-Initialization (clock, GPIOs, interrupt, DMA Peripherals interrupt events Error events Object locking mechanism: safe hardware access to prevent multiple spurious accesses to shared resources Timeout used for all blocking processes: the timeout can be a simple counter or a timebase 3.1 HAL and user-application files 3.1.1 HAL driver files A HAL drivers are composed of the following set of files Table 2. HaL driver files File Description Main peripheral/module driver file stm32g0xx_hal_ppp.c It includes the APls that are common to all STM32 devices Example: stm32gOxx ha/ adc. c, stm32gOxx ha/ irda.c Header file of the main driver c file stm32gOxX hal ppp. h It includes common data handle and enumeration structures define statements and macros, as well as the exported generic APIs Example: stm 32goxx hal adc. h, stm 32gOxx hal irda. h Extension file of a peripheral /module driver. It includes the specific aPIs for a given part number or family, as well as the newly defined aP ls that overwrite the default generic APls if stm32goxx hal ppp exc the internal process is implemented in different way Example: stm 32gOxx hal adc exc, stm 32gOxx hal flash ex c, UM2319-Rey page5/1912 UM2319 HAL and user-application files File Description Header file of the extension c file stm32goXX hal ppp exh It includes the specific data and enumeration structures, define statements and macros, as well as the exported device part number specific APIs Example: stm32goxX ha/ adc ex h, stm 32goxX hal flash ex h stm 32goxX halc This file is used for HAL initialization and contains DBGMCU, Remap and Time Delay based on Sys Tick APIs stm 32gOxx hal h stm 32g0xx hal c header file Template file to be copied to the user application folder stm32goxx hal msp template. c It contains the MSP initialization and de-initialization(main routine and callbacks)of the peripheral used in the user application stm32gOxx_hal_conf_template. h Template file allowing to customize the drivers for a given application stm 32gOxX hal def. h Common haL resources such as common define statements. enumerations structures and macros 3.1.2 User-application files The minimum files required to build an application using the HAL are listed in the table below: Table 3. User-application files File Description This file contains SystemInito which is called at startup just after reset and before branching to the main program. It does not configure the system clock at startup(contrary to the standard library system_ stm32gOxx c This is to be done using the HAL APls in the user files It allows relocating the vector table in internal SRAM Toolchain specific file that contains reset handler and exception vectors startup stm32gOXX For some toolchains, it allows adapting the stack/heap size to fit the application requirements stm32gOxx_ flash icf Linker file for EWARM toolchain allowing mainly adapting the stack/heap size to fit the application (optional) requirements stm 32gOxX halmspc This file contains the MSP initialization and de-initialization(main routine and callbacks )of the peripheral used in the user application This file allows the user to customize the HaL drivers for a specific application stm32gOxx_hal_conf, h It is not mandatory to modify this configuration. The application can use the default configuration without any modification This file contains the exceptions handler and peripherals interrupt service routine and calls HAL Inc Tick() at regular time intervals to increment a local variable( declared in stm 32gOxx hal c) stm32gOxX it c/h sed as HAL timebase. By default, this function is called each 1 ms in Systick ISR The PPP IRQHandlero routine must call HAL PPP IRQHandlero if an interrupt based process is used within the application This file contains the main program routine, mainly the call to HAL_Inito main, ch assert failed( implementation system clock configuration peripheral HAL initialization and user application code The STM32 Cube package comes with ready-to-use project templates, one for each supported board. Each project contains the files listed above and a preconfigured project for the supported toolchains Each project template provides empty main loop function and can be used as a starting point to get familiar with project settings for STM32Cube Its features are the fallowing UM2319-Rey page6/1912 UM2319 HAL data structures It contains the sources of HAL, CMSis and bsP drivers which are the minimal components to develop a code on a given board It contains the include paths for all the firmware components It defines the STM32 device supported, and allows configuring the CMSIS and HaL drivers accordingly It provides ready to use user files preconfigured as defined below HAL is initialized Sys Tick ISR implemented for HAL GetTicko System clock configured with the selected device frequency ore If an existing project is copied to another location, then include paths must be updated Figure 1. Example of project template 日STM32G081B- EVAL 亩 Templates LL tEMplates +(C SW4STM32 白Sr system_stm32gUxKc stm32qUx_itc ④stm32g0 hal_msp.c mah.c 中 MDK-ARM EInc stm32q uxo It h ④stm32 gox_hal_conf,h main. h + EWARM Templates.ioc readme tt exsecting □Eamp|es 白 Demonstration 中白 Applications 3.2 HAL data structures Each HAL driver can contain the following data structures Peripheral handle structures Initialization and configuration structures Specific process structures 3.2,.1 Peripheral handle structures The aPls have a modular generic multi-instance architecture that allows working with several IP instances simultaneously PPP Handle Type Def * handle is the main structure that is implemented in the HAL drivers. It handles the peripheral/module configuration and registers and embeds all the structures and variables needed to follow the peripheral device flo The peripheral handle is used for the following purposes Multi instance support: each peripheral/module instance has its own handle. As a result instance resources are independent Peripheral process intercommunication: the handle is used to manage shared data resources between the process routines UM2319-Rey page7/1912 UM2319 HAL data structures EXample: global pointers, DMA handles, state machine Storage: this handle is used also to manage global variables within a given HAL driver An example of peripheral structure is shown below typedef struct USART TypeDef *Instance; / USART registers base address * USART InitTypeCef Init; /* Usart communication parameters * uint8 t *pTxBuffPtri/* Pointer to Usart. Tx transfer Buffer uint16 t Txxfersize / Usart Tx Transfer size * IO uint16 t TxXferCounti/* Usart Tx Transfer Counter x int8 t *pRxBuffptr;/* Pointer to Usart Rx transfer Buffer * intlo t Rxxfersize / Usart Rx Transfer size IO uintl6 t RxXferCounti /x Usart Rx Trans=er Counter */ DMA HandleTypeCef *hdmax; / Usart Tx DMA Handle parameters * DMA HandleTypeef *hdmarx: / Usart Rx DMA Handle parameters */ HAL LockTvpeDef Lock; / Locking object */ IO IIAL USART State TypeDef State; , Usart communication state IO HAL USART ErrorTypeDef Errorcode;/* USART Error code */ USART HandleType-ef 1. The multi-instance feature implies that all the APls used in the application are reentrant and avoid using global variables because subroutines can fail to be reentrant if they rely on a global variable to remain unchanged but that variable is modified when the subroutine is recursively invoked. For this reason, the following rules are respected Reentrant code does not hold any static (or global) non-constant data: reentrant functions can work with global data. For example, a reentrant interrupt service routine can grab a piece of hardware status to work with(e.g. serial port read buffer) which is not only global, but volatile. Still, typical use of static variables and global data is not advised, in the sense that only atomic read-modify-write instructions should be used in these variables. It should not be possible for an interrupt or signal to occur during the execution of such an instruction Reentrant code does not modify its own code 2. When a peripheral can manage several processes simultaneously using the DMA (full duplex case), the DMA interface handle for each process is added in the ppp handle typeDef 3. For the shared and system peripherals, no handle or instance object is used. The peripherals concerned by this exception are the following GPIO SYST/CK NVIC PWR RCC FLASI 3.2.2 Initialization and configuration structure These structures are defined in the generic driver header file when it is common to all part numbers. When they can change from one part number to another the structures are defined in the extension header file for each par number typedef struct uint32 t BaudRate; /*! This member configures the UART communication baudrate. * uint32 t WordLength; /*!< Specifies the nunber of data bits transmitted or received in a frarn uint32 t StopBits; /*! Specifies the number of stop bits transmitted. k/ uint32 t Parity; cities th uint32 t Mode; /*! Specifies wether the Receive or Transmit mode is enabled or disabled.*/ uint32 t IIwFlowCtli 7*!< Specifies wether the hardware flow control mode is enabled or disabl uint32 t Oversampling;/*!< Specifies wether the Over sampling 8 -s enabled or d=sabled, UM2319-Rey page8/1912 UM2319 HAL data structures to achieve higher speed (up to fPCLK/8).*/ J UART InitType efi Note The config structure is used to initialize the sub-modules or sub-instances. See below example HAL ADC ConfigCharnel (ADC HandleT'ypeDei* hadc, ADC ChannelConfT'ypeDef* sConfig) 3.2.3 Specific process structures The specific process structures are used for specific process(common APIs). They are defined in the generic driver header file Example HAL PEP Frocess (FPP HandleType Def* hadc, PPP ProcessConfig* sConf:g) UM2319-Rey page9/1912 UM2319 APi classification 3.3 API classification The HAL aPis are classified into three categories Generic APIs: common generic APIs applying to all sTM32 devices. These APIs are consequently present in the generic HAL driver files of all STM32 microcontrollers HAL StatusTypeDef HAL ADC In-t(ADC HancleType Def* had=); HAL StatusType-ef HAL ADC DeIni t(ADC Handle TypeDef *hadc)i HAL StatusTypeDef HAL ADC Start(ADC HandleType ef* hadc); HA L StatusType Def HAL ADC Stop(ADC HandleTypeDef* hacc); HAL Status Type Def HAL ADc Start I T(ADC Handle TypeDefx hadc): HAL StatusTypeDef HAL ADC Stop IT(ADC HandleTyreDef* hadc) void HAL ADC IRQHandler (ADC HendleypeDef* hadc )i EXtension APIs: this set of API is divided into two sub-categories Family specific APIs: APIs applying to a given family. They are located in the extension HAL driver file (see example below related to the ADC) IIAL Status TypeDe f IIAL ADCEx Calibration Start(ADC llandlerype Def* hadc, uint 32 t Sing leDi f ); uint32 t HAT ADCEx Calibration Getvalue(AD Hand leT Def* hadc, uint32 t S ingleDif=)i Feature/Device specific APIs: these APIs are implemented in the extension file and delimited by specific define statements relative to CMsiS bits or features and depending on device part number. +i= defined(PWR SHDW SUPPCRT void HAL PnREx EntersHUTDCWNMode(void); 卡endi Note The data structure related to the specific AP/s is delimited by the device part number define statement. It is located in the corresponding extension header c file The following table summarizes the location of the different categories of HAL APIs in the driver files Table 4. APl classification Generic file Extension file Common apls Family specific APIs XXx Device specific APIs Note Family specific AP/s are only related to a given family. This means that if a specific AP/ is implemented another family, and the arguments of this latter family are different, additional structures and arguments might need to be added Note The /rQ handlers are used for common and family specific processes UM2319-Rey page10/1912

...展开详情
试读 127P STM32G0 HAL库底层说明
立即下载 低至0.43元/次 身份认证VIP会员低至7折
一个资源只可评论一次,评论内容不能少于5个字
简途 我以为是STM32G0 HAL库,结果是一个PDF的说明文档
2021-04-13
回复
您会向同学/朋友/同事推荐我们的CSDN下载吗?
谢谢参与!您的真实评价是我们改进的动力~
上传资源赚钱or赚积分
最新推荐
STM32G0 HAL库底层说明 40积分/C币 立即下载
1/127
STM32G0 HAL库底层说明第1页
STM32G0 HAL库底层说明第2页
STM32G0 HAL库底层说明第3页
STM32G0 HAL库底层说明第4页
STM32G0 HAL库底层说明第5页
STM32G0 HAL库底层说明第6页
STM32G0 HAL库底层说明第7页
STM32G0 HAL库底层说明第8页
STM32G0 HAL库底层说明第9页
STM32G0 HAL库底层说明第10页
STM32G0 HAL库底层说明第11页
STM32G0 HAL库底层说明第12页
STM32G0 HAL库底层说明第13页
STM32G0 HAL库底层说明第14页
STM32G0 HAL库底层说明第15页
STM32G0 HAL库底层说明第16页
STM32G0 HAL库底层说明第17页
STM32G0 HAL库底层说明第18页
STM32G0 HAL库底层说明第19页
STM32G0 HAL库底层说明第20页

试读结束, 可继续阅读

40积分/C币 立即下载