Date post: | 13-May-2015 |
Category: |
Technology |
Upload: | benux-wei |
View: | 825 times |
Download: | 8 times |
Part 2: GPIO meets LED
ben62014-04-21
F9-Microkernel App Development
Agenda
• Why we have to know GPIO?• What’s GPIO?• How to use GPIO?
F9
Why we have to know GPIO?
Basis of external hardware control
GPIO (General-purpose input/output)
Storagedevices
NICs Buttons LED …
Agenda
• Why we have to know GPIO?• What’s GPIO?– F9 GPIO API for basic app– Code reading about F9 GPIO Hooks
• How to use GPIO?
F9
What’s GPIO?
• GPIO -- General-purpose input/output– Generic pin on a chip whose behavior
can be controlled by the user at run time
– Support DMA (Direct Memory Access) control
STM32F407VGT6 GPIOx
GPIO input
• Floating: unknown voltage input stage• Pull-up: connect to high voltage• Pull-down: connected to ground• Non-analog mode: input data register (GPIO_IDR)
Memory Devices
gpio_input_bit(port, pin){
if (*GPIO_IDR(port) & (1 << pin))return 1;
return 0;}
GPIO output
• push-pull with pull-up/pull-down• open-drain with pull-up/pull-down• Non-analog mode, output data register (GPIO_ODR)
Memory Devices
*GPIO_ODR(GPIOA) |= (1 << pin);
Agenda
• Why we have to know GPIO?• What’s GPIO?– F9 GPIO API for basic app– Code reading about F9 GPIO Hooks
• How to use GPIO?
F9
PR #86 GPIO V1 implementation
Kernel part• include/thread.h• include/user-gpioer.h• kernel/ipc.c• kernel/user-gpioer.c
App part: library and app• user/apps/gpioer/main.c• user/include/gpioer.h• user/lib/io/gpioer.c
Pull request#86 https://github.com/f9micro/f9-kernel/pull/86
GPIO V2: Kernel part GPIO driver code will move to user-space because this
part violates L4 design principle
GPIO V2: How to make thread has authority to access AHB1_1DEV?
V1: F9 GPIO API for basic app
• Defined in user/include/gpioer.h• gpioer_config_output• gpioer_out
void gpioer_config_output(uint8_t port, uint8_t pin, uint8_t pupd, uint8_t speed);
void gpioer_out(uint8_t port, uint8_t pin, uint8_t action);
V1: gpioer_config_output
void gpioer_config_output(
uint8_t port, /* Ex: GPIOA, … , GPIOD, …*/
uint8_t pin, /* 0 – 15 */
uint8_t pupd, /* GPIO_PUPDR_UP */
uint8_t speed /* GPIO_PUPDR_UP,GPIO_OSPEEDR_50M */
);
Wrap gpio_config_output from include/platform/stm32f4/gpio.h
GPIO Output Type
#define GPIO_OTYPER_PP (uint32_t (0x0) /* Output push-pull */
#define GPIO_OTYPER_OD (uint32_t)(0x1) /* Output open drain */
include/platform/stm32f4/registers.h
GPIO Speed
#define GPIO_OSPEEDR_2M (uint32_t) (0x0) /* Output speed 2MHz
*/
#define GPIO_OSPEEDR_25M (uint32_t) (0x1) /* Output speed 25MHz
*/
#define GPIO_OSPEEDR_50M (uint32_t) (0x2) /* Output speed 50MHz
*/
#define GPIO_OSPEEDR_100M(uint32_t) (0x3) /* Output speed
100MHz*/
include/platform/stm32f4/registers.h
V1: gpioer_out
void gpioer_out(uint8_t port,
uint8_t pin,
uint8_t action /* GPIO_HIGH or GPIO_LOW */
);
Wrap gpio_out_high and gpio_out_low from include/platform/stm32f4/gpio.h
Agenda
• Why we have to know GPIO?• What’s GPIO?– F9 GPIO API for basic app– Code reading about F9 GPIO Hooks
• How to use GPIO?
F9
Code reading of GPIO for user part
• user/include/gpioer.h• user/lib/io/gpioer.c
Code reading about F9 GPIO Hooks
– include/thread.h– include/user-gpioer.h– kernel/build.mk– kernel/ipc.c– kernel/user-gpioer.c
Implementation of this hook by reference the THREAD_LOG printf function
Agenda
• Why we have to know GPIO?• What’s GPIO?• How to use GPIO?– First f9 GPIO app practice to control led light– Lab3: make led blinking in turns
F9
First f9 GPIO app practice to control led light
• PR86– https://github.com/f9micro/f9-kernel/pull/86
• Demo1. built-in 4 LEDs Blinking2. trigger External LED
Live Demo 1: built-in 4 LEDs Blinking
STM32F407 Built-in 4 User LEDs
LD3 (orange)LD4 (green) LD5 (red) LD6 (blue)
PD13
PD12
PD14
PD15
Live Demo 2: trigger External LED
Lab 3: LEDs blinking Rocks
Requirements– Modify LED sample to let the led in turns– Blinking interval 2 seconds
Hints: reference user/apps/gpioer/main.c
git clone https://github.com/benwei/f9-kernel.gitgit checkout 0421-gpioer
Summary: Points recall
• GPIO is the basis of external control
• What’s implementation of GPIO api for user app
• Easy to use API for gpioer for pin output control
Discussions
?
F9
References• F9 Microkernel source code and introduction
• GCC Naked Attribute
• ARM: Memory Model of Cortex M4
• Cortex™ -M4 Devices Generic User Guide pdf
• General-purpose Input/Output (GPIO)
• UM1472 User manual Discovery kit for STM32F407/417 lines
• STM32F4-Discovery 中文使用手冊