Skip to content

Commit

Permalink
[examples] Add NUCLEO-C031C6 board examples
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Sep 26, 2024
1 parent 37d5c36 commit a7cfe65
Show file tree
Hide file tree
Showing 15 changed files with 501 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ jobs:
- name: Update lbuild
run: |
pip3 install --upgrade --upgrade-strategy=eager modm
- name: Examples STM32C0 Series
if: always()
run: |
(cd examples && ../tools/scripts/examples_compile.py nucleo_c031c6)
- name: Examples STM32F0 Series
if: always()
run: |
Expand Down
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -658,59 +658,60 @@ We have out-of-box support for many development boards including documentation.
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-feather-rp2040">FEATHER-RP2040</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-mega-2560-pro">MEGA-2560-PRO</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-c031c6">NUCLEO-C031C6</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f031k6">NUCLEO-F031K6</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f042k6">NUCLEO-F042K6</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f042k6">NUCLEO-F042K6</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f072rb">NUCLEO-F072RB</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f091rc">NUCLEO-F091RC</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f103rb">NUCLEO-F103RB</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f303k8">NUCLEO-F303K8</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f303k8">NUCLEO-F303K8</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f303re">NUCLEO-F303RE</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f334r8">NUCLEO-F334R8</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f401re">NUCLEO-F401RE</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f411re">NUCLEO-F411RE</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f411re">NUCLEO-F411RE</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f429zi">NUCLEO-F429ZI</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f439zi">NUCLEO-F439ZI</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f446re">NUCLEO-F446RE</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f446ze">NUCLEO-F446ZE</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f446ze">NUCLEO-F446ZE</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f746zg">NUCLEO-F746ZG</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f767zi">NUCLEO-F767ZI</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-g070rb">NUCLEO-G070RB</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-g071rb">NUCLEO-G071RB</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-g071rb">NUCLEO-G071RB</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-g431kb">NUCLEO-G431KB</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-g431rb">NUCLEO-G431RB</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-g474re">NUCLEO-G474RE</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-h723zg">NUCLEO-H723ZG</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-h723zg">NUCLEO-H723ZG</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-h743zi">NUCLEO-H743ZI</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l031k6">NUCLEO-L031K6</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l053r8">NUCLEO-L053R8</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l152re">NUCLEO-L152RE</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l152re">NUCLEO-L152RE</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l432kc">NUCLEO-L432KC</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l452re">NUCLEO-L452RE</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l476rg">NUCLEO-L476RG</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l496zg-p">NUCLEO-L496ZG-P</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l496zg-p">NUCLEO-L496ZG-P</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l552ze-q">NUCLEO-L552ZE-Q</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-u575zi-q">NUCLEO-U575ZI-Q</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-olimexino-stm32">OLIMEXINO-STM32</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-rp-pico">Raspberry Pi Pico</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-rp-pico">Raspberry Pi Pico</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-samd21-mini">SAMD21-MINI</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-samd21-xplained-pro">SAMD21-XPLAINED-PRO</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-same54-xplained-pro">SAME54-XPLAINED-PRO</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-same70-xplained">SAME70-XPLAINED</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-same70-xplained">SAME70-XPLAINED</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-samg55-xplained-pro">SAMG55-XPLAINED-PRO</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-samv71-xplained-ultra">SAMV71-XPLAINED-ULTRA</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-srxe">Smart Response XE</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-stm32_f4ve">STM32-F4VE</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-stm32_f4ve">STM32-F4VE</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-stm32f030_demo">STM32F030-DEMO</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-thingplus-rp2040">THINGPLUS-RP2040</a></td>
</tr>
Expand Down
48 changes: 48 additions & 0 deletions examples/nucleo_c031c6/adc/main.cpp
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));
}
}
10 changes: 10 additions & 0 deletions examples/nucleo_c031c6/adc/project.xml
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>
83 changes: 83 additions & 0 deletions examples/nucleo_c031c6/adc_sequence/main.cpp
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;
}
10 changes: 10 additions & 0 deletions examples/nucleo_c031c6/adc_sequence/project.xml
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>
40 changes: 40 additions & 0 deletions examples/nucleo_c031c6/blink/main.cpp
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;
}
9 changes: 9 additions & 0 deletions examples/nucleo_c031c6/blink/project.xml
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>
55 changes: 55 additions & 0 deletions examples/nucleo_c031c6/timer/main.cpp
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) ;
}
11 changes: 11 additions & 0 deletions examples/nucleo_c031c6/timer/project.xml
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>
42 changes: 42 additions & 0 deletions src/modm/board/nucleo64_arduino_c0.hpp
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
Loading

0 comments on commit a7cfe65

Please sign in to comment.