匿名
未登录
登录
百问网嵌入式Linux wiki
搜索
查看“GPIO internal peripheral”的源代码
来自百问网嵌入式Linux wiki
名字空间
页面
讨论
更多
更多
页面选项
Read
查看源代码
历史
←
GPIO internal peripheral
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
==Article purpose== The purpose of this article is to * briefly introduce the GPIO peripheral and its main features * indicate the level of security supported by this hardware block * explain how each instance can be allocated to the three runtime contexts and linked to the corresponding software components * explain how to configure the GPIO peripheral. ==Peripheral overview== The '''GPIO''' peripheral is used to configure the device IO ports, also called pins or pads. <br /> Each GPIO instance controls 8 pins (for GPIOK and GPIOZ) or 16 pins (for GPIOA to GPIOJ).<br /><br /> Every IO port implements the logic shown in the image below, taken from [[STM32MP15 resources#Reference manuals|STM32MP15 reference manuals]]: * The '''IO pin''' (on the right) is the physical connection to a chip external ball, soldered on the PCB. The link between each GPIO pin and each ball of the package is given in the [[STM32MP15 resources#DS12505|datasheet]]. * The '''Read''' and '''Write''' accesses allow the processor (Arm<sup>®</sup> Cortex<sup>®</sup>-A7 or Arm<sup>®</sup> Cortex<sup>®</sup>-M4) to configure the peripheral, control the IO pin and get its status. * '''Alternate function''' (AF) links allow to connect the IO port to an internal peripheral digital line. In such a case, the IO direction is given by the line purpose: for instance, [[USART internal peripheral|UART]] transmit line (TX) is an output. * '''Analog''' links allow to connect the IO port to an internal peripheral analog line. In such a case, the IO direction is given by the line purpose: for instance, [[ADC internal peripheral|ADC]] input line is an input.<br /><br /> [[File:IO_port.png|link=]] :Note: :* the pull-up and pull-down resistors are disabled (by hardware) in analog mode. :* at reset, all pins are set in analog input mode to protect the device and minimize the power consumption. All unused pins should be kept in this state. <br /> The pin configuration done by the software consists in: * setting the '''pin mode''' in the GPIOx_MODER register: ** '''input''' or '''output''' if the pin is used as general purpose (GPIO), controlled by software. ** '''analog'''. ** '''alternate function''' (AF). * selecting the '''alternate function''' in the GPIOx_AFRH/L register (only when the pin mode is AF): ** each IO port can support up to 16 alternate functions that are documented in the [[STM32MP15 resources#DS12505|datasheet]]. * setting the '''pin characteristics''': ** '''no pull-up and no pull-down''' or '''pull-up''' or '''pull-down''' in the GPIOx_PUPDR register, needs to be selected to be coherent with the hardware schematics. ** '''push-pull''' or '''open-drain''' in the GPIOx_OTYPER register, needs to be selected to be coherent with the hardware schematics. ** '''output speed''' in the GPIOx_OSPEEDR register needs to be tuned to achieve the expected level of performance (rising and falling times) while limiting electromagnetic interferences (EMI) and overconsumption. As example, the table below summarizes the maximum achievable frequency for each supported IO voltage and a 30pF load: :{| class="st-table" width="60%" |- ! width="20%" | GPIOx_OSPEEDR !! width="20%" | Meaning !! width="20%" | VDD=3v3 !! width="20%" | VDD=1v8<br />HSLV OFF !! width="20%" | VDD=1v8<br />HSLV ON |- | align="center" | b00 || Low speed || 24 MHz || 11 MHz || 22 MHz |- | align="center" | b01 || Medium speed || 83 MHz || 28 MHz || 79 MHz |- | align="center" | b10 || High speed || 125 MHz || 66 MHz || 101 MHz |- | align="center" | b11 || Very high speed || 150 MHz || 70 MHz || 111 MHz |} :Note: :* More information is available in the '''IO speed settings''' chapter of the AN5031<ref>[[STM32MP15 resources#Application notes|AN5031]]</ref>. :* There are different '''IO types''' with different characteristics: for instance, all pads are not able to achieve 150 MHz while supplied at 3v3. Refer to the [[STM32MP15 resources#DS12505|datasheet]] to get the characteristics for each pin. :* When supplied with VDD=1v8, it is possible to enable the '''high speed low voltage''' (HSLV) pad mode for FTH (Five volt Tolerant High speed) and FTE (Five volt Tolerant Extended high speed) IO types on some peripherals ([[SPI internal peripheral|SPI]], [[SDMMC internal peripheral|SDMMC]], [[ETH internal peripheral|ETH]], [[QUADSPI internal peripheral|Dual QUADSPI]] and [[:category:Trace and debug peripherals|TRACE]]) via SYSCFG_IOCTRLR register in [[SYSCFG internal peripheral|SYSCFG]]. '''Warning''': As it could be destructive if used when VDD>2.7V, the HSLVEN_xx bits set in SYSCFG_IOCTRLR register are not taken account unless the OTP bit PRODUCT_BELOW_2V5 is set. <br /><br /> The table below shows all possible characteristics combinations for each '''pin mode''': :{| class="st-table" width="60%" valign="top" |- ! width="25%" | pin mode ! width="25%" | GPIOx_PUPDR ! width="25%" | GPIOx_OTYPER ! width="25%" | GPIOx_OSPEEDR |- | '''analog'''<br /> | Not applicable | Not applicable | Not applicable |- | '''input''' (GPIO or AF)<br /> | rowspan="2" | '''no pull-up and no pull-down''' <br />or '''pull-down''' <br />or '''pull-up''' | Not applicable | Not applicable |- | '''output''' (GPIO or AF) <br /> or '''bi-directional''' (AF) | '''push-pull''' <br />or '''open-drain''' | cf. the table above |- |} :Note: :* 'Not applicable' means that setting this register has no effect but, in any case, there is no risk for the device. :* On the other hand, leaving a register not initialized whereas it should be, may lead to an unpredictable behavior! <br /> ===Features=== Refer to [[STM32MP15 resources#Reference manuals|STM32MP15 reference manuals]] for the complete features list, and to the software components, introduced below, to know which features are really implemented.<br> ===Security support=== The GPIOA to GPIOK peripherals are '''non-secure'''.<br /> The GPIOZ peripheral is '''secure aware'''. ==Peripheral usage and associated software== ===Boot time=== The [[STM32CubeMX]] tool allows to configure in one place the GPIO configuration that is applied at boot time and used at runtime, so it is highly recommended to use it to generate your [[Device tree|device tree]]. Moreover, [[STM32CubeMX]] integrates all the information documented in the [[STM32MP15 resources#DS12505|datasheet]], making this configuration step straightforward. <br /><br /> Since a GPIO configuration is done via atomic registers read and write, concurrent accesses from different cores must be avoided and that is why all GPIO configurations are done by the Arm<sup>®</sup> Cortex<sup>®</sup>-A7. The strategy is to progressively initialize the GPIO all along the [[Boot chain overview|boot chain]], as soon as one boot component needs to use them: * Most of the GPIOs used by the [[STM32MP15 ROM code overview|ROM code]] are directly defined in the ROM code but it is possible to change some pins muxing via dedicated words in [[BSEC internal peripheral|BSEC]]. * The other boot components are relying on a common binding<ref>{{CodeSource | Linux kernel | Documentation/devicetree/bindings/pinctrl/st,stm32-pinctrl.txt | Documentation/devicetree/bindings/pinctrl/st,stm32-pinctrl.txt}}</ref> in the [[Device tree|device tree]] to get the pins configuration: ** The [[Boot chain overview|FSBL]] configures both secure (GPIOZ) and non-secure (GPIOA to GPIOK) instances. ** The [[Boot chain overview|SSBL]] and Linux [[Pinctrl overview|pinctrl]] configure only non-secure instances, so GPIOA to GPIOK, and only the pins left non-secure in GPIOZ by the [[Boot chain overview|FSBL]]. Linux also initializes the GPIO used by the coprocessor, via its [[Resource_manager_for_coprocessing#Resource_management_on_the_Cortex-M_firmware|resource manager]]. ===Runtime=== ====Overview==== The '''GPIO configuration''' must not be done from different cores to avoid concurrent accesses, but this is not the case for the '''GPIO using''': each core can manipulate IO on its own since dedicated set/clear registers are available for that.<br /> <br /> Nevertheless, beyond the boot time, the GPIO configuration also evolves at runtime: while entering in [[Power overview|low power mode]], some GPIOs may be put back to analog input mode in order to reduce the power consumption. This is done in two times: # the Arm<sup>®</sup> Cortex<sup>®</sup>-A7 non-secure takes care of the non-secure GPIO with Linux [[Overview of GPIO pins|IOs pins]] frameworks. # the Arm<sup>®</sup> Cortex<sup>®</sup>-A7 secure takes care of the secure pins of GPIOZ behind [[TF-A overview#BL32|PSCI secure services]]. On wakeup, the [[Boot chain overview|boot chain]] restores the GPIO configuration similarly to what is done at boot time. <br /><br /> Let's come back to the runtime allocation... <br /><br /> The GPIOZ pins can individually be: * set secure and assigned to the Arm<sup>®</sup> Cortex<sup>®</sup>-A7 secure for using with [[OP-TEE overview|OP-TEE]] or * set non-secure and assigned to the Arm<sup>®</sup> Cortex<sup>®</sup>-A7 non-secure for using in Linux<sup>®</sup> with the [[Overview of GPIO pins|IOs pins]] frameworks or * set non-secure and assigned to the Arm<sup>®</sup> Cortex<sup>®</sup>-M4 for using in STM32Cube with [[STM32CubeMP1 architecture|GPIO HAL driver]] <br /> The GPIOA to GPIOK pins can individually be: * assigned to the Arm<sup>®</sup> Cortex<sup>®</sup>-A7 non-secure for using in Linux<sup>®</sup> with the [[Overview of GPIO pins|IOs pins]] frameworks or * assigned to the Arm<sup>®</sup> Cortex<sup>®</sup>-M4 for using in STM32Cube with [[STM32CubeMP1 architecture|GPIO HAL driver]] ====Software frameworks==== {{:Internal_peripherals_software_table_template}} | Core/IOs | [[GPIO internal peripheral|GPIO]] | [[OP-TEE_overview|OP-TEE GPIO driver]] | [[Overview of GPIO pins|Linux IOs pins overview]] | [[STM32CubeMP1 architecture|STM32Cube GPIO driver]] | |- |} ====Peripheral configuration==== The configuration is applied by the firmware running in the context to which the peripheral is assigned. The configuration by itself can be done via [[STM32CubeMX]] tool for all internal peripheral, then it can be manually completed (especially for external peripherals) according to the information given in the corresponding software framework article. In Linux kernel, each GPIO bank is declared as a "gpio-controller" in the device tree and each pin can then be used via two different consumer frameworks: * [[Pinctrl overview|Pinctrl]] framework is used to control the alternate function (AF) selection for a given device driver, via the [[Pinctrl device tree configuration]]. * [[GPIOLib overview|Gpiolib]] framework is used to control a pin in GPIO mode from another device driver or a user space application: refer to [[GPIO device tree configuration]] for further details. ====Peripheral assignment==== {{:Internal_peripherals_assignment_table_template}} <onlyinclude> | rowspan="12" | Core/IOs | rowspan="12" | [[GPIO internal peripheral|GPIO]] | GPIOA (16 pins) | | <span title="assignable peripheral" style="font-size:21px">☐</span> | <span title="assignable peripheral" style="font-size:21px">☐</span> | Shareable (with pin granularity) |- | GPIOB (16 pins) | | <span title="assignable peripheral" style="font-size:21px">☐</span> | <span title="assignable peripheral" style="font-size:21px">☐</span> | Shareable (with pin granularity) |- | GPIOC (16 pins) | | <span title="assignable peripheral" style="font-size:21px">☐</span> | <span title="assignable peripheral" style="font-size:21px">☐</span> | Shareable (with pin granularity) |- | GPIOD (16 pins) | | <span title="assignable peripheral" style="font-size:21px">☐</span> | <span title="assignable peripheral" style="font-size:21px">☐</span> | Shareable (with pin granularity) |- | GPIOE (16 pins) | | <span title="assignable peripheral" style="font-size:21px">☐</span> | <span title="assignable peripheral" style="font-size:21px">☐</span> | Shareable (with pin granularity) |- | GPIOF (16 pins) | | <span title="assignable peripheral" style="font-size:21px">☐</span> | <span title="assignable peripheral" style="font-size:21px">☐</span> | Shareable (with pin granularity) |- | GPIOG (16 pins) | | <span title="assignable peripheral" style="font-size:21px">☐</span> | <span title="assignable peripheral" style="font-size:21px">☐</span> | Shareable (with pin granularity) |- | GPIOH (16 pins) | | <span title="assignable peripheral" style="font-size:21px">☐</span> | <span title="assignable peripheral" style="font-size:21px">☐</span> | Shareable (with pin granularity) |- | GPIOI (16 pins) | | <span title="assignable peripheral" style="font-size:21px">☐</span> | <span title="assignable peripheral" style="font-size:21px">☐</span> | Shareable (with pin granularity) |- | GPIOJ (16 pins) | | <span title="assignable peripheral" style="font-size:21px">☐</span> | <span title="assignable peripheral" style="font-size:21px">☐</span> | Shareable (with pin granularity) |- | GPIOK (8 pins) | | <span title="assignable peripheral" style="font-size:21px">☐</span> | <span title="assignable peripheral" style="font-size:21px">☐</span> | Shareable (with pin granularity) |- | GPIOZ (8 pins) | <span title="assignable peripheral" style="font-size:21px">☐</span> | <span title="assignable peripheral" style="font-size:21px">☐</span> | <span title="assignable peripheral" style="font-size:21px">☐</span> | Shareable (with pin granularity) |- </onlyinclude> |} ==How to go further== Not applicable. ==References== <references/> <noinclude> [[Category:IOs pins peripherals]] {{ArticleBasedOnModel | Internal peripheral article model}} {{PublicationRequestId | 8785 | 2018-09-18 | AlainF}} {{ReviewsComments|JCT 1840: alignment needed with the last version of the model [[Contributors:Internal peripheral article model]]}} </noinclude>
该页面使用的模板:
Internal peripherals assignment table template
(
查看源代码
)
Internal peripherals software table template
(
查看源代码
)
模板:ArticleBasedOnModel
(
查看源代码
)
模板:CodeSource
(
查看源代码
)
模板:PublicationRequestId
(
查看源代码
)
模板:ReviewsComments
(
查看源代码
)
返回至
GPIO internal peripheral
。
导航
导航
WIKI首页
官方店铺
资料下载
交流社区
所有页面
所有产品
MPU-Linux开发板
MCU-单片机开发板
Linux开发系列视频
单片机开发系列视频
所有模块配件
Wiki工具
Wiki工具
特殊页面
页面工具
页面工具
用户页面工具
更多
链入页面
相关更改
页面信息
页面日志