Skip to content

Commit a7cfe65

Browse files
committed
[examples] Add NUCLEO-C031C6 board examples
1 parent 37d5c36 commit a7cfe65

File tree

15 files changed

+501
-11
lines changed

15 files changed

+501
-11
lines changed

.github/workflows/linux.yml

+4
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ jobs:
135135
- name: Update lbuild
136136
run: |
137137
pip3 install --upgrade --upgrade-strategy=eager modm
138+
- name: Examples STM32C0 Series
139+
if: always()
140+
run: |
141+
(cd examples && ../tools/scripts/examples_compile.py nucleo_c031c6)
138142
- name: Examples STM32F0 Series
139143
if: always()
140144
run: |

README.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -658,59 +658,60 @@ We have out-of-box support for many development boards including documentation.
658658
</tr><tr>
659659
<td align="center"><a href="https://modm.io/reference/config/modm-feather-rp2040">FEATHER-RP2040</a></td>
660660
<td align="center"><a href="https://modm.io/reference/config/modm-mega-2560-pro">MEGA-2560-PRO</a></td>
661+
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-c031c6">NUCLEO-C031C6</a></td>
661662
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f031k6">NUCLEO-F031K6</a></td>
662-
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f042k6">NUCLEO-F042K6</a></td>
663663
</tr><tr>
664+
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f042k6">NUCLEO-F042K6</a></td>
664665
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f072rb">NUCLEO-F072RB</a></td>
665666
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f091rc">NUCLEO-F091RC</a></td>
666667
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f103rb">NUCLEO-F103RB</a></td>
667-
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f303k8">NUCLEO-F303K8</a></td>
668668
</tr><tr>
669+
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f303k8">NUCLEO-F303K8</a></td>
669670
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f303re">NUCLEO-F303RE</a></td>
670671
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f334r8">NUCLEO-F334R8</a></td>
671672
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f401re">NUCLEO-F401RE</a></td>
672-
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f411re">NUCLEO-F411RE</a></td>
673673
</tr><tr>
674+
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f411re">NUCLEO-F411RE</a></td>
674675
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f429zi">NUCLEO-F429ZI</a></td>
675676
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f439zi">NUCLEO-F439ZI</a></td>
676677
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f446re">NUCLEO-F446RE</a></td>
677-
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f446ze">NUCLEO-F446ZE</a></td>
678678
</tr><tr>
679+
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f446ze">NUCLEO-F446ZE</a></td>
679680
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f746zg">NUCLEO-F746ZG</a></td>
680681
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f767zi">NUCLEO-F767ZI</a></td>
681682
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-g070rb">NUCLEO-G070RB</a></td>
682-
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-g071rb">NUCLEO-G071RB</a></td>
683683
</tr><tr>
684+
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-g071rb">NUCLEO-G071RB</a></td>
684685
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-g431kb">NUCLEO-G431KB</a></td>
685686
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-g431rb">NUCLEO-G431RB</a></td>
686687
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-g474re">NUCLEO-G474RE</a></td>
687-
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-h723zg">NUCLEO-H723ZG</a></td>
688688
</tr><tr>
689+
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-h723zg">NUCLEO-H723ZG</a></td>
689690
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-h743zi">NUCLEO-H743ZI</a></td>
690691
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l031k6">NUCLEO-L031K6</a></td>
691692
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l053r8">NUCLEO-L053R8</a></td>
692-
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l152re">NUCLEO-L152RE</a></td>
693693
</tr><tr>
694+
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l152re">NUCLEO-L152RE</a></td>
694695
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l432kc">NUCLEO-L432KC</a></td>
695696
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l452re">NUCLEO-L452RE</a></td>
696697
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l476rg">NUCLEO-L476RG</a></td>
697-
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l496zg-p">NUCLEO-L496ZG-P</a></td>
698698
</tr><tr>
699+
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l496zg-p">NUCLEO-L496ZG-P</a></td>
699700
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l552ze-q">NUCLEO-L552ZE-Q</a></td>
700701
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-u575zi-q">NUCLEO-U575ZI-Q</a></td>
701702
<td align="center"><a href="https://modm.io/reference/config/modm-olimexino-stm32">OLIMEXINO-STM32</a></td>
702-
<td align="center"><a href="https://modm.io/reference/config/modm-rp-pico">Raspberry Pi Pico</a></td>
703703
</tr><tr>
704+
<td align="center"><a href="https://modm.io/reference/config/modm-rp-pico">Raspberry Pi Pico</a></td>
704705
<td align="center"><a href="https://modm.io/reference/config/modm-samd21-mini">SAMD21-MINI</a></td>
705706
<td align="center"><a href="https://modm.io/reference/config/modm-samd21-xplained-pro">SAMD21-XPLAINED-PRO</a></td>
706707
<td align="center"><a href="https://modm.io/reference/config/modm-same54-xplained-pro">SAME54-XPLAINED-PRO</a></td>
707-
<td align="center"><a href="https://modm.io/reference/config/modm-same70-xplained">SAME70-XPLAINED</a></td>
708708
</tr><tr>
709+
<td align="center"><a href="https://modm.io/reference/config/modm-same70-xplained">SAME70-XPLAINED</a></td>
709710
<td align="center"><a href="https://modm.io/reference/config/modm-samg55-xplained-pro">SAMG55-XPLAINED-PRO</a></td>
710711
<td align="center"><a href="https://modm.io/reference/config/modm-samv71-xplained-ultra">SAMV71-XPLAINED-ULTRA</a></td>
711712
<td align="center"><a href="https://modm.io/reference/config/modm-srxe">Smart Response XE</a></td>
712-
<td align="center"><a href="https://modm.io/reference/config/modm-stm32_f4ve">STM32-F4VE</a></td>
713713
</tr><tr>
714+
<td align="center"><a href="https://modm.io/reference/config/modm-stm32_f4ve">STM32-F4VE</a></td>
714715
<td align="center"><a href="https://modm.io/reference/config/modm-stm32f030_demo">STM32F030-DEMO</a></td>
715716
<td align="center"><a href="https://modm.io/reference/config/modm-thingplus-rp2040">THINGPLUS-RP2040</a></td>
716717
</tr>

examples/nucleo_c031c6/adc/main.cpp

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2024, Jörg Ebeling
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+
#include <modm/board.hpp>
12+
13+
using namespace Board;
14+
15+
/*
16+
* This example demonstrates the usage of the ADC peripheral.
17+
* Connect two potentiometers to A0 and A1 to get reasonable readings or just
18+
* touch the two pins with your fingers to get ... interesting readings.
19+
* Make sure you're not too charged up with static electricity!
20+
*/
21+
22+
int
23+
main()
24+
{
25+
Board::initialize();
26+
Board::LedD13::setOutput();
27+
28+
Adc1::connect<GpioA0::In0, GpioA1::In1>();
29+
Adc1::initialize<Board::SystemClock, Adc1::ClockMode::Asynchronous,
30+
24_MHz>(); // 24MHz/160.5 sample time=6.6us (fulfill Ts_temp of 5us)
31+
32+
Adc1::setResolution(Adc1::Resolution::Bits12);
33+
Adc1::setSampleTime(Adc1::SampleTime::Cycles160_5);
34+
Adc1::setRightAdjustResult();
35+
Adc1::enableOversampling(Adc1::OversampleRatio::x16, Adc1::OversampleShift::Div16);
36+
37+
while (true)
38+
{
39+
Board::LedD13::toggle();
40+
modm::delay(500ms);
41+
42+
const uint16_t vref = Adc1::readInternalVoltageReference();
43+
MODM_LOG_INFO.printf("Vref=%4humV T=%2hu°C A0=%4humV A1=%4humV\n",
44+
vref, Adc1::readTemperature(vref),
45+
(vref * Adc1::readChannel(Adc1::Channel::In0) / 0xFFF),
46+
(vref * Adc1::readChannel(Adc1::Channel::In1) / 0xFFF));
47+
}
48+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<library>
2+
<extends>modm:nucleo-c031c6</extends>
3+
<options>
4+
<option name="modm:build:build.path">../../../build/nucleo_c031c6/adc</option>
5+
</options>
6+
<modules>
7+
<module>modm:build:scons</module>
8+
<module>modm:platform:adc</module>
9+
</modules>
10+
</library>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright (c) 2024, Jörg Ebeling
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+
#include <modm/board.hpp>
12+
#include <array>
13+
14+
using namespace Board;
15+
16+
/*
17+
* This example demonstrates the usage of the ADC peripheral.
18+
* Connect two potentiometers to A0 and A1 to get reasonable readings or just
19+
* touch the two pins with your fingers to get ... interesting readings.
20+
* Make sure you're not too charged up with static electricity!
21+
*
22+
* NOTE: the readings are raw ADC values and need to be converted to voltage!
23+
*/
24+
25+
std::array<uint16_t, 4> adc_data_buf;
26+
27+
static void
28+
adc_handler()
29+
{
30+
static uint8_t adc_data_idx = 0;
31+
32+
if (Adc1::getInterruptFlags() & Adc1::InterruptFlag::EndOfConversion)
33+
{
34+
Adc1::acknowledgeInterruptFlags(Adc1::InterruptFlag::EndOfConversion);
35+
adc_data_buf.at(adc_data_idx) = Adc1::getValue();
36+
adc_data_idx++;
37+
}
38+
if (Adc1::getInterruptFlags() & Adc1::InterruptFlag::EndOfSequence)
39+
{
40+
Adc1::acknowledgeInterruptFlags(Adc1::InterruptFlag::EndOfSequence);
41+
adc_data_idx = 0;
42+
}
43+
}
44+
45+
// ----------------------------------------------------------------------------
46+
int
47+
main()
48+
{
49+
Board::initialize();
50+
Board::LedD13::setOutput();
51+
MODM_LOG_INFO << "Board initialized" << modm::endl;
52+
53+
Adc1::connect<GpioA0::In0, GpioA1::In1>();
54+
Adc1::initialize<Board::SystemClock, Adc1::ClockMode::Asynchronous,
55+
24_MHz>(); // 24MHz/160.5 sample time=6.6us (fulfill Ts_temp of 5us)
56+
Adc1::setResolution(Adc1::Resolution::Bits12);
57+
Adc1::setRightAdjustResult();
58+
Adc1::setSampleTime(Adc1::SampleTime::Cycles160_5);
59+
60+
const Adc1::Channel sequence[4] = {Adc1::Channel::InternalReference, Adc1::Channel::In0,
61+
Adc1::Channel::In1, Adc1::Channel::Temperature};
62+
Adc1::setChannels(sequence);
63+
64+
Adc1::enableInterruptVector(15);
65+
Adc1::enableInterrupt(Adc1::Interrupt::EndOfConversion | Adc1::Interrupt::EndOfSequence);
66+
AdcInterrupt1::attachInterruptHandler(adc_handler);
67+
Adc1::enableFreeRunningMode();
68+
Adc1::startConversion();
69+
70+
while (true)
71+
{
72+
Board::LedD13::toggle();
73+
modm::delay(500ms);
74+
75+
MODM_LOG_INFO << "ADC: ";
76+
for (size_t i = 0; auto value : adc_data_buf)
77+
{
78+
MODM_LOG_INFO << i++ << "=" << value << " ";
79+
}
80+
MODM_LOG_INFO << modm::endl;
81+
}
82+
return 0;
83+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<library>
2+
<extends>modm:nucleo-c031c6</extends>
3+
<options>
4+
<option name="modm:build:build.path">../../../build/nucleo_c031c6/adc_sequence</option>
5+
</options>
6+
<modules>
7+
<module>modm:build:scons</module>
8+
<module>modm:platform:adc</module>
9+
</modules>
10+
</library>

examples/nucleo_c031c6/blink/main.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2016-2017, Niklas Hauser
3+
* Copyright (c) 2017, Nick Sarten
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+
#include <modm/board.hpp>
13+
14+
using namespace Board;
15+
16+
int
17+
main()
18+
{
19+
Board::initialize();
20+
LedD13::setOutput();
21+
22+
// Use the logging streams to print some messages.
23+
// Change MODM_LOG_LEVEL above to enable or disable these messages
24+
MODM_LOG_DEBUG << "debug" << modm::endl;
25+
MODM_LOG_INFO << "info" << modm::endl;
26+
MODM_LOG_WARNING << "warning" << modm::endl;
27+
MODM_LOG_ERROR << "error" << modm::endl;
28+
29+
uint32_t counter(0);
30+
31+
while (true)
32+
{
33+
LedD13::toggle();
34+
modm::delay(Button::read() ? 100ms : 500ms);
35+
36+
MODM_LOG_INFO << "loop: " << counter++ << modm::endl;
37+
}
38+
39+
return 0;
40+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<library>
2+
<extends>modm:nucleo-c031c6</extends>
3+
<options>
4+
<option name="modm:build:build.path">../../../build/nucleo_c031c6/blink</option>
5+
</options>
6+
<modules>
7+
<module>modm:build:scons</module>
8+
</modules>
9+
</library>

examples/nucleo_c031c6/timer/main.cpp

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2024, Jörg Ebeling
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+
#include <modm/board.hpp>
12+
13+
using namespace Board;
14+
15+
MODM_ISR(TIM14)
16+
{
17+
Timer14::acknowledgeInterruptFlags(Timer14::InterruptFlag::Update);
18+
MODM_LOG_DEBUG << "Set LED" << modm::endl;
19+
Board::LedD13::set();
20+
}
21+
22+
MODM_ISR(TIM16)
23+
{
24+
Timer16::acknowledgeInterruptFlags(Timer16::InterruptFlag::Update);
25+
MODM_LOG_DEBUG << "Reset LED" << modm::endl;
26+
Board::LedD13::reset();
27+
}
28+
29+
int
30+
main()
31+
{
32+
Board::initialize();
33+
Board::LedD13::setOutput();
34+
35+
MODM_LOG_INFO << "Board & Logger initialized" << modm::endl;
36+
37+
Timer14::enable();
38+
Timer14::setMode(Timer14::Mode::UpCounter);
39+
Timer14::setPeriod<Board::SystemClock>(1000ms);
40+
Timer14::applyAndReset();
41+
Timer14::enableInterrupt(Timer14::Interrupt::Update);
42+
Timer14::enableInterruptVector(true, 5);
43+
44+
Timer16::enable();
45+
Timer16::setMode(Timer16::Mode::UpCounter);
46+
Timer16::setPeriod<Board::SystemClock>(909ms);
47+
Timer16::applyAndReset();
48+
Timer16::enableInterrupt(Timer16::Interrupt::Update);
49+
Timer16::enableInterruptVector(true, 5);
50+
51+
Timer14::start();
52+
Timer16::start();
53+
54+
while (true) ;
55+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<library>
2+
<extends>modm:nucleo-c031c6</extends>
3+
<options>
4+
<option name="modm:build:build.path">../../../build/nucleo_c031c6/timer</option>
5+
</options>
6+
<modules>
7+
<module>modm:build:scons</module>
8+
<module>modm:platform:timer:14</module>
9+
<module>modm:platform:timer:16</module>
10+
</modules>
11+
</library>
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2017, Sascha Schade
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+
// Nucleo64 Arduino Header Footprint for STM32C031C6
13+
// Schematic: https://www.st.com/resource/en/schematic_pack/mb1549-u575ziq-c03_schematic.pdf
14+
15+
#ifndef MODM_STM32_NUCLEO64_ARDUINO_HPP
16+
#define MODM_STM32_NUCLEO64_ARDUINO_HPP
17+
18+
using A0 = GpioA0;
19+
using A1 = GpioA1;
20+
using A2 = GpioA4;
21+
using A3 = GpioB1;
22+
using A4 = GpioA11;
23+
using A5 = GpioA12;
24+
25+
using D0 = GpioB7;
26+
using D1 = GpioB6;
27+
using D2 = GpioA10;
28+
using D3 = GpioB3;
29+
using D4 = GpioB10;
30+
using D5 = GpioB4;
31+
using D6 = GpioB5;
32+
using D7 = GpioA15;
33+
using D8 = GpioA9;
34+
using D9 = GpioC7;
35+
using D10 = GpioB0;
36+
using D11 = GpioA7;
37+
using D12 = GpioA6;
38+
using D13 = GpioA5;
39+
using D14 = GpioB9;
40+
using D15 = GpioB8;
41+
42+
#endif // MODM_STM32_NUCLEO64_ARDUINO_HPP

0 commit comments

Comments
 (0)