We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

Showing results for 
Search instead for 
Did you mean: 
Visitor xavier0001
Registered: ‎11-04-2016

UartLite with interupt not triggering properly for RX in Zybo board

Hi everyone,


Has anyone managed to use interrupts with uartlite in baremetal code? When using it via polling data can be received and sent just fine, but when uartlite interrupt is enabled, the RX interrupt does not always seem to trigger when data is present in the RX FIFO.


Usually the uartlite ends up in a situation where the RX interrupt is not triggered and there's one or more bytes in the RX FIFO. My understanding is that an interrupt should be triggered at anytime the RX FIFO isn't empty, but this only seems to happen sometimes.


The hardware used is a zybo board and is observed using version 2016.3 of xsdk. According to Vivado the Uartlite block is version 2.0 and in the BSP the uartlite libraries are in a folder called uartps_v3_2. Find below the block design used.



And below is the test code currently being used:


#include <stdio.h>
#include "xil_types.h"
#include "platform.h"
#include "xil_printf.h"
#include "xuartlite.h"
#include "xuartlite_l.h"
#include "xscugic.h"

static volatile u32* const STATUS_REG = (volatile u32*)(XPAR_UARTLITE_0_BASEADDR + XUL_STATUS_REG_OFFSET);
static volatile u32* const CTRL_REG = (volatile u32*)(XPAR_UARTLITE_0_BASEADDR + XUL_CONTROL_REG_OFFSET);
static volatile u32* const RX_REG = (volatile u32*)(XPAR_UARTLITE_0_BASEADDR + XUL_RX_FIFO_OFFSET);
static volatile u32* const TX_REG = (volatile u32*)(XPAR_UARTLITE_0_BASEADDR + XUL_TX_FIFO_OFFSET);

static volatile u8 intHappened = FALSE;
static volatile u8 bytes_received = 0;

static void a_int_handler(void *data)
	intHappened = TRUE;

// Count the number of bytes in FIFO *RX_REG; bytes_received++; } } int main() { u32 step; u32 reg; u8 Trigger = 0x3u; init_platform(); // Clear FIFO, enable interrupt *CTRL_REG = XUL_CR_FIFO_RX_RESET | XUL_CR_FIFO_TX_RESET | XUL_CR_ENABLE_INTR; /* Setup Interrupt */ Xil_ExceptionInit(); XScuGic_DeviceInitialize(XPAR_SCUGIC_SINGLE_DEVICE_ID); Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_IRQ_INT, XScuGic_DeviceInterruptHandler, (void *)XPAR_SCUGIC_SINGLE_DEVICE_ID); /* Now enable interrupts */ Xil_ExceptionEnableMask(XIL_EXCEPTION_IRQ); // Set interrupt trigger reg = XScuGic_ReadReg(XPAR_SCUGIC_0_DIST_BASEADDR, XSCUGIC_INT_CFG_OFFSET_CALC(INT_ID)); reg &= ~(XSCUGIC_INT_CFG_MASK << ((INT_ID%16U)*2U)); reg |= (u32)Trigger << ((INT_ID%16U)*2U); XScuGic_WriteReg(XPAR_SCUGIC_0_DIST_BASEADDR, XSCUGIC_INT_CFG_OFFSET_CALC(INT_ID), reg); // Register UART Interrupt Handler in GIC XScuGic_RegisterHandler(XPAR_SCUGIC_0_CPU_BASEADDR, INT_ID, a_int_handler, NULL); // Enable UART Interrupt in GIC XScuGic_EnableIntr(XPAR_SCUGIC_0_DIST_BASEADDR, INT_ID); xil_printf("\r\nLoop\r\n"); for (;;) { // Infinite xil_printf("\r\n__"); // A loooong delay, sleep crashes for some reason step = 0xFFFFFF * 5u; while(step-- >0); // Display number of bytes read if interrupt happened if(intHappened == TRUE) { xil_printf("\r\nRead %d\r\n", bytes_received); bytes_received = 0; intHappened = FALSE; } // If there's still data in the FIFO after this much delay, clear it if((*STATUS_REG & XUL_SR_RX_FIFO_VALID_DATA) != 0){ while((*STATUS_REG & XUL_SR_RX_FIFO_VALID_DATA) != 0){ *RX_REG; } xil_printf("\r\n!"); } } return 0; }

Thanks in advance.

Tags (3)
0 Kudos
2 Replies
Registered: ‎07-31-2012

Re: UartLite with interupt not triggering properly for RX in Zybo board



Did you try using the available example of interrupt mode in SDK installation?





Don’t forget to reply, kudo, and accept as solution.
0 Kudos
Visitor xavier0001
Registered: ‎11-04-2016

Re: UartLite with interupt not triggering properly for RX in Zybo board



Some issues on compilation are there with xintc.h with that example. Do note that the uartlite interrupt is connected directly to the PS as seen in the figure, so that example might need significant modification.


I ended up slightly modifying the other example, xuartlite_intr_tapp_example.c instead to display a tiny message message using xil_printf upon receiving data in "UartLiteRecvHandler" instead. The message doesn't always appear (Data is manually sent into the zybo), even after removing the "UartLiteDisableIntrSystem" call in the last line of "UartLiteDisableIntrSystem" and replacing it with an infinite loop. Adding a call to "XUartLite_ResetFifos"  inside "UartLiteRecvHandler" in that example didn't help either.




0 Kudos