Skip to content

Commit ae74049

Browse files
committed
[examples] Add generic fiber stack overflow example
1 parent e33ccab commit ae74049

File tree

4 files changed

+71
-75
lines changed

4 files changed

+71
-75
lines changed
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2024, Niklas Hauser
3+
*
4+
* This file is part of the modm project.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public
7+
* License, v. 2.0. If a copy of the MPL was not distributed with this
8+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
// ----------------------------------------------------------------------------
11+
12+
#include <modm/board.hpp>
13+
#include <modm/processing.hpp>
14+
15+
using namespace Board;
16+
using namespace std::chrono_literals;
17+
18+
19+
bool overflow{false};
20+
21+
modm::Fiber<> bad_fiber([]
22+
{
23+
while(1)
24+
{
25+
#ifdef __AVR__
26+
if (overflow) asm volatile ("push r1");
27+
#else
28+
if (overflow) asm volatile ("push {r0-r7}");
29+
#endif
30+
modm::this_fiber::yield();
31+
}
32+
});
33+
34+
modm::Fiber<> blinky([]
35+
{
36+
while(1)
37+
{
38+
Board::Leds::toggle();
39+
modm::this_fiber::sleep_for(0.5s);
40+
char c;
41+
modm::log::info.get(c);
42+
if (c == 'o') overflow = true;
43+
}
44+
});
45+
46+
int
47+
main()
48+
{
49+
Board::initialize();
50+
Board::Leds::setOutput();
51+
MODM_LOG_INFO << "\nReboot!\nSend 'o' to overflow the stack!" << modm::endl;
52+
modm::delay(1s);
53+
54+
modm::fiber::Scheduler::run();
55+
56+
return 0;
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<library>
2+
<extends>modm:nucleo-u575zi-q</extends>
3+
<!-- <extends>modm:nucleo-g071rb</extends> -->
4+
<!-- <extends>modm:nucleo-l476rg</extends> -->
5+
<!-- <extends>modm:mega-2560-pro</extends> -->
6+
<!-- <extends>modm:arduino-uno</extends> -->
7+
<options>
8+
<option name="modm:build:build.path">../../../build/generic/fiber_overflow</option>
9+
</options>
10+
<modules>
11+
<module>modm:build:scons</module>
12+
<module>modm:processing:fiber</module>
13+
</modules>
14+
</library>

examples/nucleo_u575zi-q/fiber_overflow/main.cpp

-65
This file was deleted.

examples/nucleo_u575zi-q/fiber_overflow/project.xml

-10
This file was deleted.

0 commit comments

Comments
 (0)