|
| 1 | +/* |
| 2 | + * Copyright (c) 2021, Niklas Hauser |
| 3 | + * Edited by Steven Macias |
| 4 | + * |
| 5 | + * This file is part of the modm project. |
| 6 | + * |
| 7 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 8 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 9 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 10 | + */ |
| 11 | +// ---------------------------------------------------------------------------- |
| 12 | + |
| 13 | +#include <modm/board.hpp> |
| 14 | +#include <modm/processing.hpp> |
| 15 | +#include <modm/debug.hpp> |
| 16 | + |
| 17 | +using namespace Board; |
| 18 | + |
| 19 | +Rtt rtt(0); |
| 20 | +modm::IODeviceObjectWrapper< Rtt, modm::IOBuffer::DiscardIfFull > rtt_device(rtt); |
| 21 | +// Set all four logger streams to use RTT |
| 22 | +modm::log::Logger modm::log::debug(rtt_device); |
| 23 | +modm::log::Logger modm::log::info(rtt_device); |
| 24 | +modm::log::Logger modm::log::warning(rtt_device); |
| 25 | +modm::log::Logger modm::log::error(rtt_device); |
| 26 | + |
| 27 | +#undef MODM_LOG_LEVEL |
| 28 | +#define MODM_LOG_LEVEL modm::log::INFO |
| 29 | + |
| 30 | +/* |
| 31 | +
|
| 32 | + $ scons log-rtt |
| 33 | +╭───OpenOCD───> Real Time Transfer |
| 34 | +╰─────RTT────── stm32f303vct6 |
| 35 | +Info : STLINK V2J16S0 (API v2) VID:PID 0483:3748 |
| 36 | +Info : stm32f3x.cpu: hardware has 6 breakpoints, 4 watchpoints |
| 37 | +Info : rtt: Searching for control block 'modm.rtt.modm' |
| 38 | +Info : rtt: Control block found at 0x20000c04 |
| 39 | +Info : Listening on port 9090 for rtt connections |
| 40 | +Info |
| 41 | +Warning |
| 42 | +Error |
| 43 | +loop: 0 |
| 44 | +loop: 1 |
| 45 | +loop: 2 |
| 46 | +loop: 3 |
| 47 | +loop: 4 |
| 48 | +loop: 5 |
| 49 | +
|
| 50 | +
|
| 51 | +Type number 0-9, then press enter to send. |
| 52 | +The LED should blink slower or faster. |
| 53 | +
|
| 54 | +Ctrl+D to exit |
| 55 | +
|
| 56 | +*/ |
| 57 | + |
| 58 | +// ---------------------------------------------------------------------------- |
| 59 | +int |
| 60 | +main() |
| 61 | +{ |
| 62 | + Board::initialize(); |
| 63 | + |
| 64 | + MODM_LOG_DEBUG << "Debug" << modm::endl; |
| 65 | + MODM_LOG_INFO << "Info" << modm::endl; |
| 66 | + MODM_LOG_WARNING << "Warning" << modm::endl; |
| 67 | + MODM_LOG_ERROR << "Error" << modm::endl; |
| 68 | + |
| 69 | + uint32_t counter(0); |
| 70 | + modm::PeriodicTimer tmr(100ms); |
| 71 | + |
| 72 | + char data; |
| 73 | + while (true) |
| 74 | + { |
| 75 | + MODM_LOG_INFO.get(data); |
| 76 | + switch(data) |
| 77 | + { |
| 78 | + case '0': |
| 79 | + tmr.restart(1s); |
| 80 | + break; |
| 81 | + case '1'...'9': |
| 82 | + tmr.restart(std::chrono::milliseconds((data - '0') * 100)); |
| 83 | + break; |
| 84 | + } |
| 85 | + if (tmr.execute()) |
| 86 | + { |
| 87 | + LedGreen::toggle(); |
| 88 | + |
| 89 | + MODM_LOG_INFO << "loop: " << counter++ << modm::endl; |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + return 0; |
| 94 | +} |
0 commit comments