Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12604 Discussions

DMA Issue ,please help me,PLEASE

Altera_Forum
Honored Contributor II
1,172 Views

I have a program about DMA , The functions is send data from RS232 to SDRAM, SDRAM can receive data ,but when i check this data whther rightly, find the data that it's not send from uart . the problem is i can't receive right data from uart. this problem have trouble me about 3 weeks .please give me a sugesttion or verify this programs. deeply thanks. 

( Another program work rightly to send data from SDRAM to RS232 ,so SDRAM and RS232 work rightly) 

 

software visions: Q10.0+NIOS 10.0 

 

PLEASE HELP ME,THANK YOU 

 

the program is: 

 

//&#23383;&#31526;&#20018;&#20174;RS232&#20889;&#21040;SDRAM,&#20877;&#20174;SDRAM&#35835;&#21040;JTAG UART&#31471;# include <stdio.h># include <stdlib.h># include "sys/alt_dma.h"# include "altera_avalon_uart_regs.h"# include "system.h"# include "alt_types.h"# include <string.h> 

static volatile int tx_done = 0; 

volatile static char str[] = {"this is sdram data&#65292;written by memcpy function\n"} ;//&#24453;&#20889;&#21040;SDRAM&#30340;&#25968;&#25454;# define TRANSFER_LENGTH 1024 

//&#22238;&#35843;&#20989;&#25968; 

static void done (void* handle) 

tx_done++; 

 

int main() 

alt_u8 i; 

 

FILE *fp_LCD=0; 

FILE *fp_RS232=0; 

fp_LCD = fopen("/dev/lcd","w");  

fp_RS232 = fopen("/dev/rs232","w");  

 

 

int rc; 

alt_dma_txchan txchan; 

 

void* source = (void*)(SDRAM_BASE);/* &#28304;&#22320;&#22336; */ 

void* dest = (void*)IOADDR_ALTERA_AVALON_UART_TXDATA(RS232_BASE );  

memcpy(SDRAM_BASE,str,strlen(str)); //&#23558;STR&#22320;&#22336;&#20013;&#30340;&#23383;&#31526;&#20018;&#20889;&#21040;SDRAM 

/* &#25171;&#24320;&#21457;&#36865;&#36890;&#36947; */ 

if ((txchan = alt_dma_txchan_open("/dev/dma")) == 0) 

{ printf ("successful to open transmit channel\n"); 

exit (1); 

/* &#35774;&#32622;&#30446;&#26631;&#22320;&#22336;&#22266;&#23450; */ 

if ((rc = alt_dma_txchan_ioctl(txchan, ALT_DMA_TX_ONLY_ON, dest)) < 0) 

{ printf ("Failed to set ioctl, reason = %i\n", rc); 

exit (1); 

//&#35774;&#32622;&#27599;&#27425;&#21457;&#36865;&#19968;&#20010;&#23383;&#33410;&#65292;&#21363;8&#20301;&#65292;&#22240;&#20026;UART&#27599;&#27425;&#21482;&#21457;&#36865;8&#20301; 

if((rc = alt_dma_txchan_ioctl(txchan,ALT_DMA_SET_MODE_8 ,NULL))<0) 

{ printf("Failed to set mode 8\n"); 

exit(1); 

/* &#24320;&#22987;&#21457;&#36865; */ 

if ((rc = alt_dma_txchan_send(txchan, source, strlen(str), done, NULL)) < 0) 

{ printf ("Failed to post transmit request, reason = %i\n", rc); 

exit (1); 

/* &#31561;&#24453;&#21457;&#36865;&#32467;&#26463; */ 

while (!tx_done); 

printf ("Transfer to jtag!\n"); 

fprintf(fp_LCD,"Transfer to lcd! \n"); 

fprintf(fp_RS232,"Transfer to rs232 ! \n"); 

for(i=0;i<=strlen(str);i++) 

printf ("%s\n",(SDRAM_BASE+i));  

fprintf(fp_LCD,(SDRAM_BASE+i)); 

return 0; 

}
0 Kudos
11 Replies
Altera_Forum
Honored Contributor II
406 Views

Look at the end of thread dma transfer inside isr: problem

0 Kudos
Altera_Forum
Honored Contributor II
406 Views

thanks for your suggestion,

0 Kudos
Altera_Forum
Honored Contributor II
406 Views

Hi, 

 

Does it work by now? What did you change? 

 

 

--- Quote Start ---  

void* dest = (void*)IOADDR_ALTERA_AVALON_UART_TXDATA(RS232_BASE );  

--- Quote End ---  

Did you change it to void* dest = rs232_base+1 and it worked (which would confuse me a lot)?! 

 

Regards
0 Kudos
Altera_Forum
Honored Contributor II
406 Views

thanks for your suggestion 

work baddly as yet, How to explain (rs232_base+1) ,Means TXDATA's address? 

 

sdram can't receive valid data as yet.I'M confusing,work hard search solution
0 Kudos
Altera_Forum
Honored Contributor II
406 Views

Hi 

 

 

--- Quote Start ---  

How to explain (rs232_base+1) ,Means TXDATA's address? 

--- Quote End ---  

Micio82 described that it worked for him. At least partially. He used (rs232_base+1) for TXDATA-address. 

 

but in my code I am using: 

 

 

--- Quote Start ---  

IOADDR_ALTERA_AVALON_UART_TXDATA(RS232_BASE ) 

--- Quote End ---  

which works fine and I am thinking which should be the correct way to get the TXDATA-address. 

 

We (micio82 and me) thought it was a bit strange that (rs232_base+1) partially worked. Therefore was my question, did you make the same observation?
0 Kudos
Altera_Forum
Honored Contributor II
406 Views

good evenning! 

colud you give me program about DMA(from uart to SDRAM OR ONCHIP),i can't solve this trouble . 

regardly
0 Kudos
Altera_Forum
Honored Contributor II
406 Views

my email is xyguoking@163.com

0 Kudos
Altera_Forum
Honored Contributor II
406 Views

at laset ,change code as this ,work baddly as now 

 

 

//&#20174;RS232&#25509;&#25910;&#23383;&#31526;,&#20256;&#21040;SDRAM,&#22312;&#23558;&#25152;&#20256;&#36865;&#30340;&#20449;&#24687;&#65292;&#21453;&#39304;&#21040;JTAG&#21644;RS232&#65288;&#36890;&#36807;&#25991;&#20214;&#24418;&#24335;&#65289;&#65292;&#26816;&#26597;&#20004;&#32773;&#26159;&#21542;&#27491;&#30830;# include <stdio.h># include <stdlib.h># include "sys/alt_dma.h"# include "altera_avalon_uart_regs.h"# include "altera_avalon_dma_regs.h"# include "system.h"# include "alt_types.h"# include <string.h># define TRANSFER_LENGTH 1024 

static volatile int tx_done = 0; 

static char str[512]={"this is str data,well\n"}; 

 

//&#22238;&#35843;&#20989;&#25968; 

static void done (void* handle) 

tx_done++; 

 

int main() 

alt_u8 i;  

FILE *fp_LCD=0; 

FILE *fp_RS232=0; 

fp_LCD = fopen("/dev/lcd","w");  

fp_RS232 = fopen("/dev/rs232","w");  

 

int rc; 

alt_dma_rxchan rxchan; 

 

void* source = RS232_BASE+1;/* &#28304;&#22320;&#22336; */  

void* dest = (void*)(SDRAM_BASE+100);  

/* &#25171;&#24320;&#21457;&#36865;&#36890;&#36947; */ 

if ((rxchan = alt_dma_rxchan_open("/dev/dma")) == 0) 

{ printf ("successful to open transmit channel\n"); 

exit (1); 

/* &#35774;&#32622;&#21457;&#36865;&#22320;&#22336;&#22266;&#23450; */ 

if ((rc = alt_dma_rxchan_ioctl(rxchan, ALT_DMA_RX_ONLY_ON, source)) < 0) 

{ printf ("Failed to set ioctl, reason = %i\n", rc); 

exit (1); 

//&#35774;&#32622;&#27599;&#27425;&#25509;&#25910;&#19968;&#20010;&#23383;&#33410;&#65292;&#21363;8&#20301;&#65292;&#22240;&#20026;UART&#27599;&#27425;&#21482;&#21457;&#36865;8&#20301; 

if((rc = alt_dma_rxchan_ioctl(rxchan,ALT_DMA_SET_MODE_8 ,NULL))<0) 

{ printf("Failed to set mode 8\n"); 

exit(1); 

 

/* &#24320;&#22987;&#25509;&#25910; */ 

if ((rc = alt_dma_rxchan_prepare(rxchan, SDRAM_BASE+100, 32, done, NULL)) < 0) 

{ printf ("Failed to post transmit request, reason = %i\n", rc); 

exit (1); 

/* &#31561;&#24453;&#25509;&#25910;&#32467;&#26463; */ 

while (!tx_done); 

printf ("Transfer to jtag!\n"); 

fprintf(fp_LCD,"Transfer to lcd! \n"); 

fprintf(fp_RS232,"Transfer to rs232 ! \n"); 

//alt_dma_rxchan_close(rxchan); 

memcpy(str,SDRAM_BASE+100,32); // &#23558;SDRAM&#20869;&#23481;&#22797;&#21046;&#21040;ONCHIP str&#65292;&#24182;&#26174;&#31034;&#36755;&#20986;&#65292;&#20197;&#20415;&#26816;&#26597; 

for(i=0;i<=32;i++) 

printf ("%x\n",str);  

fprintf(fp_lcd,str); 

fprintf(fp_RS232,str[i]); 

//printf("%x\n",(SDRAM_BASE+100+i)); 

//printf("%x\n",SDRAM_BASE+100); 

alt_dma_rxchan_close(rxchan); 

return 0; 

}
0 Kudos
Altera_Forum
Honored Contributor II
406 Views

You can see my program in the Thread dma transfer inside isr: problem; but I use the UART register to implement the driver - (you are using the HAL).

0 Kudos
Altera_Forum
Honored Contributor II
406 Views

Hi micio82 

deep thanks. Did you write program about DMA ,send data from uart to SDRAM,(in my another code,sdram to uart ,it works well(didn't bypass cache),but from uart to sdram not work at all) 

 

I select cpu is CPU/F ,Must it bypass the cache ? to selsect none?
0 Kudos
Altera_Forum
Honored Contributor II
406 Views

Hi! 

In my project I use the CPU/f and I have a istruction and data cache. My program works only I use uncached memory: 

 

alt_u8 *buffer; // buffer of chars -> unsigned 8 bit 

buffer = alt_uncached_malloc(BUFF_SIZE * sizeof (alt_u8)); 

 

 

Regards
0 Kudos
Reply