Skip to content

Commit f8ec343

Browse files
committed
Add target option to redirect NRF_LOG_* logging to mbed logging (stdout)
Modify the SDK11 softdevice_enable() logging to not dependent on Segger RTT being present & enabled. This change is not required in any later versions of SDK
1 parent db73ed0 commit f8ec343

File tree

5 files changed

+160
-19
lines changed

5 files changed

+160
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "softdevice",
3+
"config": {
4+
"nrf_enable_logging": {
5+
"help": "When '1' NRF_LOG_* outputs will be sent to stdout.",
6+
"value": "0",
7+
"macro_name": "NRF_LOG_ENABLED"
8+
}
9+
},
10+
"macros": [
11+
"SOFTDEVICE_PRESENT=1",
12+
"S130"
13+
],
14+
"target_overrides": {
15+
"*": {
16+
"target.features_add": ["BLE"],
17+
"target.bootloader_img": "hex/s130_nrf51_2.0.0_softdevice.hex"
18+
}
19+
}
20+
}

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/libraries/util/nrf_log.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ uint32_t log_uart_init()
182182
UART_TX_BUF_SIZE,
183183
uart_error_cb,
184184
#ifdef NRF51
185-
APP_IRQ_PRIORITY_LOW
185+
APP_IRQ_PRIORITY_LOW,
186186
#elif defined(NRF52)
187-
APP_IRQ_PRIORITY_LOWEST
187+
APP_IRQ_PRIORITY_LOWEST,
188188
#endif
189189
err_code);
190190

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/softdevice/common/softdevice_handler/softdevice_handler.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,7 @@
6262
#include "nrf_ble.h"
6363
#endif
6464

65-
66-
#if defined(NRF_LOG_USES_RTT) && NRF_LOG_USES_RTT == 1
6765
#define SD_HANDLER_LOG(...) NRF_LOG_PRINTF(__VA_ARGS__)
68-
#else
69-
#define SD_HANDLER_LOG(...)
70-
#endif
7166

7267
#if defined(NRF_LOG_USES_RTT) && NRF_LOG_USES_RTT == 1
7368
#define SD_HANDLER_LOG_INIT() NRF_LOG_INIT()
@@ -410,7 +405,8 @@ uint32_t softdevice_enable_get_default_config(uint8_t central_links_count,
410405
}
411406

412407

413-
#if defined(NRF_LOG_USES_RTT) && NRF_LOG_USES_RTT == 1
408+
#if (defined(NRF_LOG_USES_RTT) && NRF_LOG_USES_RTT == 1) || \
409+
(defined(NRF_LOG_USES_UART) && NRF_LOG_USES_UART == 1)
414410
static inline uint32_t ram_total_size_get(void)
415411
{
416412
#ifdef NRF51
@@ -453,15 +449,13 @@ uint32_t sd_check_ram_start(uint32_t sd_req_ram_start)
453449
#endif//__CC_ARM
454450
if (ram_start != sd_req_ram_start)
455451
{
456-
#if defined(NRF_LOG_USES_RTT) && NRF_LOG_USES_RTT == 1
457452
uint32_t app_ram_size= ram_end_address_get();
458453
SD_HANDLER_LOG("RAM START ADDR 0x%x should be adjusted to 0x%x\r\n",
459454
ram_start,
460455
sd_req_ram_start);
461456
app_ram_size -= sd_req_ram_start;
462457
SD_HANDLER_LOG("RAM SIZE should be adjusted to 0x%x \r\n",
463458
app_ram_size);
464-
#endif //NRF_LOG_USES_RTT
465459
return NRF_SUCCESS;
466460
}
467461
#endif//defined(S130) || defined(S132) || defined(S332)
@@ -490,22 +484,18 @@ uint32_t softdevice_enable(ble_enable_params_t * p_ble_enable_params)
490484
app_ram_base);
491485
err_code = sd_ble_enable(p_ble_enable_params, &app_ram_base);
492486

493-
#if defined(NRF_LOG_USES_RTT) && NRF_LOG_USES_RTT == 1
487+
// MODIFIED the rest of this function to match logging implementation in SDK13
494488
if (app_ram_base != ram_start)
495489
{
496-
uint32_t app_ram_size= ram_end_address_get();
497-
SD_HANDLER_LOG("sd_ble_enable: app_ram_base should be adjusted to 0x%x\r\n",
498-
app_ram_base);
499-
app_ram_size -= app_ram_base;
500-
SD_HANDLER_LOG("ram size should be adjusted to 0x%x \r\n",
501-
app_ram_size);
490+
SD_HANDLER_LOG("sd_ble_enable: RAM start should be adjusted to 0x%x\r\n",
491+
app_ram_base);
492+
SD_HANDLER_LOG("RAM size should be adjusted to 0x%x \r\n",
493+
ram_end_address_get() - app_ram_base);
502494
}
503495
else if (err_code != NRF_SUCCESS)
504496
{
505497
SD_HANDLER_LOG("sd_ble_enable: error 0x%x\r\n", err_code);
506-
while(1);
507498
}
508-
#endif // NRF_LOG_USES_RTT
509499
return err_code;
510500
#else
511501
return NRF_SUCCESS;
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef APP_UART_H_
18+
#define APP_UART_H_
19+
20+
// This replacement <app_uart.h> provides forwarding of nrf logging to
21+
// stdout when NRF_LOG_USES_UART is enabled
22+
23+
#include <stdio.h>
24+
#include "nrf_error.h"
25+
#include "nrf51_bitfields.h"
26+
#include "cmsis_compiler.h"
27+
28+
#define app_uart_put(c) putc(c, stdout)
29+
30+
__STATIC_INLINE uint32_t app_uart_get(uint8_t *c) {
31+
*c = getc(stdin);
32+
return NRF_SUCCESS;
33+
}
34+
35+
/**@brief UART Flow Control modes for the peripheral.
36+
*/
37+
typedef enum
38+
{
39+
APP_UART_FLOW_CONTROL_DISABLED, /**< UART Hw Flow Control is disabled. */
40+
APP_UART_FLOW_CONTROL_ENABLED, /**< Standard UART Hw Flow Control is enabled. */
41+
APP_UART_FLOW_CONTROL_LOW_POWER /**< Specialized UART Hw Flow Control is used. The Low Power setting allows the \nRFXX to Power Off the UART module when CTS is in-active, and re-enabling the UART when the CTS signal becomes active. This allows the \nRFXX to safe power by only using the UART module when it is needed by the remote site. */
42+
} app_uart_flow_control_t;
43+
44+
45+
/**@brief Enumeration which defines events used by the UART module upon data reception or error.
46+
*
47+
* @details The event type is used to indicate the type of additional information in the event
48+
* @ref app_uart_evt_t.
49+
*/
50+
typedef enum
51+
{
52+
APP_UART_DATA_READY, /**< An event indicating that UART data has been received. The data is available in the FIFO and can be fetched using @ref app_uart_get. */
53+
APP_UART_FIFO_ERROR, /**< An error in the FIFO module used by the app_uart module has occured. The FIFO error code is stored in app_uart_evt_t.data.error_code field. */
54+
APP_UART_COMMUNICATION_ERROR, /**< An communication error has occured during reception. The error is stored in app_uart_evt_t.data.error_communication field. */
55+
APP_UART_TX_EMPTY, /**< An event indicating that UART has completed transmission of all available data in the TX FIFO. */
56+
APP_UART_DATA, /**< An event indicating that UART data has been received, and data is present in data field. This event is only used when no FIFO is configured. */
57+
} app_uart_evt_type_t;
58+
59+
60+
/**@brief UART communication structure holding configuration settings for the peripheral.
61+
*/
62+
typedef struct
63+
{
64+
uint8_t rx_pin_no; /**< RX pin number. */
65+
uint8_t tx_pin_no; /**< TX pin number. */
66+
uint8_t rts_pin_no; /**< RTS pin number, only used if flow control is enabled. */
67+
uint8_t cts_pin_no; /**< CTS pin number, only used if flow control is enabled. */
68+
app_uart_flow_control_t flow_control; /**< Flow control setting, if flow control is used, the system will use low power UART mode, based on CTS signal. */
69+
bool use_parity; /**< Even parity if TRUE, no parity if FALSE. */
70+
uint32_t baud_rate; /**< Baud rate configuration. */
71+
} app_uart_comm_params_t;
72+
73+
/**@brief Struct containing events from the UART module.
74+
*
75+
* @details The app_uart_evt_t is used to notify the application of asynchronous events when data
76+
* are received on the UART peripheral or in case an error occured during data reception.
77+
*/
78+
typedef struct
79+
{
80+
app_uart_evt_type_t evt_type; /**< Type of event. */
81+
union
82+
{
83+
uint32_t error_communication; /**< Field used if evt_type is: APP_UART_COMMUNICATION_ERROR. This field contains the value in the ERRORSRC register for the UART peripheral. The UART_ERRORSRC_x defines from nrf5x_bitfields.h can be used to parse the error code. See also the \nRFXX Series Reference Manual for specification. */
84+
uint32_t error_code; /**< Field used if evt_type is: NRF_ERROR_x. Additional status/error code if the error event type is APP_UART_FIFO_ERROR. This error code refer to errors defined in nrf_error.h. */
85+
uint8_t value; /**< Field used if evt_type is: NRF_ERROR_x. Additional status/error code if the error event type is APP_UART_FIFO_ERROR. This error code refer to errors defined in nrf_error.h. */
86+
} data;
87+
} app_uart_evt_t;
88+
89+
//#define APP_IRQ_PRIORITY_LOW -1,
90+
//#define APP_IRQ_PRIORITY_LOWEST -1,
91+
92+
#define APP_UART_FIFO_INIT(P_COMM_PARAMS, RX_BUF_SIZE, TX_BUF_SIZE, EVT_HANDLER, IRQ_PRIO, ERR_CODE) \
93+
do \
94+
{ \
95+
(void)P_COMM_PARAMS; \
96+
ERR_CODE = 0; \
97+
} while (0)
98+
#endif // APP_UART_H_
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// Dummy header file to satify import requirement of nrf_log.c
18+
// when NRF_LOG_USES_UART is enabled
19+
20+
#ifndef DUMMY_BSP_H_
21+
#define DUMMY_BSP_H_
22+
23+
const int RX_PIN_NUMBER = -1;
24+
const int TX_PIN_NUMBER = -1;
25+
const int RTS_PIN_NUMBER = -1;
26+
const int CTS_PIN_NUMBER = -1;
27+
28+
// This is not used for any functional code so does not need to be correct
29+
#ifndef NRF51
30+
#define NRF51
31+
#endif
32+
33+
#endif // DUMMY_BSP_H_

0 commit comments

Comments
 (0)