Skip to content

Commit 3ac4405

Browse files
committed
modules: segger: remove mutex locking
Remove mutex locking in favour of the standard IRQ locking mechanism. The primary problem with the mutex implementation is that mutex locking is forbidden in ISR's. This means that any logging from an interrupt context (e.g. LOG_PANIC in an exception handler), will itself trigger another assertion due its attempt to use a mutex. Furthermore, mutexes are a relatively heavyweight locking scheme, which doesn't necessarily make sense in the context of extremely short locking periods that would be expected from RTT. This change aligns Zephyr with the default RTT locking scheme, which uses interrupt masking to perform access control. Resolves #79403. Signed-off-by: Jordan Yates <[email protected]>
1 parent 9f73988 commit 3ac4405

File tree

4 files changed

+3
-48
lines changed

4 files changed

+3
-48
lines changed

drivers/serial/uart_rtt.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
#define DT_DRV_COMPAT segger_rtt_uart
1212

13-
extern struct k_mutex rtt_term_mutex;
14-
1513
struct uart_rtt_config {
1614
void *up_buffer;
1715
size_t up_size;
@@ -100,21 +98,8 @@ static int uart_rtt_tx(const struct device *dev,
10098

10199
ARG_UNUSED(timeout);
102100

103-
/* RTT mutex cannot be claimed in ISRs */
104-
if (k_is_in_isr()) {
105-
return -ENOTSUP;
106-
}
107-
108-
/* Claim the RTT lock */
109-
if (k_mutex_lock(&rtt_term_mutex, K_NO_WAIT) != 0) {
110-
return -EBUSY;
111-
}
112-
113101
/* Output the buffer */
114-
SEGGER_RTT_WriteNoLock(ch, buf, len);
115-
116-
/* Return RTT lock */
117-
SEGGER_RTT_UNLOCK();
102+
SEGGER_RTT_Write(ch, buf, len);
118103

119104
/* Send the TX complete callback */
120105
if (data->callback) {

modules/segger/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if USE_SEGGER_RTT
2323
config SEGGER_RTT_CUSTOM_LOCKING
2424
bool "Custom locking"
2525
help
26-
Enable custom locking using a mutex.
26+
Enable custom locking using Zephyr APIs.
2727

2828
config SEGGER_RTT_MAX_NUM_UP_BUFFERS
2929
int "Maximum number of up-buffers"

modules/segger/SEGGER_RTT_zephyr.c

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,13 @@
99
#include <zephyr/init.h>
1010
#include "SEGGER_RTT.h"
1111

12-
/*
13-
* Common mutex for locking access to terminal buffer.
14-
* Note that SEGGER uses same lock macros for both SEGGER_RTT_Write and
15-
* SEGGER_RTT_Read functions. Because of this we are not able generally
16-
* separate up and down access using two mutexes until SEGGER library fix
17-
* this.
18-
*
19-
* If sharing access cause performance problems, consider using another
20-
* non terminal buffers.
21-
*/
22-
23-
K_MUTEX_DEFINE(rtt_term_mutex);
24-
2512
static int rtt_init(void)
2613
{
27-
2814
SEGGER_RTT_Init();
2915

3016
return 0;
3117
}
3218

33-
#ifdef CONFIG_MULTITHREADING
34-
35-
void zephyr_rtt_mutex_lock(void)
36-
{
37-
k_mutex_lock(&rtt_term_mutex, K_FOREVER);
38-
}
39-
40-
void zephyr_rtt_mutex_unlock(void)
41-
{
42-
k_mutex_unlock(&rtt_term_mutex);
43-
}
44-
45-
#endif /* CONFIG_MULTITHREADING */
46-
4719
unsigned int zephyr_rtt_irq_lock(void)
4820
{
4921
return irq_lock();
@@ -54,6 +26,4 @@ void zephyr_rtt_irq_unlock(unsigned int key)
5426
irq_unlock(key);
5527
}
5628

57-
58-
5929
SYS_INIT(rtt_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_OBJECTS);

west.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ manifest:
317317
path: modules/lib/picolibc
318318
revision: 27746bbc246841852912fc3bb5b45094cd8a505a
319319
- name: segger
320-
revision: b011c45b585e097d95d9cf93edf4f2e01588d3cd
320+
revision: 798f95ea9304e5ed8165a661081443051f210733
321321
path: modules/debug/segger
322322
groups:
323323
- debug

0 commit comments

Comments
 (0)