Forum Discussion

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

writing to a uart

I've got a uart in my SOPC builder system called uart_0 that I'm trying to write to using the serial example, but slightly modified. However the cyg_io_lookup function does not find this uart. I've no idea where to go from here, can someone give me a clue how to access this uart.

below is the code listing I am using, (simple_prog function only, rest is the same)

static void simple_prog(CYG_ADDRESS data)
{
    cyg_io_handle_t handle;
    Cyg_ErrNo err;
    const char test_string = "serial example is working correctly!\n";
    cyg_uint32 len = strlen(test_string);
    printf("Starting serial example\n");
   // err = cyg_io_lookup( "/dev/haldiag", &handle );
  err = cyg_io_lookup( "/dev/uart_0", &handle );
  printf("error = %d \n",err);
  
    if (ENOERR == err) {
   //     printf("Found /dev/haldiag. Writing string....\n");
          printf("Found /dev/uart_0. Writing string....\n");
        err = cyg_io_write( handle, test_string, &len );
    }
    else {
      printf("Device not detected! \n");    
    }
        
    if (ENOERR == err) {
        printf("I think I wrote the string. Did you see it?\n");
    }
    
    printf("Serial example finished\n");
}

1 Reply

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

    If you are using the 5.0 release, then you will need to enable "hardware serial device drivers" to access the full UART serial driver. You'll find this option in the "Serial device drivers" folder in configtool.

    Alternatively you can just use the simple console driver, which you can open as "/dev/haldiag". This assumes that you've set the diagnostic console device to be the UART. This is set in the "Nios2 architecture" package, which is beneath "eCos HAL".