This repository has been archived by the owner on Jan 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
Add STM32F0 Discovery board with basic examples. #284
Merged
strongly-typed
merged 4 commits into
roboterclubaachen:develop
from
strongly-typed:feature/stm32f0_discovery
Aug 24, 2017
Merged
Changes from 3 commits
Commits
Show all changes
4 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
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,4 @@ | ||
# path to the xpcc root directory | ||
xpccpath = '../../..' | ||
# execute the common SConstruct file | ||
execfile(xpccpath + '/scons/SConstruct') |
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,18 @@ | ||
#include <xpcc/architecture/platform.hpp> | ||
|
||
using namespace Board; | ||
|
||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
|
||
LedGreen::set(); | ||
LedBlue::reset(); | ||
|
||
while (true) { | ||
LedGreen::toggle(); | ||
LedBlue::toggle(); | ||
xpcc::delayMilliseconds(Board::Button::read() ? 500 : 1000); | ||
} | ||
} |
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,3 @@ | ||
[build] | ||
board = stm32f0_discovery | ||
buildpath = ${xpccpath}/build/stm32f0_discovery/${name} |
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,4 @@ | ||
# path to the xpcc root directory | ||
xpccpath = '../../..' | ||
# execute the common SConstruct file | ||
execfile(xpccpath + '/scons/SConstruct') |
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,54 @@ | ||
#include <xpcc/architecture/platform.hpp> | ||
#include <xpcc/debug/logger.hpp> | ||
#include <xpcc/processing/timer.hpp> | ||
|
||
// ---------------------------------------------------------------------------- | ||
// Set the log level | ||
#undef XPCC_LOG_LEVEL | ||
#define XPCC_LOG_LEVEL xpcc::log::INFO | ||
|
||
// Create an IODeviceWrapper around the Uart Peripheral we want to use | ||
xpcc::IODeviceWrapper< Usart1, xpcc::IOBuffer::BlockIfFull > loggerDevice; | ||
|
||
// Set all four logger streams to use the UART | ||
xpcc::log::Logger xpcc::log::debug(loggerDevice); | ||
xpcc::log::Logger xpcc::log::info(loggerDevice); | ||
xpcc::log::Logger xpcc::log::warning(loggerDevice); | ||
xpcc::log::Logger xpcc::log::error(loggerDevice); | ||
|
||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
|
||
// initialize Uart2 for XPCC_LOG_* | ||
GpioOutputA9::connect(Usart1::Tx); | ||
GpioInputA10::connect(Usart1::Rx, Gpio::InputType::PullUp); | ||
Usart1::initialize<Board::systemClock, 115200>(12); | ||
|
||
// Use the logging streams to print some messages. | ||
// Change XPCC_LOG_LEVEL above to enable or disable these messages | ||
XPCC_LOG_DEBUG << "debug" << xpcc::endl; | ||
XPCC_LOG_INFO << "info" << xpcc::endl; | ||
XPCC_LOG_WARNING << "warning" << xpcc::endl; | ||
XPCC_LOG_ERROR << "error" << xpcc::endl; | ||
|
||
Board::LedBlue::reset(); | ||
|
||
uint32_t ii(1); | ||
xpcc::Timeout timeout; | ||
|
||
while (true) { | ||
Board::LedBlue::set(); | ||
timeout.restart(100); | ||
while(not timeout.isExpired()) | ||
{}; | ||
|
||
Board::LedBlue::reset(); | ||
timeout.restart(900); | ||
while(not timeout.isExpired()) | ||
{}; | ||
|
||
XPCC_LOG_INFO << "Seconds since reboot: " << ii++ << xpcc::endl; | ||
} | ||
} |
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,3 @@ | ||
[build] | ||
board = stm32f0_discovery | ||
buildpath = ${xpccpath}/build/stm32f0_discovery/${name} |
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
10 changes: 10 additions & 0 deletions
10
src/xpcc/architecture/platform/board/stm32f0_discovery/board.cfg
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 @@ | ||
[build] | ||
device = stm32f051r8 | ||
|
||
[parameters] | ||
core.cortex.0.enable_hardfault_handler_led = true | ||
core.cortex.0.hardfault_handler_led_port = C | ||
core.cortex.0.hardfault_handler_led_pin = 8 | ||
|
||
[openocd] | ||
configfile = board/stm32f0discovery.cfg |
85 changes: 85 additions & 0 deletions
85
src/xpcc/architecture/platform/board/stm32f0_discovery/stm32f0_discovery.hpp
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,85 @@ | ||
// coding: utf-8 | ||
/* Copyright (c) 2017, Sascha Schade (strongly-typed) | ||
* All Rights Reserved. | ||
* | ||
* The file is part of the xpcc library and is released under the 3-clause BSD | ||
* license. See the file `LICENSE` for the full license governing this code. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
// | ||
// STM32F0DISCOVERY | ||
// Discovery kit for STM32F0 series | ||
// http://www.st.com/en/evaluation-tools/stm32f0discovery.html | ||
// | ||
|
||
#ifndef XPCC_STM32_F0_DISCOVERY_HPP | ||
#define XPCC_STM32_F0_DISCOVERY_HPP | ||
|
||
#include <xpcc/architecture/platform.hpp> | ||
|
||
using namespace xpcc::stm32; | ||
|
||
|
||
namespace Board | ||
{ | ||
|
||
/// STM32F0 running at 48MHz generated from the internal 8MHz with PLL. | ||
|
||
struct systemClock | ||
{ | ||
static constexpr int Frequency = MHz48; | ||
static constexpr int Usart1 = Frequency; | ||
static constexpr int Usart2 = Frequency; | ||
static constexpr int Spi2 = Frequency; | ||
|
||
static bool inline | ||
enable() | ||
{ | ||
// enable internal 8 MHz HSI RC clock | ||
ClockControl::enableInternalClock(); | ||
// (internal clock / 2) * 12 = 48MHz | ||
ClockControl::enablePll(ClockControl::PllSource::InternalClock, 12, 1); | ||
// set flash latency for 48MHz | ||
ClockControl::setFlashLatency(Frequency); | ||
// switch system clock to PLL output | ||
ClockControl::enableSystemClock(ClockControl::SystemClockSource::Pll); | ||
ClockControl::setAhbPrescaler(ClockControl::AhbPrescaler::Div1); | ||
ClockControl::setApbPrescaler(ClockControl::ApbPrescaler::Div1); | ||
// update frequencies for busy-wait delay functions | ||
xpcc::clock::fcpu = Frequency; | ||
xpcc::clock::fcpu_kHz = Frequency / 1000; | ||
xpcc::clock::fcpu_MHz = Frequency / 1000000; | ||
xpcc::clock::ns_per_loop = ::round(4000.f / (Frequency / 1000000)); | ||
|
||
return true; | ||
} | ||
}; | ||
|
||
|
||
using Button = GpioInputA0; | ||
|
||
using LedGreen = GpioOutputC9; | ||
using LedBlue = GpioOutputC8; | ||
|
||
using Leds = xpcc::SoftwareGpioPort< LedGreen, LedBlue >; | ||
|
||
|
||
inline void | ||
initialize() | ||
{ | ||
systemClock::enable(); | ||
xpcc::cortex::SysTickTimer::initialize<systemClock>(); | ||
|
||
LedGreen::setOutput(xpcc::Gpio::Low); | ||
LedBlue::setOutput(xpcc::Gpio::Low); | ||
|
||
Button::setInput(); | ||
Button::setInputTrigger(Gpio::InputTrigger::RisingEdge); | ||
Button::enableExternalInterrupt(); | ||
// Button::enableExternalInterruptVector(12); | ||
} | ||
|
||
} // namespace Board | ||
|
||
#endif // XPCC_STM32_F0_DISCOVERY_HPP |
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.
and this is missing a link ;-)