Getting userinput in STM32F4Discovery using ChibiOS RTOS

To get user input in STM32F4Discovery..chnage directory to the concerned folder

cd ChibiOS_2.4.1/demos/ARMCM4-STM32F407-DISCOVERY/

edit the main.c file and insert this code

#include "ch.h"
#include "hal.h"

int main(void) {

halInit();
chSysInit();

palSetPadMode(GPIOD,4, PAL_MODE_INPUT);
palSetPadMode(GPIOD,6, PAL_MODE_OUTPUT_PUSHPULL);

while (TRUE) {
int x;
x=palReadPad(GPIOD,4);
if (x){
palSetPad(GPIOD, 6);
}
else{
palClearPad(GPIOD, 6);
}

}
}

Here GPIOD pin4 is set as input and pin6 is set as output….I connected a button to 5v and the out of the button is connected to  pin4 which is set as input whenever i press the button pin4 becomes high and whenever pin4 becomes high pin6 becomes high an led is connected to pin6 to know the user button action…

to generate binary

cd ChibiOS_2.4.1/demos/ARMCM4-STM32F407-DISCOVERY/

make

st-flash write build/ch.bin 0x08000000

Happy Hacking 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s