Advantages of Hiring UIUX Design Service Providers for Your Business
F9 microkernel app development part 2 gpio meets led
1. Part 2: GPIO meets LED
ben6
2014-04-21
F9-Microkernel App Development
2. Agenda
• Why we have to know GPIO?
• What’s GPIO?
• How to use GPIO?
F9
3. Why we have to know GPIO?
Basis of external hardware control
GPIO (General-purpose input/output)
Storage
devices
NICs Buttons LED
…
4. 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
5. 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
7. 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;
}
8. 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);
9. 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
10. 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?
11. 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);
15. 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
16. 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
17. Code reading of GPIO for user part
• user/include/gpioer.h
• user/lib/io/gpioer.c
18. 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
19. 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
20. First f9 GPIO app practice to control
led light
• PR86
– https://github.com/f9micro/f9-kernel/pull/86
• Demo
1. built-in 4 LEDs Blinking
2. trigger External LED
24. 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.git
git checkout 0421-gpioer
25. 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
27. 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 中文使用手冊
Notes de l'éditeur
其實日常使用設備裡都有 GPIO,小到 LED 燈號,大到各式外接設備,大多都會使用到 GPIO。通常我們program使用的data都是放在memory比較多,而GPIO也提供類似的操作方法給programmer(讓我們去更改記憶體內容就可以去控制pin,並影響周遭設備的運行),但真正的設備的位置並非真正落在記憶體上(如:LED、Button、…等),故GPIO的核心是記憶體操作與設備之間的一些電路特性。
Typically, A GPIO port is grouped 8 GPIO pinsGPIO雖然建立起記憶體與設備之間的橋梁,但也並非我們就可以隨意使用,我們必須要經過設定之後才能讓我們想要的設備正常工作。一個pin通常可被設定成input、output、alternatefunction或analog,input會有兩種狀態表現(floating, pull-up/down),output也有兩種狀態表現(push-pull with pull-up/pull-down or open drain with pull-up/down)。input/output方向解說 : input是指記憶體方接收來自設備的訊號源,output是指記憶體傳送訊號給設備。當pin被設定成input時,非analog的設定下,我們可以利用GPIO的input data register(GPIOx_IDR) 或是memory中提供給目標設備的data register (當設成alternatefunction的時候)去接收data。當pin被設定成output時,非analog的設定下,GPIO本身有提供output data register (GPIOx_ODR)來對目標設備做控制,但要是pin不是使用原本預先定義好的功能時(非預先定義的功能都算是alternate function的類別),此時要用memory中,另外規劃給目標設備用的register。如果pin被設成analog的話,無論input or output都會由adc那邊做處理。
floating vs. pull-up/pull-down當input pin被處在高阻抗的模式下,若沒有外部訊號源進來的話,此時是無法確定pin的狀態(不能確定現在處在高電位或低電位),除非有外部訊號來驅動電路。換句話說,input floating,這個input電位狀態完全是由外部訊號來決定,沒有訊號驅動的話,就會呈現高阻抗狀態。剛剛提到floating在沒有外部訊號驅動的情況下是呈現高阻抗狀態(無法確定電位狀態=>不能明確表示現在值是0或1),如果我們需要這個pin有一個明確的預設狀態時,必須借助pull-up(pull-down)resistor來做調整,在pull-up resistor(pull-up外接高電壓,pull-down通常會接地)加入之下,讓pin的維持在明確的高電壓狀態(pull-down則是讓pin維持在低電壓狀態)。舉例來說,如果我們定電壓在3-4 V之間是1的狀態,0-1之間是0的狀態,高阻抗的時候,電壓是不明確的,有可能電壓值會落在1-3之間的不明確地帶,甚至是沒有在任何一個狀態維持一段時間,此時的狀態是未定的,但如果我們加入pull-up resistor的話,這個pin接受來自pull-up另一端的電壓供應,讓pin至少維持在3v以上時,我們就可以確定在沒有外部訊號驅動時,pin是維持在高電位狀態。
Typically, A GPIO port is grouped 8 GPIO pinsGPIO雖然建立起記憶體與設備之間的橋梁,但也並非我們就可以隨意使用,我們必須要經過設定之後才能讓我們想要的設備正常工作。一個pin通常可被設定成input、output、alternatefunction或analog,input會有兩種狀態表現(floating, pull-up/down),output也有兩種狀態表現(push-pull with pull-up/pull-down or open drain with pull-up/down)。input/output方向解說 : input是指記憶體方接收來自設備的訊號源,output是指記憶體傳送訊號給設備。當pin被設定成input時,非analog的設定下,我們可以利用GPIO的input data register(GPIOx_IDR) 或是memory中提供給目標設備的data register (當設成alternatefunction的時候)去接收data。當pin被設定成output時,非analog的設定下,GPIO本身有提供output data register (GPIOx_ODR)來對目標設備做控制,但要是pin不是使用原本預先定義好的功能時(非預先定義的功能都算是alternate function的類別),此時要用memory中,另外規劃給目標設備用的register。如果pin被設成analog的話,無論input or output都會由adc那邊做處理。