-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[examples] Add NUCLEO-C031C6 board examples
- Loading branch information
Showing
15 changed files
with
501 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2024, Jörg Ebeling | ||
* | ||
* 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> | ||
|
||
using namespace Board; | ||
|
||
/* | ||
* This example demonstrates the usage of the ADC peripheral. | ||
* Connect two potentiometers to A0 and A1 to get reasonable readings or just | ||
* touch the two pins with your fingers to get ... interesting readings. | ||
* Make sure you're not too charged up with static electricity! | ||
*/ | ||
|
||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
Board::LedD13::setOutput(); | ||
|
||
Adc1::connect<GpioA0::In0, GpioA1::In1>(); | ||
Adc1::initialize<Board::SystemClock, Adc1::ClockMode::Asynchronous, | ||
24_MHz>(); // 24MHz/160.5 sample time=6.6us (fulfill Ts_temp of 5us) | ||
|
||
Adc1::setResolution(Adc1::Resolution::Bits12); | ||
Adc1::setSampleTime(Adc1::SampleTime::Cycles160_5); | ||
Adc1::setRightAdjustResult(); | ||
Adc1::enableOversampling(Adc1::OversampleRatio::x16, Adc1::OversampleShift::Div16); | ||
|
||
while (true) | ||
{ | ||
Board::LedD13::toggle(); | ||
modm::delay(500ms); | ||
|
||
const uint16_t vref = Adc1::readInternalVoltageReference(); | ||
MODM_LOG_INFO.printf("Vref=%4humV T=%2hu°C A0=%4humV A1=%4humV\n", | ||
vref, Adc1::readTemperature(vref), | ||
(vref * Adc1::readChannel(Adc1::Channel::In0) / 0xFFF), | ||
(vref * Adc1::readChannel(Adc1::Channel::In1) / 0xFFF)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<library> | ||
<extends>modm:nucleo-c031c6</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/nucleo_c031c6/adc</option> | ||
</options> | ||
<modules> | ||
<module>modm:build:scons</module> | ||
<module>modm:platform:adc</module> | ||
</modules> | ||
</library> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright (c) 2024, Jörg Ebeling | ||
* | ||
* 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 <array> | ||
|
||
using namespace Board; | ||
|
||
/* | ||
* This example demonstrates the usage of the ADC peripheral. | ||
* Connect two potentiometers to A0 and A1 to get reasonable readings or just | ||
* touch the two pins with your fingers to get ... interesting readings. | ||
* Make sure you're not too charged up with static electricity! | ||
* | ||
* NOTE: the readings are raw ADC values and need to be converted to voltage! | ||
*/ | ||
|
||
std::array<uint16_t, 4> adc_data_buf; | ||
|
||
static void | ||
adc_handler() | ||
{ | ||
static uint8_t adc_data_idx = 0; | ||
|
||
if (Adc1::getInterruptFlags() & Adc1::InterruptFlag::EndOfConversion) | ||
{ | ||
Adc1::acknowledgeInterruptFlags(Adc1::InterruptFlag::EndOfConversion); | ||
adc_data_buf.at(adc_data_idx) = Adc1::getValue(); | ||
adc_data_idx++; | ||
} | ||
if (Adc1::getInterruptFlags() & Adc1::InterruptFlag::EndOfSequence) | ||
{ | ||
Adc1::acknowledgeInterruptFlags(Adc1::InterruptFlag::EndOfSequence); | ||
adc_data_idx = 0; | ||
} | ||
} | ||
|
||
// ---------------------------------------------------------------------------- | ||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
Board::LedD13::setOutput(); | ||
MODM_LOG_INFO << "Board initialized" << modm::endl; | ||
|
||
Adc1::connect<GpioA0::In0, GpioA1::In1>(); | ||
Adc1::initialize<Board::SystemClock, Adc1::ClockMode::Asynchronous, | ||
24_MHz>(); // 24MHz/160.5 sample time=6.6us (fulfill Ts_temp of 5us) | ||
Adc1::setResolution(Adc1::Resolution::Bits12); | ||
Adc1::setRightAdjustResult(); | ||
Adc1::setSampleTime(Adc1::SampleTime::Cycles160_5); | ||
|
||
const Adc1::Channel sequence[4] = {Adc1::Channel::InternalReference, Adc1::Channel::In0, | ||
Adc1::Channel::In1, Adc1::Channel::Temperature}; | ||
Adc1::setChannels(sequence); | ||
|
||
Adc1::enableInterruptVector(15); | ||
Adc1::enableInterrupt(Adc1::Interrupt::EndOfConversion | Adc1::Interrupt::EndOfSequence); | ||
AdcInterrupt1::attachInterruptHandler(adc_handler); | ||
Adc1::enableFreeRunningMode(); | ||
Adc1::startConversion(); | ||
|
||
while (true) | ||
{ | ||
Board::LedD13::toggle(); | ||
modm::delay(500ms); | ||
|
||
MODM_LOG_INFO << "ADC: "; | ||
for (size_t i = 0; auto value : adc_data_buf) | ||
{ | ||
MODM_LOG_INFO << i++ << "=" << value << " "; | ||
} | ||
MODM_LOG_INFO << modm::endl; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<library> | ||
<extends>modm:nucleo-c031c6</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/nucleo_c031c6/adc_sequence</option> | ||
</options> | ||
<modules> | ||
<module>modm:build:scons</module> | ||
<module>modm:platform:adc</module> | ||
</modules> | ||
</library> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2016-2017, Niklas Hauser | ||
* Copyright (c) 2017, Nick Sarten | ||
* | ||
* 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> | ||
|
||
using namespace Board; | ||
|
||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
LedD13::setOutput(); | ||
|
||
// Use the logging streams to print some messages. | ||
// Change MODM_LOG_LEVEL above to enable or disable these messages | ||
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); | ||
|
||
while (true) | ||
{ | ||
LedD13::toggle(); | ||
modm::delay(Button::read() ? 100ms : 500ms); | ||
|
||
MODM_LOG_INFO << "loop: " << counter++ << modm::endl; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<library> | ||
<extends>modm:nucleo-c031c6</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/nucleo_c031c6/blink</option> | ||
</options> | ||
<modules> | ||
<module>modm:build:scons</module> | ||
</modules> | ||
</library> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2024, Jörg Ebeling | ||
* | ||
* 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> | ||
|
||
using namespace Board; | ||
|
||
MODM_ISR(TIM14) | ||
{ | ||
Timer14::acknowledgeInterruptFlags(Timer14::InterruptFlag::Update); | ||
MODM_LOG_DEBUG << "Set LED" << modm::endl; | ||
Board::LedD13::set(); | ||
} | ||
|
||
MODM_ISR(TIM16) | ||
{ | ||
Timer16::acknowledgeInterruptFlags(Timer16::InterruptFlag::Update); | ||
MODM_LOG_DEBUG << "Reset LED" << modm::endl; | ||
Board::LedD13::reset(); | ||
} | ||
|
||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
Board::LedD13::setOutput(); | ||
|
||
MODM_LOG_INFO << "Board & Logger initialized" << modm::endl; | ||
|
||
Timer14::enable(); | ||
Timer14::setMode(Timer14::Mode::UpCounter); | ||
Timer14::setPeriod<Board::SystemClock>(1000ms); | ||
Timer14::applyAndReset(); | ||
Timer14::enableInterrupt(Timer14::Interrupt::Update); | ||
Timer14::enableInterruptVector(true, 5); | ||
|
||
Timer16::enable(); | ||
Timer16::setMode(Timer16::Mode::UpCounter); | ||
Timer16::setPeriod<Board::SystemClock>(909ms); | ||
Timer16::applyAndReset(); | ||
Timer16::enableInterrupt(Timer16::Interrupt::Update); | ||
Timer16::enableInterruptVector(true, 5); | ||
|
||
Timer14::start(); | ||
Timer16::start(); | ||
|
||
while (true) ; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<library> | ||
<extends>modm:nucleo-c031c6</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/nucleo_c031c6/timer</option> | ||
</options> | ||
<modules> | ||
<module>modm:build:scons</module> | ||
<module>modm:platform:timer:14</module> | ||
<module>modm:platform:timer:16</module> | ||
</modules> | ||
</library> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2017, Sascha Schade | ||
* | ||
* 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/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
// Nucleo64 Arduino Header Footprint for STM32C031C6 | ||
// Schematic: https://www.st.com/resource/en/schematic_pack/mb1549-u575ziq-c03_schematic.pdf | ||
|
||
#ifndef MODM_STM32_NUCLEO64_ARDUINO_HPP | ||
#define MODM_STM32_NUCLEO64_ARDUINO_HPP | ||
|
||
using A0 = GpioA0; | ||
using A1 = GpioA1; | ||
using A2 = GpioA4; | ||
using A3 = GpioB1; | ||
using A4 = GpioA11; | ||
using A5 = GpioA12; | ||
|
||
using D0 = GpioB7; | ||
using D1 = GpioB6; | ||
using D2 = GpioA10; | ||
using D3 = GpioB3; | ||
using D4 = GpioB10; | ||
using D5 = GpioB4; | ||
using D6 = GpioB5; | ||
using D7 = GpioA15; | ||
using D8 = GpioA9; | ||
using D9 = GpioC7; | ||
using D10 = GpioB0; | ||
using D11 = GpioA7; | ||
using D12 = GpioA6; | ||
using D13 = GpioA5; | ||
using D14 = GpioB9; | ||
using D15 = GpioB8; | ||
|
||
#endif // MODM_STM32_NUCLEO64_ARDUINO_HPP |
Oops, something went wrong.