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++
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
12748 Discussions

UART use with Small newlib C Library

Altera_Forum
Honored Contributor II
1,449 Views

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
0 Kudos
6 Replies
Altera_Forum
Honored Contributor II
740 Views

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

 

Boris
0 Kudos
Altera_Forum
Honored Contributor II
740 Views

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.

0 Kudos
Altera_Forum
Honored Contributor II
740 Views

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.
0 Kudos
Altera_Forum
Honored Contributor II
740 Views

Thank you that helped me to understand things better.  

 

/Boris
0 Kudos
Altera_Forum
Honored Contributor II
740 Views

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

As a matter of interest, where are functions such as these documented?
0 Kudos
Altera_Forum
Honored Contributor II
740 Views

I think you should find them in the software developper's handbook, in the hal section (http://www.altera.com/literature/hb/nios2/n2sw_nii5v2_02.pdf).

0 Kudos
Reply