Forum Discussion

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

UART use with Small newlib C Library

I want to add a UART to a minimal resources system.

Stdin/out are used by JTAG Uart.

Is there any way to utilise the standard UART using HAL if fopen and similar are unavailable?

I'm quite happy to access the registers directly but attempts to read the status register location always return a value of 0. Do I have to do something to allow direct access to the registers?

Many thanks

6 Replies

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

    If you have data cache on your NIOS you will have to declare the variables as volatile unless you use IORD_..........

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

    volatile isn't enough. You need to use the alt_remap_uncached() function to directly access a register if you have cache. The IORD* macros are easier to use for that purpose.

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

    Making variables 'volatile' doesn't cause the data cache to be bypassed.

    It is probably required [1] to ensure that all the memory transfers requested by the C source actually happen, and in the correct order.

    Passing -mno-cache-volatile to the compiler will cause it to use ldio/stio instructions for volatile data. But it would be more useful if this were a separate attribute.

    [1] judicious use of memory barriers [2] can have the desired effect.

    [2] eg asm volatile("\n":::"memory") tells gcc that any of memory might have changed - so it must not have memory cached in registers (and v.v.) across the statement.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Many thanks for the ideas - using IORD and IOWR works fine.

    As a matter of interest, where are functions such as these documented?