Segger Real time transfer¶
Segger RTT is a method to use the Segger J-Link to transfer a stream of data over a debugger session. It makes it possible to use printf and similar to output data without using any extra connection, except SWD
More information about Segger RTT is available from Segger
Enable RTT output¶
To enable RTT, add MIRA_IODEF_RTT(0)
to the MIRA_IODEFS()
table:
In mira_setup()
initialize RTT:
Blocking mode¶
RTT is non-blocking by default. Data is dropped if the buffer is full. This may occur if no client is reading, or if the bandwidth is too low for the amount of data.
In some cases, avoiding the loss of data is more important than preserving system performance. Blocking mode is available for that purpose.
For more information, see mira_rtt_set_blocking()
Data input¶
It is possible to read data from RTT. To read from RTT, use active polling.
To read data, start a process that polls the interface:
PROCESS_THREAD(rtt_reader, ev, data) {
uint8_t buffer[16];
int len;
PROCESS_BEGIN();
PROCESS_PAUSE();
for (;;) {
/* Yield to give other processes access to the CPU */
PROCESS_PAUSE();
do {
/*
* Continously poll while data is available, to clear te buffer as
* fast as possible
*/
len = mira_rtt_read(-1, 0, buffer, sizeof(buffer));
if (len > 0) {
/*
* Handle buffer here...
*/
}
} while (len > 0);
}
PROCESS_END()
}
Defines¶
MIRA_IODEF_RTT¶
MIRA_IODEF handler for RTT.
To use RTT as output for mira iodefs, use MIRA_IODEF_RTT(0) as operation in MIRA_IODEFS().
Functions¶
mira_rtt_init¶
Initialize RTT interface.
Return value¶
status of operation
mira_rtt_set_blocking¶
Set blocking mode.
In blocking mode, mira_rtt_write() will block until enough space is available in output buffer for output.
Parameters¶
Name | Description |
---|---|
buf_idx | Index of buffer. Only buf_idx=0 is supported. |
blocking | 0 for non-blocking, non-zero for blocking. |
Return value¶
Status of operation.
mira_rtt_read¶
Read data from RTT.
Writes raw data to output buffer, given buf_idx.
Parameters¶
Name | Description |
---|---|
fd | Unused. Available to fit MIRA_IODEF. |
buf_idx | Index of buffer. Only buf_idx=0 is supported. |
ptr | Pointer to where to store input. |
len | Length of input buffer. |
Return value¶
Length of data read and written to ptr. Negative on error.
mira_rtt_write¶
Write data to RTT.
This method is intended to be used as a MIRA_IODEF output handler.
Writes raw data to output buffer, given buf_idx.
Parameters¶
Name | Description |
---|---|
fd | Unused. Available to fit MIRA_IODEF. |
buf_idx | Index of buffer. Only buf_idx=0 is supported. |
ptr | Pointer to where output is stored. |
len | Length of output buffer. |
Return value¶
Length of data written. Negative on error.