Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add STM32H7 ADC driver + ADC injected conversions #1049

Merged
merged 4 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Please [discover modm's peripheral drivers for your specific device][discover].
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center"></td>
<td align="center"></td>
<td align="center">○</td>
<td align="center">✅</td>
<td align="center">✅</td>
Expand Down
56 changes: 56 additions & 0 deletions examples/nucleo_h723zg/adc_injected_conversion/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2023, Christopher Durand
*
* 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 <cstdint>
#include <modm/board.hpp>

using namespace Board;

int main()
{
Board::initialize();

Adc1::connect<A0::Inp15, A1::Inp10>();
Adc1::initialize(Adc1::ClockMode::SynchronousPrescaler4,
Adc1::ClockSource::NoClock,
Adc1::Prescaler::Disabled,
Adc1::CalibrationMode::SingleEndedInputsMode);

MODM_LOG_INFO << "ADC Injected Conversion Test\n";

Adc1::setInjectedConversionSequenceLength(4);
Adc1::setInjectedConversionChannel<A0>(0, Adc1::SampleTime::Cycles17);
Adc1::setInjectedConversionChannel<A1>(1, Adc1::SampleTime::Cycles17);
Adc1::setInjectedConversionChannel<A0>(2, Adc1::SampleTime::Cycles17);
Adc1::setInjectedConversionChannel<A1>(3, Adc1::SampleTime::Cycles17);

while (true) {
// start regular conversion
Adc1::setPinChannel<A1>(Adc1::SampleTime::Cycles17);
Adc1::startConversion();

Adc1::startInjectedConversionSequence();
while (!Adc1::isInjectedConversionFinished());

MODM_LOG_INFO << "ADC1 CH15 (injected): " << Adc1::getInjectedConversionValue(0) << '\n';
MODM_LOG_INFO << "ADC1 CH15 (injected): " << Adc1::getInjectedConversionValue(2) << '\n';
MODM_LOG_INFO << "ADC1 CH10 (injected): " << Adc1::getInjectedConversionValue(1) << '\n';
MODM_LOG_INFO << "ADC1 CH10 (injected): " << Adc1::getInjectedConversionValue(3) << '\n';

// wait for regular conversion to finish
while (!Adc1::isConversionFinished());
MODM_LOG_INFO << "ADC1 CH10 (regular): " << Adc1::getValue() << "\n\n";

Leds::toggle();
modm::delay_ms(500);
}

return 0;
}
10 changes: 10 additions & 0 deletions examples/nucleo_h723zg/adc_injected_conversion/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<library>
<extends>modm:nucleo-h723zg</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_h723zg/adc_injected_conversion</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:platform:adc:1</module>
</modules>
</library>
54 changes: 54 additions & 0 deletions examples/nucleo_h723zg/adc_simple/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2023, Christopher Durand
*
* 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 <cstdint>
#include <modm/board.hpp>

using namespace Board;

// ADC1 (16 bit) channel 15
using A0 = GpioA3;
// ADC3 (12 bit) channel 10
using A1 = GpioC0;

int main()
{
Board::initialize();

Adc1::connect<A0::Inp15>();
Adc1::initialize(Adc1::ClockMode::SynchronousPrescaler4,
Adc1::ClockSource::NoClock,
Adc1::Prescaler::Disabled,
Adc1::CalibrationMode::SingleEndedInputsMode);

Adc3::connect<A1::Inp10>();
Adc3::initialize(Adc3::ClockMode::SynchronousPrescaler4,
Adc3::ClockSource::NoClock,
Adc3::Prescaler::Disabled,
Adc3::CalibrationMode::SingleEndedInputsMode);

MODM_LOG_INFO << "ADC Test\n";

while (true) {
Adc1::setPinChannel<A0>(Adc1::SampleTime::Cycles17);
Adc1::startConversion();
while (!Adc1::isConversionFinished());
MODM_LOG_INFO << "ADC1 CH15: " << Adc1::getValue() << '\n';

Adc3::setPinChannel<A1>(Adc3::SampleTime::Cycles13);
Adc3::startConversion();
while (!Adc3::isConversionFinished());
MODM_LOG_INFO << "ADC3 CH10: " << Adc3::getValue() << '\n';

modm::delay_ms(500);
}

return 0;
}
10 changes: 10 additions & 0 deletions examples/nucleo_h723zg/adc_simple/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<library>
<extends>modm:nucleo-h723zg</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_h723zg/adc_simple</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:platform:adc:*</module>
</modules>
</library>
Loading
Loading