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

Feature/bsp for nucleo f303re #376

Merged
merged 1 commit into from
Apr 14, 2020
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 .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
- run:
name: Examples STM32F3 Series
command: |
(cd examples && ../tools/scripts/examples_compile.py stm32f3_discovery nucleo_f303k8)
(cd examples && ../tools/scripts/examples_compile.py stm32f3_discovery nucleo_f303k8 nucleo_f303re)
- run:
name: Examples STM32F7 Series
command: |
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,20 @@ documentation.
</tr><tr>
<td align="center">NUCLEO-F103RB</td>
<td align="center">NUCLEO-F303K8</td>
<td align="center">NUCLEO-F303RE</td>
<td align="center">NUCLEO-F401RE</td>
<td align="center">NUCLEO-F411RE</td>
</tr><tr>
<td align="center">NUCLEO-F411RE</td>
<td align="center">NUCLEO-F429ZI</td>
<td align="center">NUCLEO-F446RE</td>
<td align="center">NUCLEO-G071RB</td>
<td align="center">NUCLEO-G474RE</td>
</tr><tr>
<td align="center">NUCLEO-G474RE</td>
<td align="center">NUCLEO-L152RE</td>
<td align="center">NUCLEO-L432KC</td>
<td align="center">NUCLEO-L476RG</td>
<td align="center">OLIMEXINO-STM32</td>
</tr><tr>
<td align="center">OLIMEXINO-STM32</td>
<td align="center">STM32F030F4P6-DEMO</td>
</tr>
</table>
Expand Down
40 changes: 40 additions & 0 deletions examples/nucleo_f303re/blink/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2016-2017, Niklas Hauser
salkinium marked this conversation as resolved.
Show resolved Hide resolved
*
* 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_ms(Button::read() ? 100 : 500);

MODM_LOG_INFO << "loop: " << counter++ << modm::endl;
}

return 0;
}
9 changes: 9 additions & 0 deletions examples/nucleo_f303re/blink/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<library>
<extends>modm:nucleo-f303re</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_f303re/blink</option>
</options>
<modules>
<module>modm:build:scons</module>
</modules>
</library>
52 changes: 52 additions & 0 deletions examples/nucleo_f303re/itm/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2019, Niklas Hauser
*
* 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/processing.hpp>

using namespace Board;

modm::IODeviceWrapper<Itm, modm::IOBuffer::DiscardIfFull> itm_device;
modm::IOStream stream(itm_device);

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

// Done by OpenOCD: scons itm fcpu=64000000
// Itm::initialize<Board::SystemClock, 500_kHz>();
// Itm::connect<GpioB3::Traceswo>();

stream << "Hello from the SWO." << modm::endl;
stream << "debug" << modm::endl;
stream << "info" << modm::endl;
stream << "warning" << modm::endl;
stream << "error" << modm::endl;


while (true)
{
static modm::PeriodicTimer tmr{500ms};
if (tmr.execute())
{
tmr.restart(Button::read() ? 100ms : 500ms);
LedD13::toggle();

static uint32_t counter{0};
stream << "loop: " << counter++ << modm::endl;
}
Itm::update();
}

return 0;
}
12 changes: 12 additions & 0 deletions examples/nucleo_f303re/itm/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<library>
<extends>modm:nucleo-f303re</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_f303re/itm</option>
<option name="modm:platform:itm:buffer.tx">250</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:platform:itm</module>
<module>modm:processing:timer</module>
</modules>
</library>
80 changes: 80 additions & 0 deletions examples/nucleo_f303re/rtos/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2014, Georgi Grinshpun
* Copyright (c) 2014, Sascha Schade
* Copyright (c) 2015-2017, 2019 Niklas Hauser
*
* 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/processing/rtos.hpp>

using namespace modm::platform;
using namespace modm::literals;

/**
* This example uses four threads to check if task switching works correctly.
*
* What to expect?
* ---------------
* - All our LEDs blinking at different rates, about 3 to 4 Hz
* - A string at 115200 baud
*
* 0aA!1bB"2cC#3dD$4eE%5fF&6gG'7hH(8iI9)jJ0*aA1!bB2"cC
*
* Each thread prints out a sequence
* 0123456789
* abcdefghij
* ABCDEFGHIJ
* !"#$%&'()*
* respectivly.
*/

// ----------------------------------------------------------------------------
template <typename Gpio, int SleepTime>
class P: modm::rtos::Thread
{
char c;
uint8_t i = 0;
volatile float a = 10.f;
public:
P(char c): Thread(2,1<<10), c(c) {}

void run()
{
Gpio::setOutput();
while (true)
{
sleep(SleepTime * MILLISECONDS);

Gpio::toggle();
{
static modm::rtos::Mutex lm;
modm::rtos::MutexGuard m(lm);
MODM_LOG_INFO << char(i + c);
}
i = (i+1)%10;
a *= 3.141f;
}
}
};

P< Board::LedD13, 260 > p1('0');
P< Board::LedD13, 260 + 10 > p2('a');
P< Board::LedD13, 260 + 20 > p3('A');
P< Board::LedD13, 260 + 30 > p4('!');


// ----------------------------------------------------------------------------
int
main()
{
Board::initialize();
modm::rtos::Scheduler::schedule();
return 0;
}
11 changes: 11 additions & 0 deletions examples/nucleo_f303re/rtos/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<library>
<extends>modm:nucleo-f303re</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_f303re/rtos</option>
</options>
<modules>
<module>modm:processing:rtos</module>
<module>modm:platform:heap</module>
<module>modm:build:scons</module>
</modules>
</library>
119 changes: 119 additions & 0 deletions src/modm/board/nucleo_f303re/board.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* Copyright (c) 2016-2018, Niklas Hauser
* Copyright (c) 2017, Sascha Schade
salkinium marked this conversation as resolved.
Show resolved Hide resolved
*
* 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_NUCLEO_F303RE_HPP
#define MODM_STM32_NUCLEO_F303RE_HPP

#include <modm/platform.hpp>
#include <modm/architecture/interface/clock.hpp>
#include <modm/debug/logger.hpp>
/// @ingroup modm_board_nucleo_f303re
#define MODM_BOARD_HAS_LOGGER

using namespace modm::platform;

/// @ingroup modm_board_nucleo_f303re
namespace Board
{
using namespace modm::literals;

/// STM32F303RE running at 64MHz generated from the internal 8MHz clock
// Dummy clock for devices
struct SystemClock {
static constexpr uint32_t Frequency = 64_MHz;
static constexpr uint32_t Ahb = Frequency;
static constexpr uint32_t Apb1 = Frequency / 2;
static constexpr uint32_t Apb2 = Frequency;

static constexpr uint32_t Adc1 = Apb2;
static constexpr uint32_t Adc2 = Apb2;

static constexpr uint32_t Can = Apb1;

static constexpr uint32_t Spi1 = Apb2;

// USART1 is on APB2 bus, but default clock is PCLK1
static constexpr uint32_t Usart1 = Apb1;
static constexpr uint32_t Usart2 = Apb1;
static constexpr uint32_t Usart3 = Apb1;

// I2C1 clock source is HSI per default
static constexpr uint32_t I2c1 = 8_MHz;

static constexpr uint32_t Apb1Timer = Apb1 * 2;
static constexpr uint32_t Apb2Timer = Apb2 * 1;
static constexpr uint32_t Timer1 = Apb2Timer;
static constexpr uint32_t Timer2 = Apb1Timer;
static constexpr uint32_t Timer3 = Apb1Timer;
static constexpr uint32_t Timer6 = Apb1Timer;
static constexpr uint32_t Timer7 = Apb1Timer;
static constexpr uint32_t Timer15 = Apb2Timer;
static constexpr uint32_t Timer16 = Apb2Timer;
static constexpr uint32_t Timer17 = Apb2Timer;

static bool inline
enable()
{
Rcc::enableInternalClock(); // 8MHz
// 8MHz / 2 * 16 = 64MHz
const Rcc::PllFactors pllFactors{
.pllMul = 16,
.pllPrediv = 2,
};
Rcc::enablePll(Rcc::PllSource::InternalClock, pllFactors);
// set flash latency for 64MHz
Rcc::setFlashLatency<Frequency>();
// switch system clock to PLL output
Rcc::enableSystemClock(Rcc::SystemClockSource::Pll);
Rcc::setAhbPrescaler(Rcc::AhbPrescaler::Div1);
// APB1 has max. 36MHz
Rcc::setApb1Prescaler(Rcc::Apb1Prescaler::Div2);
Rcc::setApb2Prescaler(Rcc::Apb2Prescaler::Div1);
// update frequencies for busy-wait delay functions
Rcc::updateCoreFrequency<Frequency>();

return true;
}
};

// Arduino Footprint
#include "nucleo64_arduino.hpp"

using Button = GpioInverted<GpioInputC13>;
using LedD13 = D13;

using Leds = SoftwareGpioPort< LedD13 >;


namespace stlink
{
using Rx = GpioInputA15;
using Tx = GpioOutputA2;
using Uart = Usart2;
}

using LoggerDevice = modm::IODeviceWrapper< stlink::Uart, modm::IOBuffer::BlockIfFull >;


inline void
initialize()
{
SystemClock::enable();
SysTickTimer::initialize<SystemClock>();

stlink::Uart::connect<stlink::Tx::Tx, stlink::Rx::Rx>();
stlink::Uart::initialize<SystemClock, 115200_Bd>();
}

}

#endif // MODM_STM32_NUCLEO_F303RE_HPP
16 changes: 16 additions & 0 deletions src/modm/board/nucleo_f303re/board.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<library>
<repositories>
<repository>
<path>../../../../repo.lb</path>
</repository>
</repositories>

<options>
<option name="modm:target">stm32f303ret6</option>

<option name="modm:platform:uart:2:buffer.tx">2048</option>
</options>
<modules>
<module>modm:board:nucleo-f303re</module>
</modules>
</library>
Loading