Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
20 years ago

rubbish out of uart in multiprocessor design

I've got a design with two nios2 cpus which have a uart component and the jtag uart on cpu1. At present I'm just sending some data from cpu2 to cpu1 via shared memory and a mutex. When cpu1 gets the data it writes it to stdout. When I hook up the jtag uart to stdout by checking a box in system library, everything works. However, if instead I hook up the uart to stdout, garbage comes out of the serial port. I've tried moving the uart component address in SOPC Builder, explicitly opening /dev/uart1 and writing to the file instead of using stdout; nothing works, I still get garbage out of the uart. Before making my two-cpu design I had studied the multiprocessor tutorial and got it working. So, I went back to the multiprocessor tutorial and hooked up the uart to stdin/stdout/stderr in place of the jtag uart; this also results in rubbish out of the uart. However, if I hook up the uart as stdin/stdout on a design with a single nios2 cpu, the uart works properly.

Can anyone give me some guidance on what I'm doing wrong?

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I fixed the problem. In SOPC Builder I set up the baud rate for the uart component as 9600 baud. I had a second PC connected to the uart in order to monitor the garbage from the uart. Bizarrely, upon configuring the program in the monitor PC to run at 4800 baud, the output from the uart became sensible! Presumably this means that the uart's divisor register is being set wrongly; perhaps in SOPC Builder?

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I used this to set the baud rate

    # define M_Set_UART_Baudrate(X)

    IOWR_ALTERA_AVALON_UART_DIVISOR(m_ui_UARTBaseAdress, X)# define M_Get_UART_Baudrate()

    IORD_ALTERA_AVALON_UART_DIVISOR(m_ui_UARTBaseAdress)

    ////////////////////////////////////////////////////////////////////////////////

    bool UARTClass::SetBaudRate // true - success; false - failure

    (

    unsigned int para_ui_Baudrate

    )

    {

    alt_u16 proc_u16_Baudrate = (alt_u16)((ALT_CPU_FREQ / para_ui_Baudrate) + 0.5);

    M_Set_UART_Baudrate(proc_u16_Baudrate);

    if(proc_u16_Baudrate == M_Get_UART_Baudrate())

    {

    return true;

    }

    else

    {

    return false;

    }

    }

    ////////////////////////////////////////////////////////////////////////////////

    unsigned int UARTClass::GetBaudRate

    (

    void

    )

    {

    return IORD_ALTERA_AVALON_UART_DIVISOR(m_ui_UARTBaseAdress);

    }