Skip to content
This repository has been archived by the owner on Jan 7, 2019. It is now read-only.

Add STM32F0 Discovery board with basic examples. #284

Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Here is a list of supported **and tested** microcontrollers and development boar
| ATtiny85 | custom | ★★★ |
| ATmega328p | [Arduino Uno][] | ★★★ |
| STM32F031 | [Nucleo F031K6][] | ★★★★ |
| STM32F051 | [STM32F0 Discovery][] | ★★ |
Copy link
Member

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 ;-)

| STM32F072 | [STM32F072 Discovery][] | ★★★★ |
| STM32F100 | [STM32F1 Discovery][] | ★★★ |
| STM32F103 | [Nucleo F103RB][] | ★★★ |
Expand Down
1 change: 1 addition & 0 deletions examples/generic/blinky/project.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#board = nucleo_f411re
#board = nucleo_f429zi
board = nucleo_l476rg
#board = stm32f0_discovery
#board = stm32f072_discovery
#board = stm32f103c8t6_blue_pill
#board = stm32f1_discovery
Expand Down
4 changes: 4 additions & 0 deletions examples/stm32f0_discovery/blink/SConstruct
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')
18 changes: 18 additions & 0 deletions examples/stm32f0_discovery/blink/main.cpp
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);
}
}
3 changes: 3 additions & 0 deletions examples/stm32f0_discovery/blink/project.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build]
board = stm32f0_discovery
buildpath = ${xpccpath}/build/stm32f0_discovery/${name}
4 changes: 4 additions & 0 deletions examples/stm32f0_discovery/logger/SConstruct
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')
54 changes: 54 additions & 0 deletions examples/stm32f0_discovery/logger/main.cpp
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;
}
}
3 changes: 3 additions & 0 deletions examples/stm32f0_discovery/logger/project.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build]
board = stm32f0_discovery
buildpath = ${xpccpath}/build/stm32f0_discovery/${name}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ struct systemClock
static bool inline
enable()
{
// Enable the interal 48MHz clock
ClockControl::enableInternalClockMHz48();
// Enable the internal 48MHz clock
// set flash latency for 48MHz
ClockControl::setFlashLatency(Frequency);
// Switch to the 48MHz clock
Expand Down
10 changes: 10 additions & 0 deletions src/xpcc/architecture/platform/board/stm32f0_discovery/board.cfg
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
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