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++
12600 Discussions

about programable UART Baudrate

Altera_Forum
Honored Contributor II
1,073 Views

the readme.txt of the board_diag show that: 

 

* - UART test  

* Tests UART functionality for the UART defined as STDOUT. 

* * Currently, only tested on the JTAG UART device. 

 

the component UART in the SOPC Builder has a option "Baud rate can be change by software". 

Are there any API that can control the divisor register and set baud rate with software? 

 

thank u!
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
293 Views

ffone13, 

 

There is an ioctl call to set the baud rate etc for the UART. If you look in the manual for the UART n2cpu_nii51010.pdf and look under the software programming model there is a section in here on ioctl which is where you should start.
0 Kudos
Altera_Forum
Honored Contributor II
293 Views

hello rugbybloke, 

 

could you look at the following code that change the baudrate? 

in the sopc builder i have set the option that divisor can be change. 

and the result is when execute: 

if (fd->dev->ioctl) 

rc = fd->dev->ioctl(fd, req, arg); 

it stop! 

 

/********************************************************/ 

int main (void) 

{  

char* msg = "hello world"; 

FILE* fp; 

 

struct termios* term; 

 

fp = fopen ("/dev/uart1", "w"); 

 

if (fp) 

term->c_ispeed=B57600; 

ioctl(fp, TIOCMSET, term); 

fprintf(fp, "%s",msg); 

fclose (fp); 

return 0; 

 

/********************************************************/ 

 

could you show me how to do? 

thank you!
0 Kudos
Altera_Forum
Honored Contributor II
293 Views

ffone13, 

 

My guess is that you don't have the ioctl code included, the comment at the top of the driver gives you some clues 

 

/* 

* To reduce the code footprint of this driver, the ioctl() function is not 

* included by default. If you wish to use the ioctl features provided  

* below, you can do so by adding the option : -DALTERA_AVALON_UART_USE_IOCTL 

* to CPPFLAGS in the Makefile (or through the Eclipse IDE). 

*/ 

 

If this does not solve the problem then either step into the ioctl call to find the offending line, or set a breakpoint in the ioctl code inside the UART driver to find where the problem is.
0 Kudos
Altera_Forum
Honored Contributor II
293 Views

Yes, you are right.I have finished it. but i find a bug that it seems to be in "static int alt_avalon_uart_tiocmset (alt_avalon_uart_dev* dev, struct termios* term) " function 

of the altera_avalon_uart.c . 

 

IOWR_ALTERA_AVALON_UART_DIVISOR(dev->base, ((dev->freq/speed) - 1)); the speed should be  

dev->termios.c_ispeed, i think. because firstly speed = dev->termios.c_ispeed; is the original value. 

 

 

thank you for reply!
0 Kudos
Altera_Forum
Honored Contributor II
293 Views

ffone, 

 

Looks like you're right thanks for the tip
0 Kudos
Reply