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

System restarts

Posted by saiberion on April 23, 2007
Hi,

I have a problem with the AT91SAM7S Controller using the SPI over DMA.
I already had the application working (no interrupts, no dma) and now I'd like to use the DMA for better performance.
DMA transfer for itself works but after the transfer and it's output to my serial debug port FreeRTOS starts again from the beginning in main().

Here some code snippets:
command for initiating a DMA transfer:

void spiDMA_sendandreceive(portCHAR cs, portCHAR *datatosend, portCHAR sizeofsend, portCHAR* datatoreceive, portCHAR sizeofreceive)
{
___portCHAR rectmp;
___// Use given Chipselect for transfer
___spi_select_cs(cs);

___// Initialize the Transmit and Receive Pointer
___AT91C_BASE_SPI->SPI_RPR = (unsigned int)datatoreceive;
___AT91C_BASE_SPI->SPI_TPR = (unsigned int)datatosend;

___// Intialize the Transmit and Receive Counters
___AT91C_BASE_SPI->SPI_RCR = sizeofreceive;
___AT91C_BASE_SPI->SPI_TCR = sizeofsend;

___// Enable Interrupts just for DMA transfer; The most of the application still uses the existing SPI commands
___AT91F_SPI_EnableIt(AT91C_BASE_SPI, AT91C_SPI_ENDRX);
___AT91C_BASE_SPI->SPI_PTCR = AT91C_PDC_TXTEN + AT91C_PDC_RXTEN;
___// Wait for receive to be finished
___xQueueReceive(xQueueSPIRec,&rectmp,portMAX_DELAY);
___AT91C_BASE_SPI->SPI_PTCR = AT91C_PDC_TXTDIS + AT91C_PDC_RXTDIS;
___AT91F_SPI_DisableIt(AT91C_BASE_SPI, AT91C_SPI_ENDRX);
}

The ISR: (xQueueSPIRec from above and xSPIRecQueue from below are identical; queue passing as in EMAC example in uIP demo)
void SPIISR(void)
{
___portENTER_SWITCHING_ISR();
___portBASE_TYPExTaskPreviouslyWoken;
___portCHAR cRec;
___cRec = 0xb5;

___xTaskPreviouslyWoken = pdFALSE;

___xTaskPreviouslyWoken = xQueueSendFromISR(xSPIRecQueue,&cRec,xTaskPreviouslyWoken );

___AT91C_BASE_AIC->AIC_EOICR = 0;
___portEXIT_SWITCHING_ISR(pdFALSE);
}

call of DMA:
[...]
portSHORT sRec;
spiDMA_sendandreceive(7,0,8,(portCHAR*)&sRec,8);
[...]

The SPI has following configuration:
Master Mode, Fixed Peripheral, chip select generation with decoder;
(each chip select register) CPOL = 0, NCPHA = 1, CSAAT = 0, 8-Bit transfers, SCK ~ 2MHz

RE: System restarts

Posted by embeddedc on April 23, 2007
I was going to suggest that you look at the EMAC example as this uses the DMA, but reading your post again it seems you are already doing this.

As you are always passing pdFALSE to portEXIT_SWITCHING_ISR() then you need not bother with the portENTER_SWITCHING_ISR/portEXIT_SWITCHING_ISR() macros and could instead just use the __IRQ attribute (assuming GCC). This would save you a bit of stack in case it is a stack issue that is causing the problem.

RE: System restarts

Posted by saiberion on April 24, 2007
I again reviewed the EMAC code and the documentation. The Emac works with DMA but for the SPI I intend to use the PDC as DMA controller (EMAC doesn't have PDC controls).

But somehow, like magic, my given code above today works perfectly Oo. At first I thought it was because enabling/disabling the PDC was the cause because after splitting this up in 2 calls it already worked.
Today back stepping my changes to find the erroneous part. But I ended with my code example I gave. Weird thing ;)


[ 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