Clayton Kimber
/
Segger_RTT_TEST
Implementation of Segger RTT on nRF52832. There is unneeded code in the defines and main(commented out).
main.cpp@0:ead2f457b1a2, 2019-04-26 (annotated)
- Committer:
- claytonk
- Date:
- Fri Apr 26 17:46:21 2019 +0000
- Revision:
- 0:ead2f457b1a2
initial
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
claytonk | 0:ead2f457b1a2 | 1 | /* mbed Microcontroller Library |
claytonk | 0:ead2f457b1a2 | 2 | * Copyright (c) 2018 ARM Limited |
claytonk | 0:ead2f457b1a2 | 3 | * SPDX-License-Identifier: Apache-2.0 |
claytonk | 0:ead2f457b1a2 | 4 | */ |
claytonk | 0:ead2f457b1a2 | 5 | |
claytonk | 0:ead2f457b1a2 | 6 | #define NRF_LOG_BACKEND_SERIAL_USES_RTT 1 |
claytonk | 0:ead2f457b1a2 | 7 | #define NRF_MODULE_ENABLED 1 |
claytonk | 0:ead2f457b1a2 | 8 | #define NRF_LOG_BACKEND_RTT 1 |
claytonk | 0:ead2f457b1a2 | 9 | #define NRF_LOG_USES_RTT 1 |
claytonk | 0:ead2f457b1a2 | 10 | #define NRF_LOG_USES_COLORS 1 |
claytonk | 0:ead2f457b1a2 | 11 | #define NRF_LOG_ENABLED 1 |
claytonk | 0:ead2f457b1a2 | 12 | #define TWIS_CONFIG_LOG_ENABLED 1 |
claytonk | 0:ead2f457b1a2 | 13 | #define TWI_CONFIG_LOG_ENABLED 1 |
claytonk | 0:ead2f457b1a2 | 14 | #include "retarget_segger_rtt.h" |
claytonk | 0:ead2f457b1a2 | 15 | #include "mbed.h" |
claytonk | 0:ead2f457b1a2 | 16 | #include "stats_report.h" |
claytonk | 0:ead2f457b1a2 | 17 | |
claytonk | 0:ead2f457b1a2 | 18 | #define ledRed_pin p12 |
claytonk | 0:ead2f457b1a2 | 19 | |
claytonk | 0:ead2f457b1a2 | 20 | DigitalOut led1(ledRed_pin); |
claytonk | 0:ead2f457b1a2 | 21 | |
claytonk | 0:ead2f457b1a2 | 22 | #define SLEEP_TIME 500 // (msec) |
claytonk | 0:ead2f457b1a2 | 23 | #define PRINT_AFTER_N_LOOPS 20 |
claytonk | 0:ead2f457b1a2 | 24 | |
claytonk | 0:ead2f457b1a2 | 25 | // main() runs in its own thread in the OS |
claytonk | 0:ead2f457b1a2 | 26 | int main() |
claytonk | 0:ead2f457b1a2 | 27 | { |
claytonk | 0:ead2f457b1a2 | 28 | // Unneeded stuff |
claytonk | 0:ead2f457b1a2 | 29 | // SEGGER_RTT_Init(); |
claytonk | 0:ead2f457b1a2 | 30 | // NRF_LOG_INIT(); |
claytonk | 0:ead2f457b1a2 | 31 | // segger.write(buffer,2); |
claytonk | 0:ead2f457b1a2 | 32 | |
claytonk | 0:ead2f457b1a2 | 33 | SystemReport sys_state( SLEEP_TIME * PRINT_AFTER_N_LOOPS /* Loop delay time in ms */); |
claytonk | 0:ead2f457b1a2 | 34 | |
claytonk | 0:ead2f457b1a2 | 35 | int count = 0; |
claytonk | 0:ead2f457b1a2 | 36 | while (true) { |
claytonk | 0:ead2f457b1a2 | 37 | // Blink LED and wait 0.5 seconds |
claytonk | 0:ead2f457b1a2 | 38 | led1 = !led1; |
claytonk | 0:ead2f457b1a2 | 39 | wait_ms(SLEEP_TIME); |
claytonk | 0:ead2f457b1a2 | 40 | // can use printf, but it gets stored in a buffer somewhere and isn't immediate |
claytonk | 0:ead2f457b1a2 | 41 | printf("led"); |
claytonk | 0:ead2f457b1a2 | 42 | |
claytonk | 0:ead2f457b1a2 | 43 | // USE SEGGER_RTT_WriteString |
claytonk | 0:ead2f457b1a2 | 44 | // Very fast |
claytonk | 0:ead2f457b1a2 | 45 | SEGGER_RTT_WriteString(0, "Hello World from SEGGER!\r\n"); |
claytonk | 0:ead2f457b1a2 | 46 | |
claytonk | 0:ead2f457b1a2 | 47 | // NOT NEEDED, but could be usefull |
claytonk | 0:ead2f457b1a2 | 48 | if ((0 == count) || (PRINT_AFTER_N_LOOPS == count)) { |
claytonk | 0:ead2f457b1a2 | 49 | // Following the main thread wait, report on the current system status |
claytonk | 0:ead2f457b1a2 | 50 | sys_state.report_state(); |
claytonk | 0:ead2f457b1a2 | 51 | count = 0; |
claytonk | 0:ead2f457b1a2 | 52 | } |
claytonk | 0:ead2f457b1a2 | 53 | ++count; |
claytonk | 0:ead2f457b1a2 | 54 | |
claytonk | 0:ead2f457b1a2 | 55 | } |
claytonk | 0:ead2f457b1a2 | 56 | } |