stm32f4硬體週邊介紹
DESCRIPTION
TRANSCRIPT
GPIO
GPIO(General Purpose Input/Output)
• GPIO is a generic pin on a chip whose behavior !
including whether it is an input or output pin) can be controlled (programmed) by the user at run time.
GPIO Input
• Floating
unknown voltage input stage
• Pull-up
connect to high voltage
• Pull-down
connected to ground
Input configuration
GPIO Output
• push pull
pull-up
pull-down
• open-drain
pull-up
pull-downPull-down
Output configuration
Setting GPIO pins• You can configure on the corresponding peripheral:
Speed
Mode
Type
Pull up/pull down resistors
Setting GPIO pins• On the STM32F4xx the GPIO ports are connected
to the AHB1 bus
• Enabling the clock:
Setting GPIO pins• The GPIO’s clock can be anything of the following:
• GPIO_Speed_2MHz
GPIO_Speed_25MHz
GPIO_Speed_50MHz
GPIO_Speed_100MHz
Setting GPIO pins• On the STM32F4 the GPIO can have up to 4 modes
GPIO_Mode_OUT for digital output
GPIO_Mode_IN for digital input
GPIO_Mode_AN for analog input
GPIO_Mode_AF for the alternate functions (like SPI, I²C, USART, …)
Setting GPIO pins• For the gpio output, The type indicates the
hardware configuration of the pin which can be:
GPIO_OType_PP, !
• a push-pull is driving the output
GPIO_OType_OD!
• the output is open-drain
Setting GPIO pins•Next we can configure pull up, pull down resistors or nothing at all for each pin:!
•GPIO_PuPd_NOPULL no resistor connected
•GPIO_PuPd_UP pin is connected to a pull up resistor
•GPIO_PuPd_DOWN pin is connect to a pull down resistor
Setting GPIO pinsThe resistors value of Pull-up and Pull-down
Setting GPIO pins•A complete of code to set the gpio pin:
Interrupt
Interrupt Structure
Interrupt Structure
Interrupt handler• On way to achieve this goal consists in the creation of
tasks waiting for an interrupt to occur with a semaphore. !• Let this safer portion of code actually handle the interrupt.
An ISR “gives” a semaphore and unblock a ’Handler” task that is able to handler the ISR, making the ISR execution much shorter
Nested Vectored Interrupt Controller (NVIC)
• Depending on the implementation used by the silicon manufacturer.
• The NVIC can support up to 240 external interrupts with up to 256 different priority levels(0 to 255) that can be dynamically reprioritized.
PreemptionPriority: 4bits
SubPriority: 4bits
External Interrupt(EXTI)•Before settings EXTI, You must be:
connected from GPIO settings EXTI 設定哪條Line
• Interrupt mode • interrupt condition?(Rising, Falling, Rising&falling ) • LineCmd( ENABLE is open,DISABLE is close.)
settings NVIC • IRQ_Channel • PreemptionPriority and SubPriority • ChannelCmd
External Interrupt(EXTI)
External Interrupt(EXTI)
The hardware of controller EXTI (blue boxes are registers, red dots are input pins)
External Interrupt(EXTI)for example
Ref.!
• STM32F4 GPIO Configuration
• NCKU wiki
• Interrupts & ports
Thanks!