f9 microkernel app development part 2 gpio meets led
DESCRIPTION
Slides for Sharing at JuluOSDev 04/21TRANSCRIPT
![Page 1: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/1.jpg)
Part 2: GPIO meets LED
ben62014-04-21
F9-Microkernel App Development
![Page 2: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/2.jpg)
Agenda
• Why we have to know GPIO?• What’s GPIO?• How to use GPIO?
F9
![Page 3: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/3.jpg)
Why we have to know GPIO?
Basis of external hardware control
GPIO (General-purpose input/output)
Storagedevices
NICs Buttons LED …
![Page 4: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/4.jpg)
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
![Page 5: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/5.jpg)
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
![Page 6: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/6.jpg)
STM32F407VGT6 GPIOx
![Page 7: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/7.jpg)
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;}
![Page 8: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/8.jpg)
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);
![Page 9: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/9.jpg)
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
![Page 10: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/10.jpg)
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?
![Page 11: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/11.jpg)
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);
![Page 12: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/12.jpg)
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
![Page 13: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/13.jpg)
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
![Page 14: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/14.jpg)
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
![Page 15: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/15.jpg)
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
![Page 16: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/16.jpg)
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
![Page 17: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/17.jpg)
Code reading of GPIO for user part
• user/include/gpioer.h• user/lib/io/gpioer.c
![Page 18: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/18.jpg)
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
![Page 19: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/19.jpg)
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
![Page 20: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/20.jpg)
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
![Page 21: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/21.jpg)
Live Demo 1: built-in 4 LEDs Blinking
![Page 22: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/22.jpg)
STM32F407 Built-in 4 User LEDs
LD3 (orange)LD4 (green) LD5 (red) LD6 (blue)
PD13
PD12
PD14
PD15
![Page 23: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/23.jpg)
Live Demo 2: trigger External LED
![Page 24: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/24.jpg)
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
![Page 25: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/25.jpg)
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
![Page 26: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/26.jpg)
Discussions
?
F9
![Page 27: F9 microkernel app development part 2 gpio meets led](https://reader035.vdocuments.net/reader035/viewer/2022062418/5552dc17b4c90532498b4bad/html5/thumbnails/27.jpg)
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 中文使用手冊