Clayton Kimber
/
Segger_RTT_TEST
Implementation of Segger RTT on nRF52832. There is unneeded code in the defines and main(commented out).
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2018 ARM Limited 00003 * SPDX-License-Identifier: Apache-2.0 00004 */ 00005 00006 #define NRF_LOG_BACKEND_SERIAL_USES_RTT 1 00007 #define NRF_MODULE_ENABLED 1 00008 #define NRF_LOG_BACKEND_RTT 1 00009 #define NRF_LOG_USES_RTT 1 00010 #define NRF_LOG_USES_COLORS 1 00011 #define NRF_LOG_ENABLED 1 00012 #define TWIS_CONFIG_LOG_ENABLED 1 00013 #define TWI_CONFIG_LOG_ENABLED 1 00014 #include "retarget_segger_rtt.h" 00015 #include "mbed.h" 00016 #include "stats_report.h" 00017 00018 #define ledRed_pin p12 00019 00020 DigitalOut led1(ledRed_pin); 00021 00022 #define SLEEP_TIME 500 // (msec) 00023 #define PRINT_AFTER_N_LOOPS 20 00024 00025 // main() runs in its own thread in the OS 00026 int main() 00027 { 00028 // Unneeded stuff 00029 // SEGGER_RTT_Init(); 00030 // NRF_LOG_INIT(); 00031 // segger.write(buffer,2); 00032 00033 SystemReport sys_state( SLEEP_TIME * PRINT_AFTER_N_LOOPS /* Loop delay time in ms */); 00034 00035 int count = 0; 00036 while (true) { 00037 // Blink LED and wait 0.5 seconds 00038 led1 = !led1; 00039 wait_ms(SLEEP_TIME); 00040 // can use printf, but it gets stored in a buffer somewhere and isn't immediate 00041 printf("led"); 00042 00043 // USE SEGGER_RTT_WriteString 00044 // Very fast 00045 SEGGER_RTT_WriteString(0, "Hello World from SEGGER!\r\n"); 00046 00047 // NOT NEEDED, but could be usefull 00048 if ((0 == count) || (PRINT_AFTER_N_LOOPS == count)) { 00049 // Following the main thread wait, report on the current system status 00050 sys_state.report_state(); 00051 count = 0; 00052 } 00053 ++count; 00054 00055 } 00056 }
Generated on Thu Jul 21 2022 02:33:58 by 1.7.2