PebbleOS v4.47.0-1161-g94e3d98da
Loading...
Searching...
No Matches
SEGGER RTT

Channels in RAM that a debug probe reads and writes over SWD while the target runs. More...

Functions

void pbl_rtt_init (void)
 Set the control block up, if not done yet.
 
size_t pbl_rtt_write (unsigned int ch, const void *data, size_t len)
 Write to an up channel.
 
size_t pbl_rtt_read (unsigned int ch, void *data, size_t len)
 Read from a down channel.
 
bool pbl_rtt_flush (unsigned int ch, uint32_t timeout_us)
 Wait for a probe to read what was written to an up channel.
 

Detailed Description

Channels in RAM that a debug probe reads and writes over SWD while the target runs.

The control block is the global _SEGGER_RTT, which debug probes find by that symbol in the ELF. It holds CONFIG_RTT_NUM_UP channels from the target to the probe and CONFIG_RTT_NUM_DOWN back, each with a buffer of CONFIG_RTT_UP_SIZE or CONFIG_RTT_DOWN_SIZE bytes. Channel 0 is the terminal by convention.

Nothing waits for a probe: a write that does not fit is dropped whole, as RTT's NO_BLOCK_SKIP mode does. Only pbl_rtt_flush() waits, and only for a probe seen reading the channel. The functions take the kernel lock, so they also run before the kernel and from a fault handler, but not from a zero-latency interrupt.

The probe reads the RAM behind any data cache, so with one the control block and the buffers are in the kernel's non-cacheable section (PBL_NOCACHE).

(void)pbl_rtt_write(0, "hello\n", 6);
uint8_t c;
if (pbl_rtt_read(0, &c, 1) == 1) {
// a byte from the probe
}
size_t pbl_rtt_write(unsigned int ch, const void *data, size_t len)
Write to an up channel.
size_t pbl_rtt_read(unsigned int ch, void *data, size_t len)
Read from a down channel.

Function Documentation

◆ pbl_rtt_flush()

bool pbl_rtt_flush ( unsigned int  ch,
uint32_t  timeout_us 
)

Wait for a probe to read what was written to an up channel.

Returns at once unless a probe was seen reading the channel. A probe that does not catch up within timeout_us counts as gone until it reads again, so later flushes do not wait.

Parameters
chUp channel.
timeout_usLongest wait, in microseconds.
Returns
true when the channel is empty.

◆ pbl_rtt_init()

void pbl_rtt_init ( void  )

Set the control block up, if not done yet.

The other functions do it too; this lets a probe find the block before anything is written.

◆ pbl_rtt_read()

size_t pbl_rtt_read ( unsigned int  ch,
void *  data,
size_t  len 
)

Read from a down channel.

Parameters
chDown channel.
[out]dataBytes read.
lenMost bytes to read.
Returns
Number of bytes read, 0 when there are none or ch does not exist.

◆ pbl_rtt_write()

size_t pbl_rtt_write ( unsigned int  ch,
const void *  data,
size_t  len 
)

Write to an up channel.

Parameters
chUp channel.
dataBytes to write.
lenNumber of bytes.
Returns
len, or 0 when they do not all fit, or ch does not exist, and nothing is written.