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




Loading

STM32F4 (I2S) - how to properly configure DMA1_Stream7_IRQHandler priority?

Posted by robbo1975 on September 5, 2016

Hi Last week I started porting Helix mp3 decoder to FreeRTOS enviroment and I stuck on DMA1Stream7IRQHandler. Inside the interrupr routine I release transmission complete semaphore by xSemaphoreGiveFromISR (xSemaphoreTC, &xHigherPriorityTaskWoken). Calling of this function causes permanent stuck inside vPortValidateInterruptPriority( void ). I know the problem is related to the priorities, but i can't solve it by myself. Is there any helping hand? By the way, i'm rookie to FreeRTOS. :)

Dma configuration code ~~~ void DMA1Stream7cfg () { DMAInitTypeDef DMAInitStructure; NVICInitTypeDef NVICInitStructure;

RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_DMA1, ENABLE);

DMA_DeInit (DMA1_Stream7);
DMA_InitStructure.DMA_Channel = DMA_Channel_0;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) & SPI3->DR;
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;

DMA_InitStructure.DMA_Memory0BaseAddr = 0;
DMA_InitStructure.DMA_BufferSize = 0;

DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_Low;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init (DMA1_Stream7, &DMA_InitStructure);

/* Config the DMA Stream IRQ Channel */
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream7_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configMAX_SYSCALL_INTERRUPT_PRIORITY;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init (&NVIC_InitStructure);
/* Enable DMA request after last transfer (Single-ADC mode) */
DMA_ITConfig (DMA1_Stream7, DMA_IT_TC, ENABLE);
NVIC_EnableIRQ (DMA1_Stream7_IRQn);

} ~~~

DMA Irq ~~~ void DMA1Stream7IRQHandler () { BaseType_t xHigherPriorityTaskWoken; xHigherPriorityTaskWoken = pdFALSE;

if (DMA_GetITStatus (DMA1_Stream7,DMA_IT_TCIF7) != RESET)
{
	DMA_ClearITPendingBit (DMA1_Stream7, DMA_IT_TCIF7);
   /* and after that kernel hangs in vPortValidateInterruptPriority( void ) */
    xSemaphoreGiveFromISR (xSemaphoreTC, &xHigherPriorityTaskWoken);
	wait = 0;
}
portYIELD_FROM_ISR (xHigherPriorityTaskWoken);

} ~~~

and code fired transmission

~~~ if (buffready) { DMA1Stream7->NDTR = bufflen; DMA1Stream7->M0AR = (uint32t) buff; DMA1Stream7->CR |= DMASxCREN; buff_nr ^= 1;

			while (xSemaphoreTake (xSemaphoreTC, (TickType_t) 20) == pdFALSE)
			{
				vTaskDelay(1);
			}

~~~

Regards Krzysztof Sroka


STM32F4 (I2S) - how to properly configure DMA1_Stream7_IRQHandler priority?

Posted by rtel on September 5, 2016

I suspect your problem will be with this line:

NVICInitStructure.NVICIRQChannelPreemptionPriority = configMAXSYSCALLINTERRUPT_PRIORITY;

which is using an unshifted priority value (the priority bits are already set in the most significant bits) - whereas you probably need to use an unshifted value (whereas the priority bits are set in the least significant bits). See the following link for more details:

http://www.freertos.org/RTOS-Cortex-M3-M4.html

DMA1Stream7IRQHandler

In this handler it would be more efficient to use a direct to task notification than a semaphore.


STM32F4 (I2S) - how to properly configure DMA1_Stream7_IRQHandler priority?

Posted by robbo1975 on September 5, 2016

So that any use of NVIC_Init () will cause mess up with priorities?

Regards Krzysztof Sroka


STM32F4 (I2S) - how to properly configure DMA1_Stream7_IRQHandler priority?

Posted by rtel on September 5, 2016

I'm not sure what more I can say over what I already mentioned in my last email as I have already pointed out the line in your code that I think is wrong. Perhaps you should grep NVIC_InitTypeDef in the FreeRTOS/demo directory to see examples of how the structure is being used (be careful to see how the FreeRTOS code is actually using it, rather than uses within the ST code itself).


STM32F4 (I2S) - how to properly configure DMA1_Stream7_IRQHandler priority?

Posted by robbo1975 on September 5, 2016

Heh, the most confusing thing is that I have the same mechanism used in my previus project. The diference is is only in peripherials, where data was transferred form ADC to ram buffer.

~~~ void DMA2Stream0IRQHandler (void) { BaseType_t xHigherPriorityTaskWoken;

xHigherPriorityTaskWoken = pdFALSE;

if (DMA_GetITStatus (DMA2_Stream0, DMA_IT_TCIF0))
{
	DMA_ClearITPendingBit (DMA2_Stream0, DMA_IT_TCIF0);
	TIM_Cmd (TIM2, DISABLE);
	xSemaphoreGiveFromISR (xSemaphore, &xHigherPriorityTaskWoken);
	GPIO_ToggleBits( GPIOD, GPIO_Pin_8);
}

if (DMA_GetITStatus(DMA2_Stream0, DMA_IT_TEIF0))
{
	DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TEIF0);
	xSemaphoreGiveFromISR (xSemaphore, &xHigherPriorityTaskWoken);
}
portYIELD_FROM_ISR (xHigherPriorityTaskWoken);

} ~~~

and init

~~~ NVICInitStructure.NVICIRQChannel = DMA2Stream0IRQn; NVICInitStructure.NVICIRQChannelPreemptionPriority = 13; NVICInitStructure.NVICIRQChannelSubPriority = 13; NVICInitStructure.NVICIRQChannelCmd = ENABLE; NVICInit (&NVICInitStructure); ~~~

Code above works perfectly. Weird...

Regards Krzysztof Sroka


STM32F4 (I2S) - how to properly configure DMA1_Stream7_IRQHandler priority?

Posted by robbo1975 on September 5, 2016

I have tested now pri and subpri set to 13. Nothing changes.

Regards Krzysztof Sroka


STM32F4 (I2S) - how to properly configure DMA1_Stream7_IRQHandler priority?

Posted by rtel on September 5, 2016

I have tested now pri and subpri set to 13. Nothing changes.

Please read the page I linked to in my first reply, and look at the examples in the download. This is still wrong.


STM32F4 (I2S) - how to properly configure DMA1_Stream7_IRQHandler priority?

Posted by robbo1975 on September 5, 2016

Mea culpa... I had incorrectly defined parameters configKERNELINTERRUPTPRIORITY and configMAXSYSCALLINTERRUPT_PRIORITY in FreeRTOSConfig.h. :/ Thank you very much for help! I'm tired of this and I read without understanding the content... Finally everything work ok.

Regards Krzysztof Sroka


[ 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