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


FreeRTOS Sempahore from ISR not working

Posted by ableeldhose on January 23, 2014

I need to make a data accusition device whose one task is to samples some GPIO's and record the GPIO status and send it to PC via UART to display in PC. The algorithm i chose was (please correct me since iam very novice in RTOS) to create a timer running at 1us and then poll the status of all GPIO needed. For that i used a timer in the freertos demo. And give a semaphore in the timer ISR which should call a task which do all the remaining job.

Don't know why but the code i edited dont work

My main() is

int main(void) {
  /* Prepare the hardware to run this demo. */

  if( SemaphoreTask != NULL )
    xTaskCreate( SemaphoreTakeTask, "SemaphoreTakeTask", 240, NULL , 3, NULL );
  return 0;

Task 1 a dummy function i wrote just to try out if semaphore is working

void SemaphoreTakeTask(void* parameter){
  vSetupTimerTest(10);                 // Timer initialization function in FreeRtos DEMO
  TRISEbits.TRISE6 = 0;                // Set the GPIO as Output
  xSemaphoreTake( SemaphoreTask, 0 );  // As mentioned in user guide just take the semaphore once to clear the semaphore at start
    xSemaphoreTake( SemaphoreTask, portMAX_DELAY );
    LATEbits.LATE6 ^= 1;               // Toggle an IO to see whether its working

Timer ISR handler

void vT2InterruptHandler(void) {
  portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
  /* Clear the timer interrupt. */
  xSemaphoreGiveFromISR(SemaphoreTask, &xHigherPriorityTaskWoken);
  if (xHigherPriorityTaskWoken != pdFALSE) {

When i put break point in the ISR handler it comes there but the GPIO is not toggling (which i placed in Task 1)

Iam a novice in RTOS so please pardon me if i missed any basic things in the code

I just need to give a semaphore from ISR handler

FreeRTOS Sempahore from ISR not working

Posted by edwards3 on January 23, 2014

I cant see anything wrong with your use of the FreeRTOS API. You dont need to test xHigherPriorityTaskWoken before callilng portENDSWITCHINGISR as the test is in the macro, but it wont cause you a problem.

But do you really want to do this at 1uS. That is too fast to use a queue in this way. At that speed you need to do the IO sampling inside the interrupt handling function, even then it is very fast. You will need to pack the sampled bits into larger data variables to send at that rate over a uart.

FreeRTOS Sempahore from ISR not working

Posted by ableeldhose on January 24, 2014

@Medwards I added one extra task Task1 which just blinks another LED1 using vTaskDelay. Another task Task2 which waits for the semaphore and toggles an LED2 when recieved semaphore.

When Semaphore is given from the Task1 everything works fine.

When that semaphore is given from ISR which occurs after 5 second Untill the xSemaphoreGiveFromISR is called the Task1 is working, but when it is called everything gets stuck and the code moves to a infinite loop in vAssertCalled(). So for 5 seconds LED1 will toggle and after that its does not.

When i commented that xSemaphoreGiveFromISR in the ISR then Task1 is working without any issue

I placed a breakpoint just below the xSemaphoreGiveFromISR and the control never reach that line. When the xSemaphoreGiveFromISR is commented then control reaches there.

I cant understand the issue since iam a starter in RTOS

FreeRTOS Sempahore from ISR not working

Posted by rtel on January 24, 2014

Each call to configASSERT() contains a condition that is tested to ensure the system status (variable values, hardware state, etc.) is valid. As vAssertCalled() is being called then a condition passed to configASSERT() has been found to be invalid - which is presumably why your application is not working.

Which call to configASSERT() is failing?


FreeRTOS Sempahore from ISR not working

Posted by ableeldhose on January 24, 2014

The configAssert() call from the below #define is found to get stuck


The #define expansion is


After this function call everything gets stuck. No task is running after this

FreeRTOS Sempahore from ISR not working

Posted by davedoors on January 24, 2014

You must set the priority of the interrupt to below your configMAXSYSCALLINTERRUPT_PRIORITY setting. Read the Configuration section of the web page that details how to use the port. THe following page might help (or serve to confuse more) too http://www.freertos.org/RTOS-Cortex-M3-M4.html

FreeRTOS Sempahore from ISR not working

Posted by ableeldhose on January 24, 2014

@Dave Thanks man It works

[ 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