Bootloader
/
test_app.cpp
87 строк · 1.5 Кб
1
2#include <iopins.h>
3#include <dispatcher.h>
4#include <sys_tick.h>
5#include <watchdog.h>
6#include <usart.h>
7#include <tiny_ostream.h>
8#include <tiny_iomanip.h>
9
10using namespace Mcucpp;
11using namespace Mcucpp::IO;
12using namespace Mcucpp::Clock;
13
14
15#if defined(STM32F40_41xxx)
16
17typedef Usart1 BootDevice;
18typedef Usart1Clock BootDeviceClock;
19
20typedef Pb6 TxPin;
21typedef Pb7 RxPin;
22typedef NullPin DePin;
23typedef Pd13 Led;
24
25#elif defined(STM32L471xx)
26
27
28typedef Usart3 BootDevice;
29typedef Usart3Clock BootDeviceClock;
30
31typedef Pc4 TxPin;
32typedef Pc5 RxPin;
33typedef Pb1 DePin;
34typedef Pb9 Led;
35
36#endif
37
38basic_ostream<BootDevice> cout;
39
40void Blink()
41{
42Led::Toggle();
43GetCurrentDispatcher().SetTimer(1000, Blink);
44}
45
46struct Bar
47{
48public:
49unsigned c;
50unsigned d;
51};
52
53struct Foo
54{
55public:
56int a;
57int b;
58Bar bar;
59uint16_t buffer[100];
60};
61
62volatile Foo fooInstance{1, 2, {3, 4}, {0}};
63
64int main()
65{
66Led::Port::Enable();
67Led::SetConfiguration(Led::Port::Out);
68Led::Set();
69BootDevice::Init(115200);
70BootDevice::SelectTxRxPins<TxPin, RxPin>();
71BootDevice::SelectDePin<DePin>();
72BootDevice::SetRxTimeout(20);
73
74cout << "Hello!!\r\n";
75
76Watchdog::Start(2000);
77SysTickTimer::Init(1);
78SysTickTimer::EnableInterrupt();
79GetCurrentDispatcher().SetTimerFunc(&GetTickCount);
80Blink();
81
82while (true)
83{
84GetCurrentDispatcher().Poll();
85Watchdog::Reset();
86}
87return 0;
88}