Forum Discussion
Altera_Forum
Honored Contributor
16 years agoUART 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 thanks6 Replies
- Altera_Forum
Honored 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
Honored 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
Honored 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
Honored Contributor
Thank you that helped me to understand things better.
/Boris - Altera_Forum
Honored Contributor
Many thanks for the ideas - using IORD and IOWR works fine.
As a matter of interest, where are functions such as these documented? - Altera_Forum
Honored Contributor
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).