-
Notifications
You must be signed in to change notification settings - Fork 143
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
[stm32] Add comparator platform driver for f3 and l4 #41
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2018, Raphael Lehmann | ||
* | ||
* 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 <modm/platform/comp/comp_1.hpp> | ||
|
||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
Board::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; | ||
|
||
using Comparator = modm::platform::Comp1; | ||
|
||
Comparator::connect<GpioA0::Out, GpioA1::Inp>(); | ||
|
||
Comparator::initialize( | ||
Comparator::InvertingInput::Vref1Div2, | ||
Comparator::NonInvertingInput::GpioA1, | ||
Comparator::Hysteresis::NoHysteresis, | ||
Comparator::Mode::HighSpeed, | ||
Comparator::Polarity::NonInverted, | ||
false); | ||
|
||
while (1) | ||
{ | ||
modm::delayMilliseconds(250); | ||
MODM_LOG_INFO << "Comparator: " << Comparator::getOutput() << modm::endl; | ||
Board::LedD13::set(Comparator::getOutput()); | ||
} | ||
|
||
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,11 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<library> | ||
<extends>../../../src/modm/board/nucleo_l432kc/board.xml</extends> | ||
<options> | ||
<option name=":build.scons:build.path">../../../build/nucleo_l432kc/blink</option> | ||
</options> | ||
<modules> | ||
<module>modm:platform:comp:*</module> | ||
<module>: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,68 @@ | ||
/* | ||
* Copyright (c) 2018, Raphael Lehmann | ||
* | ||
* 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 <modm/debug/logger.hpp> | ||
|
||
#include <modm/platform/comp/comp_2.hpp> | ||
|
||
// Set the log level | ||
#undef MODM_LOG_LEVEL | ||
#define MODM_LOG_LEVEL modm::log::INFO | ||
|
||
// Create an IODeviceWrapper around the Uart Peripheral we want to use | ||
modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; | ||
|
||
// Set all four logger streams to use the UART | ||
modm::log::Logger modm::log::debug(loggerDevice); | ||
modm::log::Logger modm::log::info(loggerDevice); | ||
modm::log::Logger modm::log::warning(loggerDevice); | ||
modm::log::Logger modm::log::error(loggerDevice); | ||
|
||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
Board::LedNorth::setOutput(); | ||
|
||
// initialize Uart2 for MODM_LOG_ | ||
Usart2::connect<GpioOutputA2::Tx>(); | ||
Usart2::initialize<Board::systemClock, 115200>(); | ||
|
||
// 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; | ||
|
||
using Comparator = modm::platform::Comp2; | ||
|
||
Comparator::connect<GpioA7::Inp, GpioA2::Out>(); | ||
|
||
Comparator::initialize( | ||
Comparator::InvertingInput::Vref1Div2, | ||
Comparator::NonInvertingInput::BitUnset, // GpioA7 | ||
Comparator::Output::Tim1Or8BkIn2, | ||
Comparator::Hysteresis::NoHysteresis, | ||
Comparator::Mode::HighSpeed, | ||
Comparator::Polarity::NonInverted, | ||
false); | ||
|
||
while (1) | ||
{ | ||
modm::delayMilliseconds(250); | ||
MODM_LOG_INFO << "Comparator: " << Comparator::getOutput() << modm::endl; | ||
Board::LedNorth::set(Comparator::getOutput()); | ||
} | ||
|
||
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,13 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<library> | ||
<extends>../../../src/modm/board/disco_f303vc/board.xml</extends> | ||
<options> | ||
<option name=":build.scons:build.path">../../../build/stm32f3_discovery/blink</option> | ||
</options> | ||
<modules> | ||
<module>:debug</module> | ||
<module>:platform:uart:2</module> | ||
<module>modm:platform:comp:*</module> | ||
<module>: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,66 @@ | ||
/* | ||
* Copyright (c) 2018, Raphael Lehmann | ||
* | ||
* 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/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#ifndef MODM_STM32_COMP_BASE_HPP | ||
#define MODM_STM32_COMP_BASE_HPP | ||
|
||
/** | ||
* @ingroup {{partname}} | ||
* @defgroup {{partname}}_comp Comparator | ||
*/ | ||
namespace modm::platform | ||
{ | ||
class CompBase | ||
{ | ||
public: | ||
enum class | ||
Mode | ||
{ | ||
{% if driver.type in ["stm32-v1.3"] -%} | ||
UltraLowPower = 0b00 << 2, | ||
LowPower = 0b01 << 2, | ||
MediumSpeed = 0b10 << 2, | ||
HighSpeed = 0b11 << 2, | ||
{% elif driver.type in ["stm32-tsmc90_cube"] -%} | ||
HighSpeed = 0b00 << 2, | ||
MediumSpeed = 0b01 << 2, | ||
//MediumSpeed2 = 0b10 << 2, | ||
UltraLowPower = 0b11 << 2, | ||
{% endif -%} | ||
}; | ||
protected: | ||
static constexpr uint32_t ModeMask = 0b11 << 2; | ||
|
||
public: | ||
enum class | ||
Polarity | ||
{ | ||
NonInverted = 0b0 << 15, | ||
Inverted = 0b1 << 15, | ||
}; | ||
protected: | ||
static constexpr uint32_t PolarityMask = 0b1 << 15; | ||
|
||
public: | ||
enum class | ||
Hysteresis | ||
{ | ||
NoHysteresis = 0b00 << 16, | ||
LowHysteresis = 0b01 << 16, | ||
MediumHysteresis = 0b10 << 16, | ||
HighHysteresis = 0b11 << 16, | ||
}; | ||
protected: | ||
static constexpr uint32_t HysteresisMask = 0b11 << 16; | ||
}; | ||
} | ||
|
||
#endif // MODM_STM32_COMP_BASE_HPP |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be renamed in this file:
https://github.com/modm-io/modm-devices/blob/develop/tools/generator/dfg/stm32/stm_peripherals.py
Would it be a lot of work to check the binary compatiblity of all STM32 Comp devices and add them too?
You'd need to compare the peripheral memory map overview of all devices with this functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea how the different comparator IPs should be grouped, so I don't think a renaming makes sense at the moment:
I don't think it makes sense to compare the memory maps. I prefer to wait a few weeks and compare the data of the register descriptions from the PDF data sheets.
The memory maps of L43x and F303/F3x8 look very similar, but some bits have other meaning: On L43x the HighSpeed mode is
0b00
, on F303/F3x8 the same bit have to be0b11
to enable the HighSpeed mode 😒Data about the configurations of the input- or output- selection (etc.) bits is not present in the memory maps and CMSIS header files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Someone is optimistic 😳