deejay2221
deejay2221

Reputation: 11

How to print inside a Xilinx Artix-7 Microblaze exception handler

I am working on a baremetal Microblaze and I want to print data when it crashes. I setup the exception handler and I know it's working since the breakpoint triggers inside this handler. However, I cannot push anything on the console UART. I make sure to use the blocking UART (no interrupt).

I tried to use xil_printf and XUartNs550_SendByte without success. Note that both techniques work when I use them outside the exception handler.

#define XIL_EXCEPTION_ID_FIRST                0U
#define XIL_EXCEPTION_ID_FSL                  0U
#define XIL_EXCEPTION_ID_UNALIGNED_ACCESS     1U
#define XIL_EXCEPTION_ID_ILLEGAL_OPCODE       2U
#define XIL_EXCEPTION_ID_M_AXI_I_EXCEPTION    3U
#define XIL_EXCEPTION_ID_IPLB_EXCEPTION       3U
#define XIL_EXCEPTION_ID_M_AXI_D_EXCEPTION    4U
#define XIL_EXCEPTION_ID_DPLB_EXCEPTION       4U
#define XIL_EXCEPTION_ID_DIV_BY_ZERO          5U
#define XIL_EXCEPTION_ID_FPU                  6U
#define XIL_EXCEPTION_ID_STACK_VIOLATION      7U
#define XIL_EXCEPTION_ID_MMU                  7U
#define XIL_EXCEPTION_ID_LAST             XIL_EXCEPTION_ID_MMU

static const char * gs_exception_str = "EXCEPTION ";
#define EXCEPTION_STR_LEN   10

static void exception_handler(void * p_pData)
{
    volatile unsigned int errorType = p_pData;

    XIntc_Stop(gs_intc_instance0_p); // With or without, makes no difference

    /*** Technique 1 ***/
    for (int i = 0; i < EXCEPTION_STR_LEN; i++)
    {
        XUartNs550_SendByte(XPAR_UART_AXI_UART_CSL_BASEADDR, gs_exception_str[i]);
    }
    XUartNs550_SendByte(XPAR_UART_AXI_UART_CSL_BASEADDR, '0' + errorType);
    fflush(stdout); // With or without, makes no difference

    /*** Technique 2 ***/
    xil_printf(gs_exception_str);
    xil_printf("%d", errorType);
    fflush(stdout); // With or without, makes no difference

    while(1); // A breakpoint here triggers
}

void init()
{
    Xil_ExceptionInit();
    Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler)XIntc_InterruptHandler, gs_intc_instance0_p);
    for (unsigned int i = 0; i <= XIL_EXCEPTION_ID_LAST; i++)
    {
        Xil_ExceptionRegisterHandler(i, (Xil_ExceptionHandler)exception_handler, i);
    }
    Xil_ExceptionEnable();
}

Thank you

Upvotes: 0

Views: 39

Answers (0)

Related Questions