Skip to main content

uart-rx-ringbuf

Interrupt-driven UART RX with a caller-supplied byte-granular ring buffer. Demonstrates the alp_uart_rx_ringbuf_* pattern for when the consumer can't keep up with the line rate.

Source: examples/uart-rx-ringbuf/.

board.yaml

som:
sku: E1M-AEN701

preset: e1m-evk

cores:
m55_hp:
app: ./src
peripherals: [uart]

diagnostics:
log_level: info

Enable the ring-buffer path with CONFIG_ALP_SDK_UART_RX_RINGBUF=y in prj.conf or as a CMake flag.

Source (abbreviated)

#include <alp/peripheral.h>
#include <alp/e1m_pinout.h>

static uint8_t rx_ring_storage[256];

int main(void) {
alp_uart_t *uart = alp_uart_open(&(alp_uart_config_t){
.port_id = ALP_E1M_UART0,
.baudrate = 115200u,
.data_bits = 8,
.stop_bits = 1,
});
if (uart == NULL) return -1;

/* attach() returns a handle; the backing store must outlive it. */
alp_uart_rx_ringbuf_t *rb =
alp_uart_rx_ringbuf_attach(uart, rx_ring_storage, sizeof(rx_ring_storage));
if (rb == NULL) return -1;

uint8_t buf[64];
while (1) {
size_t got = 0;
if (alp_uart_rx_ringbuf_pop(rb, buf, sizeof(buf), &got) == ALP_OK && got > 0) {
alp_uart_write(uart, buf, got);
} else {
k_msleep(10);
}
}
}

See also

Questions about this page? Discuss in Community Forum