--
You received this message because you are subscribed to the Google Groups "RISC-V HW Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hw-dev+un...@groups.riscv.org.
To post to this group, send email to hw-...@groups.riscv.org.
Visit this group at https://groups.google.com/a/groups.riscv.org/group/hw-dev/.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/hw-dev/d4aef2fe-e5ac-4b22-aa12-4d1f300b005f%40groups.riscv.org.
No need to modify the compiler, just write a routine similar to
this:
#include <string.h>
#include <stdarg.h>
int printf (const char *fmt, ...)
{
char buffer[99], *sptr = buffer;
va_list va;
int rslt;
va_start(va, fmt);
rslt = vsnprintf(buffer, sizeof(buffer), fmt, va);
va_end(va);
while (*sptr) uart_send(*sptr++);
return rslt;
}
You will need to write the routine uart_send() which will be
hardware dependent, and just needs to wait for the UART output to
drain, before adding the next character.
That will depend on your hardware. If it is 16550 compliant you could use something like this:
// RBR: Receiver buffer register [Read, LCR[7] == 0]
#define UART_RBR 0x0u
// THR: Transmitter Holding register [Write, LCR[7] == 0]
#define UART_THR 0x0u
// IER: Interrupt enable register [Read/Write, LCR[7] == 0]
#define UART_IER 0x1u
// IIR: Interrupt identification register [Read]
#define UART_IIR 0x2u
// FCR: FIFO control register [Write, Read only when LCR[7] == 1]
#define UART_FCR 0x2u
// LCR: Line control register [Read/Write]
#define UART_LCR 0x3u
// MCR: Modem control register [Read/Write]
#define UART_MCR 0x4u
// LSR: Line status register [Read/Write]
#define UART_LSR 0x5u
// MSR: Modem status register [Read/Write]
#define UART_MSR 0x6u
// SCR: Scratch register [Read/Write]
#define UART_SCR 0x7u
// DLL: Divisor latch (least significant byte) register
[Read/Write, LCR[7] == 1]
#define UART_DLL 0x0u
// DLM: Divisor latch (most significant byte) register
[Read/Write, LCR[7] == 1]
#define UART_DLM 0x1u
volatile uint32_t *uart_base_ptr = (uint32_t *)(UART_BASE);
void uart_init() {
// set 0x0080 to UART.LCR to enable DLL and DLM write
// configure baud rate
*(uart_base_ptr + UART_LCR) = 0x0080;
// System clock 25 MHz, 115200 baud rate
// divisor = clk_freq / (16 * Baud)
*(uart_base_ptr + UART_DLL) = 25*1000*1000u / (16u * 115200u) %
0x100u;
*(uart_base_ptr + UART_DLM) = 25*1000*1000u / (16u * 115200u)
>> 8;
// 8-bit data, 1-bit odd parity
*(uart_base_ptr + UART_LCR) = 0x000Bu;
}
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/hw-dev/b88bbe97-8c8b-4fc8-91ec-605763c8ac6e%40groups.riscv.org.
> email to hw-dev+unsubscribe@groups.riscv.org.
> To post to this group, send email to hw-...@groups.riscv.org.
> Visit this group at
> https://groups.google.com/a/groups.riscv.org/group/hw-dev/.
> To view this discussion on the web visit
> https://groups.google.com/a/groups.riscv.org/d/msgid/hw-dev/811718ad-f16c-42bf-84fe-d718d22cfa72%40groups.riscv.org.
--
You received this message because you are subscribed to the Google Groups "RISC-V HW Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hw-dev+unsubscribe@groups.riscv.org.
To post to this group, send email to hw-...@groups.riscv.org.
Visit this group at https://groups.google.com/a/groups.riscv.org/group/hw-dev/.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/hw-dev/CALo5CZzZh56_nMLn8KgEZBQn%2B9V47R-9xuFpjSrPRYFo5a%2Budw%40mail.gmail.com.
> email to hw-dev+un...@groups.riscv.org.
> To post to this group, send email to hw-...@groups.riscv.org.
> Visit this group at
> https://groups.google.com/a/groups.riscv.org/group/hw-dev/.
> To view this discussion on the web visit
> https://groups.google.com/a/groups.riscv.org/d/msgid/hw-dev/811718ad-f16c-42bf-84fe-d718d22cfa72%40groups.riscv.org.
--
You received this message because you are subscribed to the Google Groups "RISC-V HW Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hw-dev+un...@groups.riscv.org.
To post to this group, send email to hw-...@groups.riscv.org.
Visit this group at https://groups.google.com/a/groups.riscv.org/group/hw-dev/.