Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

STM32 Not resuming other tasks after IRQ

Posted by moamind on September 2, 2014

I am writing an application using FreeRTOS V8.0.1 and the STM32F4 discovery board (Cortex-M4) in keil.

When powering and running a GPS reciever on USART2 after the IRQ is run no other tasks will resume. It was my understanding that with the Cortex-M4 processors no state saving functions need to be called during the ISR to preserve the system state and ISRs can be written as normal ensuring any rtos functions are *FromISR

In the code below I have an LCD initialise and display the some SD card information with another task updating the display with clock information. As soon as the gpstask runs and the chip recieves power (therefore transmitting NMEA strings) the IRQ will fire, the task run and then according to the debugger the application never leaves the gpstasks infinite while loop (even sleeping the task doesnt help).

I do not understand what could cause the other tasks (LED flag, Update time, etc) to no longer be scheduled.

MAIN.C

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :::c++ int main(void) { prvSetupHardware();

usartGate = xSemaphoreCreateMutex();
lcdGate = xSemaphoreCreateMutex();
sdCardGate = xSemaphoreCreateMutex();

gpsMSG = xSemaphoreCreateMutex();
supremaMSG = xSemaphoreCreateMutex();

xTaskCreate(lcd_demo, (signed char*)"lcd", 512, NULL, 2, NULL);
xTaskCreate(alert_flash, (signed char*)"lcd", 512, NULL, 1, NULL);
xTaskCreate(update_time, (signed char*)"time", 512, NULL, 1, NULL);
xTaskCreate(gps_task, (signed char*)"gps", 512, NULL,1,NULL);

/* Start the scheduler. */
vTaskStartScheduler();


for( ;; );

} /-----------------------------------------------------------/ /-----------------------------------------------------------/ void lcd_demo(void){

char buffer[40];
int row = 4;

if(xSemaphoreTake(lcdGate, 500)){
	lcd_init();	
	GLCD_Clear();
	GLCD_TextGoTo(0,row);
	row++;
	GLCD_WriteText("Power On");

	//Begin Boot Message
	GLCD_TextGoTo(0,row);
	row++;
	GLCD_WriteText("BETR V3.1 ");
	GLCD_TextGoTo(0,row);
	row++;
	row++;
	GLCD_WriteText("Acme PTY LTD");
	GLCD_TextGoTo(0,row);
	row++;
	row++;
	GLCD_WriteText("  Greetings Earthlings");
	GLCD_TextGoTo(0,row);
	row++;
	if(xSemaphoreTake (sdCardGate, 500)){
		GLCD_WriteText("Read SD Card Contents");
		if(!disk_initialize(0)){
			GLCD_TextGoTo(0,row);
			row++;
			GLCD_WriteText("Disc Initialised");
			if(!f_mount(0, &FatFs)){
				GLCD_TextGoTo(0,row);
				row++;
				GLCD_WriteText("Drive Mounted");
				fResult = f_opendir(&workDir, "");
				if(fResult == FR_OK){
					GLCD_TextGoTo(0,row);
					row++;
					GLCD_WriteText("Opened Directory");
					fResult = f_readdir(&workDir, &info);
					while(fResult == FR_OK && info.fname[0] != NULL){
						snprintf(buffer, 40, "Name: %s Size: %d Bytes",info.fname, info.fsize);
						row++;
						GLCD_TextGoTo(0,row);
						GLCD_WriteText(buffer);
						fResult = f_readdir(&workDir, &info);
	}}}}}
	xSemaphoreGive(lcdGate);
}
vTaskDelete(NULL);

while(1){
	vTaskDelay(200);
}

}

/-----------------------------------------------------------/ /-----------------------------------------------------------/ void alert_flash(void){

while(1){
	//alert_red(ON);
	alert_green(OFF);
	vTaskDelay(50);
	//alert_red(OFF);
	alert_green(ON);
	vTaskDelay(20);
}

}

/-----------------------------------------------------------/ /-----------------------------------------------------------/ void updatetime(void){ char dateString[40]; char timeString[40]; RTCDateTypeDef RTCDateStructure; RTCTimeTypeDef RTC_TimeStruct;

while(1){
	RTC_GetDate(RTC_Format_BIN, &RTC_DateStructure); //retrieve date information, consider shifting to low priority task with higher interval
	RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct);    //retrieve time information
		//Build display strings in preperation
	snprintf(dateString, 40, "Date 20%02d/%02d/%02d", RTC_DateStructure.RTC_Year, RTC_DateStructure.RTC_Month, RTC_DateStructure.RTC_Date);
	snprintf(timeString, 40, "Time %02d:%02d:%02d", RTC_TimeStruct.RTC_Hours, RTC_TimeStruct.RTC_Minutes, RTC_TimeStruct.RTC_Seconds);
	if(xSemaphoreTake(lcdGate, 500)){
		GLCD_TextGoTo(0,1);
		GLCD_WriteText("                              ");
		GLCD_TextGoTo(0,2);
		GLCD_WriteText("                              ");
		GLCD_TextGoTo(0,1);
		GLCD_WriteText(dateString);
		GLCD_TextGoTo(0,2);
		GLCD_WriteText(timeString);
		xSemaphoreGive(lcdGate);
	}
	vTaskDelay(500);
}

}

/-----------------------------------------------------------/ /-----------------------------------------------------------/

void USART2IRQHandler(void){ alertred(ON); }

void gps_task(void){

gps_init();
power_GPS(POWER_ON);

while(1){
vTaskDelay(1000);

} }

/-----------------------------------------------------------/ /-----------------------------------------------------------/ static void prvSetupHardware( void ) { /* Setup STM32 system (clock, PLL and Flash configuration) */ SystemInit();

/* Ensure all priority bits are assigned as preemption priority bits. */
NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );
power_init();
alert_init();
power_LCD(POWER_ON);
print_usart_init();
App_RTC_Init();

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

gps_init

~~~~~~~~~~~~~~~~~~~~~ :::c++

void gpsinit(void){ USARTInitTypeDef USARTInitStructure; NVICInitTypeDef NVICInitStructure; GPIOInitTypeDef GPIO_InitStructure;

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

RCCAPB1PeriphClockCmd(RCCAPB1Periph_USART2, ENABLE);

GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2);

GPIOInitStructure.GPIOSpeed = GPIOSpeed50MHz; GPIOInitStructure.GPIOMode = GPIOModeAF; GPIOInitStructure.GPIOPuPd = GPIOPuPdNOPULL; GPIOInitStructure.GPIOPin = GPIOPin3; GPIOInit(GPIOA, &GPIOInitStructure);

USART_InitStructure.USART_BaudRate = 4800;

USARTInitStructure.USARTWordLength = USARTWordLength8b; USARTInitStructure.USARTStopBits = USARTStopBits1; USARTInitStructure.USARTParity = USARTParityNo; USARTInitStructure.USARTHardwareFlowControl = USARTHardwareFlowControlNone; USARTInitStructure.USARTMode = USARTModeRx; USARTInit(USART2, &USARTInitStructure);

/* Enable the USART Interrupt */ NVICInitStructure.NVICIRQChannel = USART2IRQn; NVICInitStructure.NVICIRQChannelPreemptionPriority = 0x0F; NVICInitStructure.NVICIRQChannelSubPriority = 0x0F; NVICInitStructure.NVICIRQChannelCmd = ENABLE; NVICInit(&NVIC_InitStructure);

/* Enable USART */ USARTCmd(USART2, ENABLE); USARTITConfig(USART2, USARTITRXNE, ENABLE);

// receiverState = waitForStart; // parsedMsg.msgvalid = NOTVALID; // lastKnowGoodPos.msgvalid = NOTVALID; }

~~~~~~~~~~~~~~~~~~~~~~~~~~


STM32 Not resuming other tasks after IRQ

Posted by davedoors on September 2, 2014

I can't see that you are clearing the uart interrupt. Perhaps you are just continuously exiting then reentering the interrupt.


STM32 Not resuming other tasks after IRQ

Posted by moamind on September 2, 2014

Close Dave, thanks for the nudge.

It appears on this chipset the data buffer must be read to clear the interrupt.

modifying the IRQ handler to...

~~~~~~~~~~~~~ :::c++

void USART2IRQHandler(void){ uint8t data; data = (uint8t)USARTReceiveData(USART2);

alert_red(ON);

}

~~~~~~~~~~~~~~~

It is always fun starting with a new chip and a new OS at the same time. Mods can delete as this is not a FreeRTOS issue if they wish.


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


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

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

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner