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.

Using a uart without HAL

Altera_Forum
Honored Contributor II
1,370 Views

Hi, we're just starting out with Nios II. We have a lot of experience with embedded processors, particularly the NXP ARM7 and the Atmel AVR. 

 

We are trying to write code to receive the serial lighting protocol DMX512 on a UART. This is basically a break followed by 512 bytes of data, at 250Kbaud. The device only has to receive a few bytes of the data relevant to itself, e.g. bytes 100-103. We have C code to do this on other embedded processors which accesses the hardware registers directly. 

 

However on the Nios II, settings I make directly to the UART registers are overwritten, I presume by HAL routines. For example the UART interrupt enable flags are constantly overwritten to a different value from the one I want. 

 

Can anyone advise me how to disable the HAL routines so I can access the UART directly? 

 

Tim Mitchell
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
644 Views

Sorry to reply to my own post, I've just found out from another programmer that the HAL code does not take effect unless you use fopen() or other C stream commands. So my problem must be elsewhere. 

 

I am slightly confused by the section in the "Embedded Peripherals" documentation which appears to suggest that you should not access the UART registers directly "if the HAL driver is active for the device".
0 Kudos
Altera_Forum
Honored Contributor II
644 Views

Hi, 

 

The HAL functions works with UART register, so if in one side you use them to read or write, and on another side you access directly the UART register, this may result in conflict, particularly with interrupts. 

 

To access directly the registers of UART, you don't have to disable anything about HAL, just use the macro defined in the file altera_avalon_uart_regs.h. (cf Nios II Software Developer’s Handbook, Chapter 7, part Accessing Hardware, for the use of IORD and IOWR macros). 

 

So, to write or read data, you simply have to do the following : 

IOWR_ALTERA_AVALON_UART_TXDATA(UART_BASE, data); 

data = IORD_ALTERA_AVALON_UART_RXDATA(UART_BASE); 

 

Jérôme
0 Kudos
Reply