Skip to content

Commit 5a55b39

Browse files
authored
Merge pull request #2887 from ARMmbed/update_mbed_trace
Update mbed trace
2 parents 765fbbb + 11f8ccc commit 5a55b39

File tree

2 files changed

+47
-16
lines changed

2 files changed

+47
-16
lines changed

features/FEATURE_COMMON_PAL/mbed-trace/README.md

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,37 @@ The purpose of the library is to provide a light, simple and general tracing sol
4343
### Prerequisites
4444

4545
* Initialize the serial port so that `stdout` works. You can verify that the serial port works using the `printf()` function.
46-
* if you want to redirect the traces somewhere else, see the [trace API](https://github.com/ARMmbed/mbed-trace/blob/master/mbed-trace/mbed_trace.h#L170).
47-
* to activate traces, configure yotta with flag: `YOTTA_CFG_MBED_TRACE` set to 1 or true. Setting the flag to 0 or false disables tracing.
48-
* By default trace uses 1024 bytes buffer for trace lines, but it can be configure by yotta with: `YOTTA_CFG_MBED_TRACE_LINE_LENGTH`. Default length: 1024.
49-
* To disable ipv6 convertion, set `YOTTA_CFG_MBED_TRACE_FEA_IPV6 = 0` from yotta configurations.
50-
* If thread safety is needed, configure the wait and release callback functions before initialization so that the protection is in place as soon as the library is initialized. This should usually only be done once in the application's lifetime.
46+
* if you want to redirect the traces somewhere else, see the [trace API](https://github.com/ARMmbed/mbed-trace/blob/master/mbed-trace/mbed_trace.h#L170).
47+
* To enable the tracing API:
48+
* With yotta: set `YOTTA_CFG_MBED_TRACE` to 1 or true. Setting the flag to 0 or false disables tracing.
49+
* [With mbed OS 5](#enabling-the-tracing-api-in-mbed-os-5)
50+
* By default, trace uses 1024 bytes buffer for trace lines, but you can change it by yotta with: `YOTTA_CFG_MBED_TRACE_LINE_LENGTH`.
51+
* To disable the IPv6 conversion, set `YOTTA_CFG_MBED_TRACE_FEA_IPV6 = 0`.
52+
* If thread safety is needed, configure the wait and release callback functions before initialization to enable the protection. Usually, this needs to be done only once in the application's lifetime.
5153
* Call the trace initialization (`mbed_trace_init`) once before using any other APIs. It allocates the trace buffer and initializes the internal variables.
52-
* Define `TRACE_GROUP` in your source code (not in the header!) to use traces. `TRACE_GROUP` is a 1-4 character long char-array (for example `#define TRACE_GROUP "APPL"`). This will be printed on every trace line.
54+
* Define `TRACE_GROUP` in your source code (not in the header!) to use traces. It is a 1-4 characters long char-array (for example `#define TRACE_GROUP "APPL"`). This will be printed on every trace line.
55+
56+
### Enabling the tracing API in mbed OS 5
57+
58+
* Add the feature COMMON_PAL into the build
59+
* Set `MBED_CONF_MBED_TRACE_ENABLE` to 1 or true
60+
61+
To do so, add the following to your mbed_app.json:
62+
63+
```json
64+
{
65+
"target_overrides": {
66+
"*": {
67+
"target.features_add": ["COMMON_PAL"],
68+
"mbed-trace.enable": 1
69+
}
70+
}
71+
}
72+
```
73+
74+
Don't forget to fulfill the other [prerequisites](#prerequisites)!
75+
76+
([Click here for more information on the configuration system](https://github.com/ARMmbed/mbed-os/blob/master/docs/config_system.md))
5377

5478
### Traces
5579

@@ -63,31 +87,35 @@ Available levels:
6387
* info
6488
* cmdline (special behavior, should not be used)
6589

66-
Set mutex wait and release functions, if thread safety is needed. Do this before initialization so the functions are immediately available:
90+
For the thread safety, set the mutex wait and release functions. You need do this before the initialization to have the functions available right away:
6791

6892
```c
6993
mbed_trace_mutex_wait_function_set(my_mutex_wait);
7094
mbed_trace_mutex_release_function_set(my_mutex_release);
7195
```
7296
73-
Initialization (once in application lifetime):
97+
Initialization (once in application's lifetime):
7498
7599
```c
76100
int mbed_trace_init(void);
77101
```
78102

79-
Set output function, `printf` by default:
103+
Set the output function, `printf` by default:
80104

81105
```c
82106
mbed_trace_print_function_set(printf)
83107
```
84108
85109
### Helping functions
86110
87-
The purpose of the helping functions is to provide simple conversions, for example from an array to C string, so that you can print everything to single trace line.
88-
These must be called inside actual trace calls, e.g. ```tr_debug("My IP6 address: %s", mbed_trace_ipv6(addr));```.
111+
The purpose of the helping functions is to provide simple conversions, for example from an array to C string, so that you can print everything to single trace line. They must be called inside the actual trace calls, for example:
112+
113+
```
114+
tr_debug("My IP6 address: %s", mbed_trace_ipv6(addr));
115+
```
89116
90117
Available conversion functions:
118+
91119
```
92120
char *mbed_trace_ipv6(const void *addr_ptr)
93121
char *mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len)
@@ -104,7 +132,7 @@ See more in [mbed_trace.h](https://github.com/ARMmbed/mbed-trace/blob/master/mbe
104132
#include "mbed-trace/mbed_trace.h"
105133
#define TRACE_GROUP "main"
106134
107-
// These are only necessary if thread safety is needed
135+
// These are necessary only if thread safety is needed
108136
static Mutex MyMutex;
109137
static void my_mutex_wait()
110138
{
@@ -131,15 +159,17 @@ int main(void){
131159

132160
## Unit tests
133161

134-
To run unit tests
162+
To run unit tests:
163+
164+
* In Linux
135165

136-
* In Linux:
137166
```
138167
yotta target x86-linux-native
139168
yotta test mbed_trace_test
140169
```
141170

142-
* In Windows:
171+
* In Windows
172+
143173
```
144174
yotta target x86-windows-native
145175
yotta test mbed_trace_test

features/FEATURE_COMMON_PAL/mbed-trace/source/mbed_trace.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,8 @@ void mbed_vtracef(uint8_t dlevel, const char* grp, const char *fmt, va_list ap)
454454

455455
end:
456456
if ( m_trace.mutex_release_f ) {
457-
for ( ;m_trace.mutex_lock_count > 0; m_trace.mutex_lock_count-- ) {
457+
while (m_trace.mutex_lock_count > 0) {
458+
m_trace.mutex_lock_count--;
458459
m_trace.mutex_release_f();
459460
}
460461
}

0 commit comments

Comments
 (0)