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

Fix for Baud Rate cannot be changed by Software

Altera_Forum
Honored Contributor II
991 Views

G'day, 

 

Just ran into a problem setting the baud rate by software under Nios2 v1.01. My apologies if this has already been posted before. Setup as follows: 

 

Optional Hardware Feature: uart divisor register 

Optional Compiler Flag: -DALTERA_AVALON_UART_USE_IOCTL 

 

#include "sys/termios.h"# include "sys/ioctl.h" struct termios uart_settings; // default baud rate set to 115200 ioctl(fd, TIOCMGET, &uart_settings); uart_settings.c_ispeed = 57600; uart_settings.c_ospeed = 57600; // Must set both c_ispeed & c_ospeed otherwise TIOCMGET fails. ioctl(fd, TIOCMSET, &uart_settings); 

 

The above code doesn't successfully change the baud rate. The problem is in the "altera_avalon_uart.c" function alt_avalon_uart_tiocmset(). Instead of calculating the new divisor value based on the new baud rate it uses the old baud rate. Also changed the divisor calc in accordance with the Nios 2 Processor Reference Manual Section 10-5, which matches what the SOPC buider generates. 

 

Change line... 

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

 

...to... 

IOWR_ALTERA_AVALON_UART_DIVISOR(dev->base, ((dev->freq/dev->termios.c_ispeed) + 0.5)); 

 

ciao 

 

-- 

Bob
0 Kudos
0 Replies
Reply