uart-console-log-9.ino

Efinix Sapphire RV64 : Configurable 64-bit RISC-V SoC for FPGAs · File : uart-console-log-9.ino · Language : C · Use case : Implémenter une redirection printf vers l'UART pour le débogage console.

Configures UART0 for serial debug output, enabling the use of standard printf functions.

Connect a USB-UART converter to the TX/RX pins of UART0. The code overrides the low-level _putchar function to direct output to the UART hardware. Ensure the system clock frequency matches the baud rate. Use a serial terminal at 115200 baud.

uart-console-log-9.ino

#include <stdio.h>
#include <unistd.h>
#include "xhal_uart.h"

#define UART_INSTANCE XHAL_UART0

// Redirection de stdout/stderr vers UART0
void _putchar(char c) {
    xhal_uart_write_char(UART_INSTANCE, c);
}

// Fonction d'initialisation requise par certaines libc
void _exit(int status) {
    while(1);
}

int main(void) {
    xhal_uart_init(UART_INSTANCE, 115200, 8, XHAL_UART_PARITY_NONE, 1);
    
    printf("Sapphire RV64 Booting...\n");
    printf("CPU: VexiiRiscv\n");
    
    int counter = 0;
    while(1) {
        printf("Heartbeat: %d\n", counter++);
        // Simple delay
        for(volatile int i=0; i<1000000; i++);
    }
}

← Back to the board