Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: [SOLVED] Initialization of USART with PDC in my own driver
PostPosted: Sun Nov 06, 2011 10:16 pm 
Offline

Joined: Sat Sep 24, 2011 11:33 pm
Posts: 13
Hi,

A few weeks ago I was discussing a problem of achieving of high throughput in AT91SAM9260 USART.
After resolving problems with PDC buffer (which had to be moved to internal SRAM) and bus matrix (which should pioritize USART) it appeared that I have to replace the original
USART driver with my own, which uses CPU to copy the data only once - from PDC buffer in SRAM to final buffer mmapped into application memory.
I've written such a driver (it will be published under GPL after some polishing), but still have a problem with USART initialization.

Below is the code (based on analysis of atmel_serial.c), which I use to initialize USART and PDC (I've changed macros used in atmel_serial.c, so that they do not need "port" argument - using the USART2 registers). I have also removed error handling when
copying the code to this message.

[code]
//Register the interrupt service routine
request_irq(AT91SAM9260_ID_US2, wzusart_irq, IRQF_SHARED,"WZ_USART_interrupt", THIS_MODULE);

//Set pins for USART
at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD2 */
at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD2 */
at91_set_A_periph(AT91_PIN_PA30, 1); /* SCK2 */

//Reserve the DMA buffer in internal SRAM
if (request_mem_region(AT91SAM9260_SRAM0_BASE, 2*PDC_BUFFER_SIZE, "wzusart")) {
rx_dma_buf = AT91SAM9260_SRAM0_BASE;
} else if (request_mem_region(AT91SAM9260_SRAM1_BASE, 2*PDC_BUFFER_SIZE, "wzusart")) {
rx_dma_buf = AT91SAM9260_SRAM1_BASE;
} else {
//We were not able to allocate the DMA buffer in SRAM
return -ENOMEM;
}
//Create mapping for the allocated buffer
rx_virt_buf = ioremap(rx_dma_buf,2*PDC_BUFFER_SIZE);
//Alocate the area for USART registers
request_mem_region(WZ_USART_BASE, 0x80, "wzusart"));
//Create mapping for registers
usart_regs=ioremap(WZ_USART_BASE, 0x80);

//Initialize the hardware - only receiver is used, SYNC mode, external clock on SCK2,
//6MB/s
//Reset both transmitter and receiver
UART_PUT_CR(ATMEL_US_RXDIS | ATMEL_US_TXDIS | ATMEL_US_RSTRX | ATMEL_US_RSTTX);
//Initialize PDC part of USART
UART_PUT_PTCR(ATMEL_PDC_TXTDIS);
UART_PUT_PTCR(ATMEL_PDC_RXTDIS);
UART_PUT_RPR(rx_dma_buf);
UART_PUT_RNPR(rx_dma_buf+PDC_BUFFER_SIZE);
UART_PUT_RCR(PDC_BUFFER_SIZE);
UART_PUT_RNCR(PDC_BUFFER_SIZE);
//Initialize USART transmission parameters
UART_PUT_MR(ATMEL_US_USMODE_NORMAL | ATMEL_US_USCLKS_SCK | ATMEL_US_CHRL_8 |
ATMEL_US_SYNC | ATMEL_US_PAR_NONE | ATMEL_US_NBSTOP_1 |
ATMEL_US_CHMODE_NORMAL );
//Set the timeout
UART_PUT_RTOR(60);
UART_PUT_CR(ATMEL_US_RSTSTA | ATMEL_US_STTTO);
//Finally start the reception
UART_PUT_CR(ATMEL_US_RXEN | ATMEL_US_TXEN);
/* enable PDC controller */
UART_PUT_IER(ATMEL_US_ENDRX | ATMEL_US_TIMEOUT | read_status_mask);
UART_PUT_PTCR(ATMEL_PDC_RXTEN);
[/code]

The problem is, that after the above initialization I receive no USART interrupts.
I can see, that clock is correctly provided to SCK2 line, and that input data are visible at RXD2 pin, but number of interrupts received on line 8 (assigned to USART2) in /proc/interrupts is still equal to zero and my interrupt routine is never called...
Where have I mistaken in my initialization code?
--
TIA,
Wojtek

UPDATE 1:
I have found initialization code template in viewtopic.php/f,9/t,19205/
The only difference is that final PTCR value is written before CR (In my code I first write CR, then IER and finally PTCR. Could it cause the observed problems?

UPDATE 2:
I have changed the order of instrunctions according to update 1, but it didn't help.
The real problem was, that the USART2 clock was not enabled.
I have to call:
clk_enable(clk_get(NULL,"usart2_clk"));
in the module initialization function
and
clk_disable(clk_get(NULL,"usart2_clk"));
in the module exit function.

Now I can receive my data!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: