Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


GPIO polling in freeRTOS

Posted by ajinkya on January 31, 2013
I have very simple program written for polling a GPIO pin.

void main( void )
#ifdef DEBUG
xTaskCreate( vOnOffPoll, "AC_ON_OFF_Poll", configMINIMAL_STACK_SIZE * 3, NULL, mainCHECK_TASK_PRIORITY - 1, NULL);

for( ;; );

First I tried simple if else loop inside while(1)

void vOnOffPoll(void *pvParameters)
if( GPIO_ReadBit(GPIO4,GPIO_Pin_7) == Bit_RESET)
GPIO_WriteBit(GPIO4, GPIO_Pin_0, Bit_SET);
GPIO_WriteBit(GPIO4, GPIO_Pin_0, Bit_RESET);

then I tried switch case statement to do the same task in while(1)

void vOnOffPoll(void *pvParameters)
int state=0;
state = GPIO_ReadBit(GPIO4,GPIO_Pin_7);
case 1:
GPIO_WriteBit(GPIO4, GPIO_Pin_0, Bit_SET);
case 0:
GPIO_WriteBit(GPIO4, GPIO_Pin_0, Bit_RESET);

I have no other task but still it gets executed once it dose not poll continuously.

Initially pin (GPIO4,GPIO_Pin_7) is connected to on board GND then (GPIO4,GPIO_Pin_0) is set
but when I connect (GPIO4,GPIO_Pin_7) to on board VCC it is not changing state ((GPIO4,GPIO_Pin_0) is not reset) untill I reset kit keeping (GPIO4,GPIO_Pin_7) to on board VCC.

What is the problem? A task cannot be more simpler than this and still it is not working.

RE: GPIO polling in freeRTOS

Posted by Dave on January 31, 2013
There is nothing wrong with the code you have written and because there is only one task that never blocks and the task runs with a priority that is higher than the idle priority the task should just run continuously.

If you put a break point on the first line of the task then step through the code you should see what it is doing.

You can also replace the while loop with a simple increment variable like

volatile int i = 0;

while( 1 ) {

run your code and check that the value of i is counted up. If it is then the task is being executed as expected. If the task does not execute as expected with the original GPIO code then it must be something in the GPIO functions that stops it.

RE: GPIO polling in freeRTOS

Posted by ajinkya on January 31, 2013
Thanks davedoors for reply,
Actually I was doing small mistake in pin configuration.
Whole project we divided in modules and couldn't notice hardware config than should have changed at first place.

[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists