Forum Discussion

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

HAL&Uart example ?

Hi all

I cant find example for uart with HAL http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/sad.gif

I have two RS232 uarts (uart232,uart0)

1&#39;st i connect to stdin stdout and use it for debuging (uart232)

2&#39;nd i try to make workable (uart0)

My goal is :

create interrupt for uart0 which execute when uart0 recive data and in interrupt function i want transsmit received data from uart0 to uart232

data->uart0->uart232

I can&#39;t understand why that code hang&#39;s

void isr_uart0(void* context, alt_u32 id) // uart0 interrupt handler

{

alt_u32 status;

// status = IORD_ALTERA_AVALON_UART_STATUS(base);

printf("%s",IORD_ALTERA_AVALON_UART_RXDATA(UART0_BASE));//read data from uart0 and write to uart232

}

void ALEX_UART_TRY() //uart routines (initialization , irq register )

{

void *puart0 = (void*) UART0_BASE; // set pointer to uart0

alt_u32 divisor = (ALT_CPU_FREQ/115200)-1; // calculate divisor

IOWR_ALTERA_AVALON_UART_DIVISOR(UART0_BASE, divisor); // assign bbrate

IOWR_ALTERA_AVALON_UART_CONTROL(UART0_BASE, // enable interrupt

ALTERA_AVALON_UART_CONTROL_RRDY_MSK // Enable interrupt for a read ready

);

alt_irq_register(UART0_IRQ, puart0, isr_uart0); //register irq (nios2 hangs after that )

char* msg = "hello world"; // test uart0 by sending "Hello wold" (it work fine )

FILE* fp;

fp = fopen (UART0_NAME, "w");

if (fp)

{

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

fclose(fp);

}

}

void main()

{

ALEX_UART_TRY();

}

2 Replies

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

    I&#39;m not sure what you&#39;re trying to do here, but it looks more complex than I&#39;d expect.

    You could just open /dev/uart232 and read from it, writing to /dev/uart1 when there is data available.

    But if you want to do this from interrupts then you need to stop the HAL from attaching its drivers to the UARTS you are using.

    I suggest you stop at alt_main() and step through that function and through alt_sys_init.c to see what&#39;s going on. There&#39;s a tickbox in the launch configuration to make it stop at alt_main.

    To replace the HAL&#39;s drivers you should copy the appropriate files from the altera_avalon_uart directory into your system project and edit them there. The build system will use your copies instead of the shipped ones and you can edit as much as you want.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    May be, you should think about the printf-statement in your isr. Is it possible that this blocks the system? Take a look at "NIOS II Software Developmer&#39;s Handbook" page 6-7 / 6-8