Skip to content

Commit

Permalink
[examples] Add RTT with OpenOCD example
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Apr 12, 2021
1 parent c2391e3 commit 6f178d5
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 1 deletion.
3 changes: 2 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ supported development boards:
[CAN](https://github.com/modm-io/modm/blob/develop/examples/stm32f3_discovery/can/main.cpp),
[Accelerometer](https://github.com/modm-io/modm/blob/develop/examples/stm32f3_discovery/accelerometer/main.cpp),
[Gyroscope](https://github.com/modm-io/modm/blob/develop/examples/stm32f3_discovery/rotation/main.cpp),
[TinyUSB DFU](https://github.com/modm-io/modm/blob/develop/examples/stm32f3_discovery/usb_dfu/main.cpp).
[TinyUSB DFU](https://github.com/modm-io/modm/blob/develop/examples/stm32f3_discovery/usb_dfu/main.cpp),
[Logging via RTT](https://github.com/modm-io/modm/blob/develop/examples/stm32f3_discovery/rtt/main.cpp).
- STM32F4 Discovery:
[Blinky](https://github.com/modm-io/modm/blob/develop/examples/stm32f4_discovery/blink/main.cpp),
[CAN](https://github.com/modm-io/modm/blob/develop/examples/stm32f4_discovery/can/main.cpp),
Expand Down
93 changes: 93 additions & 0 deletions examples/stm32f3_discovery/rtt/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright (c) 2021, Niklas Hauser
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#include <modm/board.hpp>
#include <modm/processing.hpp>
#include <modm/debug.hpp>

using namespace Board;

Rtt rtt(0);
modm::IODeviceObjectWrapper< Rtt, modm::IOBuffer::DiscardIfFull > rtt_device(rtt);
// Set all four logger streams to use RTT
modm::log::Logger modm::log::debug(rtt_device);
modm::log::Logger modm::log::info(rtt_device);
modm::log::Logger modm::log::warning(rtt_device);
modm::log::Logger modm::log::error(rtt_device);

#undef MODM_LOG_LEVEL
#define MODM_LOG_LEVEL modm::log::INFO

/*
$ scons log-rtt
╭───OpenOCD───> Real Time Transfer
╰─────RTT────── stm32f303vct6
Info : STLINK V2J16S0 (API v2) VID:PID 0483:3748
Info : stm32f3x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : rtt: Searching for control block 'modm.rtt.modm'
Info : rtt: Control block found at 0x20000c04
Info : Listening on port 9090 for rtt connections
Info
Warning
Error
loop: 0
loop: 1
loop: 2
loop: 3
loop: 4
loop: 5
Type number 0-9, then press enter to send.
The LED should blink slower or faster.
Ctrl+D to exit
*/

// ----------------------------------------------------------------------------
int
main()
{
Board::initialize();

MODM_LOG_DEBUG << "Debug" << modm::endl;
MODM_LOG_INFO << "Info" << modm::endl;
MODM_LOG_WARNING << "Warning" << modm::endl;
MODM_LOG_ERROR << "Error" << modm::endl;

uint32_t counter(0);
modm::PeriodicTimer tmr(100ms);

char data;
while (true)
{
MODM_LOG_INFO.get(data);
switch(data)
{
case '0':
tmr.restart(1s);
break;
case '1'...'9':
tmr.restart(std::chrono::milliseconds((data - '0') * 100));
break;
}
if (tmr.execute())
{
LedNorth::toggle();

MODM_LOG_INFO << "loop: " << counter++ << modm::endl;
}
}

return 0;
}
13 changes: 13 additions & 0 deletions examples/stm32f3_discovery/rtt/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<library>
<extends>modm:disco-f303vc</extends>
<options>
<option name="modm:build:build.path">../../../build/stm32f3_discovery/rtt</option>
<option name="modm:platform:rtt:buffer.rx">16</option>
</options>
<modules>
<module>modm:platform:rtt</module>
<module>modm:processing:timer</module>
<module>modm:build:scons</module>
<module>modm:debug</module>
</modules>
</library>

0 comments on commit 6f178d5

Please sign in to comment.