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

[board] Add NUCLEO-L053R8 board #756

Merged
merged 2 commits into from
Oct 21, 2021
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 .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ jobs:
- name: Examples STM32L0 Series
if: always()
run: |
(cd examples && ../tools/scripts/examples_compile.py nucleo_l031k6)
(cd examples && ../tools/scripts/examples_compile.py nucleo_l031k6 nucleo_l053r8)
- name: Examples STM32L1 Series
if: always()
run: |
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -556,20 +556,21 @@ We have out-of-box support for many development boards including documentation.
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-h743zi">NUCLEO-H743ZI</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-l031k6">NUCLEO-L031K6</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-l053r8">NUCLEO-L053R8</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-l152re">NUCLEO-L152RE</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-l432kc">NUCLEO-L432KC</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-l452re">NUCLEO-L452RE</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-l452re">NUCLEO-L452RE</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-l476rg">NUCLEO-L476RG</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-l496zg-p">NUCLEO-L496ZG-P</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-board-olimexino-stm32">OLIMEXINO-STM32</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-board-raspberrypi">Raspberry Pi</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-board-raspberrypi">Raspberry Pi</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-board-samd21-mini">SAMD21-MINI</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-board-samg55-xplained-pro">SAMG55-XPLAINED-PRO</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-board-stm32_f4ve">STM32-F4VE</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-board-stm32f030_demo">STM32F030-DEMO</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-board-stm32f030_demo">STM32F030-DEMO</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-board-srxe">Smart Response XE</a></td>
</tr>
</table>
Expand Down
40 changes: 40 additions & 0 deletions examples/nucleo_l053r8/blink/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2016-2017, Niklas Hauser
* Copyright (c) 2017, Nick Sarten
*
* 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(Button::read() ? 100ms : 500ms);

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

return 0;
}
9 changes: 9 additions & 0 deletions examples/nucleo_l053r8/blink/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<library>
<extends>modm:nucleo-l053r8</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_l053r8/blink</option>
</options>
<modules>
<module>modm:build:scons</module>
</modules>
</library>
118 changes: 118 additions & 0 deletions src/modm/board/nucleo_l053r8/board.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Copyright (c) 2021, 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/.
*/
// ----------------------------------------------------------------------------

#pragma once

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

using namespace modm::platform;

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

/// STM32L053R8 running at 32MHz generated from 16 MHz HSI16 clock
struct SystemClock
{
static constexpr uint32_t Frequency = 32_MHz;
static constexpr uint32_t Ahb = Frequency;
static constexpr uint32_t Apb1 = Frequency;
static constexpr uint32_t Apb2 = Frequency;

static constexpr uint32_t Adc = Apb2;

static constexpr uint32_t Dac = Apb1;

static constexpr uint32_t Comp1 = Apb2;
static constexpr uint32_t Comp2 = Apb2;

static constexpr uint32_t Spi1 = Apb2;
static constexpr uint32_t Spi2 = Apb1;

static constexpr uint32_t Usart1 = Apb2;
static constexpr uint32_t Usart2 = Apb1;

static constexpr uint32_t Lpuart1 = Apb1;

static constexpr uint32_t I2c1 = Apb1;
static constexpr uint32_t I2c2 = Apb1;

static constexpr uint32_t Usb = Apb1;

static constexpr uint32_t Apb1Timer = Apb1 * 1;
static constexpr uint32_t Apb2Timer = Apb2 * 1;
static constexpr uint32_t Timer2 = Apb1Timer;
static constexpr uint32_t Timer6 = Apb1Timer;
static constexpr uint32_t Timer21 = Apb2Timer;
static constexpr uint32_t Timer22 = Apb2Timer;

static bool inline
enable()
{
Rcc::enableInternalClock(); // 16MHz
// (internal clock / 1) * 4 / 2 = 32MHz
const Rcc::PllFactors pllFactors{
.pllMul = Rcc::PllMultiplier::Mul4,
.pllDiv = 2,
.enableHsiPrediv4 = false
};
Rcc::enablePll(Rcc::PllSource::Hsi16, pllFactors);
// set flash latency for 32MHz
Rcc::setFlashLatency<Frequency>();
// switch system clock to PLL output
Rcc::enableSystemClock(Rcc::SystemClockSource::Pll);
Rcc::setAhbPrescaler(Rcc::AhbPrescaler::Div1);
Rcc::setApb1Prescaler(Rcc::Apb1Prescaler::Div1);
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 = GpioInputA3;
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>();

Button::setInput();
}

}
16 changes: 16 additions & 0 deletions src/modm/board/nucleo_l053r8/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">stm32l053r8t6</option>

<option name="modm:platform:uart:2:buffer.tx">2048</option>
</options>
<modules>
<module>modm:board:nucleo-l053r8</module>
</modules>
</library>
42 changes: 42 additions & 0 deletions src/modm/board/nucleo_l053r8/module.lb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016-2018, Niklas Hauser
# Copyright (c) 2017, Fabian Greif
#
# 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/.
# -----------------------------------------------------------------------------

def init(module):
module.name = ":board:nucleo-l053r8"
module.description = """\
# NUCLEO-L053R8

[Nucleo kit for STM32L053R8](https://www.st.com/en/evaluation-tools/nucleo-l053r8.html)
"""

def prepare(module, options):
if not options[":target"].partname.startswith("stm32l053r8t"):
return False

module.depends(":platform:core", ":platform:gpio", ":platform:clock", ":platform:uart:2",
":debug", ":architecture:clock")
return True

def build(env):
env.outbasepath = "modm/src/modm/board"
env.substitutions = {
"with_logger": True,
"with_assert": env.has_module(":architecture:assert")
}
env.template("../board.cpp.in", "board.cpp")
env.copy('.')
env.copy("../nucleo64_arduino.hpp", "nucleo64_arduino.hpp")

env.outbasepath = "modm/openocd/modm/board/"
env.copy(repopath("tools/openocd/modm/st_nucleo_l0.cfg"), "st_nucleo_l0.cfg")
env.collect(":build:openocd.source", "modm/board/st_nucleo_l0.cfg")