3. 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.
4. GPIO Input
• Floating
unknown voltage input stage
• Pull-up
connect to high voltage
• Pull-down
connected to ground
8. Setting GPIO pins
• You can configure on the corresponding peripheral:
Speed
Mode
Type
Pull up/pull down resistors
9. Setting GPIO pins
• On the STM32F4xx the GPIO ports are connected
to the AHB1 bus
• Enabling the clock:
10. 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
11. 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, …)
12. 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
13. 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
19. 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
20. 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
21. 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