Skip to content
This repository was archived by the owner on Jan 7, 2019. It is now read-only.

Commit a1b5a1b

Browse files
rlehsalkinium
authored andcommitted
[examples] Nucleo-L432KC pwm example
1 parent b4b4915 commit a1b5a1b

3 files changed

Lines changed: 64 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# path to the xpcc root directory
2+
xpccpath = '../../..'
3+
# execute the common SConstruct file
4+
exec(compile(open(xpccpath + '/scons/SConstruct', "rb").read(), xpccpath + '/scons/SConstruct', 'exec'))
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <xpcc/architecture/platform.hpp>
2+
3+
using namespace Board;
4+
5+
#undef XPCC_LOG_LEVEL
6+
#define XPCC_LOG_LEVEL xpcc::log::INFO
7+
8+
// ----------------------------------------------------------------------------
9+
int
10+
main()
11+
{
12+
initialize();
13+
14+
XPCC_LOG_INFO << "Nucleo L432KC PWM example" << xpcc::endl;
15+
16+
LedGreen::set();
17+
18+
uint32_t counter = 0;
19+
20+
GpioOutputA8::connect(Timer1::Channel1);
21+
GpioOutputA9::connect(Timer1::Channel2);
22+
GpioOutputA10::connect(Timer1::Channel3);
23+
GpioOutputA11::connect(Timer1::Channel4);
24+
25+
Timer1::enable();
26+
Timer1::setMode(Timer1::Mode::UpCounter);
27+
28+
// 80 MHz / 800 / 2^16 ~ 1.5 Hz
29+
Timer1::setPrescaler(800);
30+
Timer1::setOverflow(65535);
31+
32+
33+
Timer1::configureOutputChannel(1, Timer2::OutputCompareMode::Pwm, 32767);
34+
Timer1::configureOutputChannel(2, Timer2::OutputCompareMode::Pwm, 32767);
35+
Timer1::configureOutputChannel(3, Timer2::OutputCompareMode::Pwm, 32767);
36+
Timer1::configureOutputChannel(4, Timer2::OutputCompareMode::Pwm, 32767);
37+
38+
Timer1::applyAndReset();
39+
40+
Timer1::start();
41+
Timer1::enableOutput();
42+
43+
while (true)
44+
{
45+
LedGreen::toggle();
46+
xpcc::delayMilliseconds(500);
47+
XPCC_LOG_INFO << "loop: " << counter++ << xpcc::endl;
48+
XPCC_LOG_INFO << "Timer1 counter: " << Timer1::getValue() << xpcc::endl;
49+
}
50+
51+
return 0;
52+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[build]
2+
board = nucleo_l432kc
3+
buildpath = ${xpccpath}/build/nucleo_l432kc/${name}
4+
5+
[parameters]
6+
core.cortex.0.enable_hardfault_handler_led = true
7+
core.cortex.0.hardfault_handler_led_port = B
8+
core.cortex.0.hardfault_handler_led_pin = 3

0 commit comments

Comments
 (0)