Skip to content

Commit

Permalink
[board] Add Nucleo_L031K6 BSP
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-durand committed Apr 1, 2021
1 parent d04fa96 commit 26d4909
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 9 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,18 +487,19 @@ 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-g431kb">NUCLEO-G431KB</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-g431rb">NUCLEO-G431RB</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-g474re">NUCLEO-G474RE</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-l031k6">NUCLEO-L031K6</a></td>
</tr><tr>
<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>
<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-olimexino-stm32">OLIMEXINO-STM32</a></td>
</tr><tr>
<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>
<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-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>
</tr>
</table>
<!--/bsptable-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ using D3 = GpioB0;
using D4 = GpioB7;
using D5 = GpioB6;
using D6 = GpioB1;
%% if has_gpio_c14_c15
using D7 = GpioC14;
using D8 = GpioC15;
%% else
using D7 = GpioF0;
using D8 = GpioF1;
%% endif
using D9 = GpioA8;
using D10 = GpioA11;
using D11 = GpioB5;
Expand Down
5 changes: 3 additions & 2 deletions src/modm/board/nucleo_f031k6/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ def build(env):
env.outbasepath = "modm/src/modm/board"
env.substitutions = {
"with_logger": True,
"with_assert": env.has_module(":architecture:assert")
"with_assert": env.has_module(":architecture:assert"),
"has_gpio_c14_c15": False
}
env.template("../board.cpp.in", "board.cpp")
env.copy('.')
env.copy("../nucleo32_arduino.hpp", "nucleo32_arduino.hpp")
env.template("../nucleo32_arduino.hpp.in", "nucleo32_arduino.hpp")
env.collect(":build:openocd.source", "board/st_nucleo_f0.cfg");
5 changes: 3 additions & 2 deletions src/modm/board/nucleo_f042k6/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ def build(env):
env.outbasepath = "modm/src/modm/board"
env.substitutions = {
"with_logger": True,
"with_assert": env.has_module(":architecture:assert")
"with_assert": env.has_module(":architecture:assert"),
"has_gpio_c14_c15": False
}
env.template("../board.cpp.in", "board.cpp")
env.copy('.')
env.copy("../nucleo32_arduino.hpp", "nucleo32_arduino.hpp")
env.template("../nucleo32_arduino.hpp.in", "nucleo32_arduino.hpp")
env.collect(":build:openocd.source", "board/st_nucleo_f0.cfg");
5 changes: 3 additions & 2 deletions src/modm/board/nucleo_f303k8/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ def build(env):
env.outbasepath = "modm/src/modm/board"
env.substitutions = {
"with_logger": True,
"with_assert": env.has_module(":architecture:assert")
"with_assert": env.has_module(":architecture:assert"),
"has_gpio_c14_c15": False
}
env.template("../board.cpp.in", "board.cpp")
env.copy('.')
env.copy("../nucleo32_arduino.hpp", "nucleo32_arduino.hpp")
env.template("../nucleo32_arduino.hpp.in", "nucleo32_arduino.hpp")
env.collect(":build:openocd.source", "board/st_nucleo_f3.cfg");
112 changes: 112 additions & 0 deletions src/modm/board/nucleo_l031k6/board.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright (c) 2016-2018, Niklas Hauser
* Copyright (c) 2017, Nick Sarten
* Copyright (c) 2017, Sascha Schade
* Copyright (c) 2021, Christopher Durand
*
* 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_L031K6_HPP
#define MODM_STM32_NUCLEO_L031K6_HPP

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

using namespace modm::platform;

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

/// STM32L031K6 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 Apb1Timer = Apb1;
static constexpr uint32_t Apb2Timer = Apb2;

static constexpr uint32_t Adc = Apb2;

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

static constexpr uint32_t I2c1 = Apb1;

static constexpr uint32_t Spi1 = Apb2;

static constexpr uint32_t Timer2 = Apb1Timer;
static constexpr uint32_t Timer21 = Apb2Timer;
static constexpr uint32_t Timer22 = Apb2Timer;

static constexpr uint32_t Usart2 = Apb1;

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 Nano Footprint
#include "nucleo32_arduino.hpp"

using Button = GpioUnused;
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_L031K6_HPP
17 changes: 17 additions & 0 deletions src/modm/board/nucleo_l031k6/board.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<library>
<repositories>
<repository>
<path>../../../../repo.lb</path>
</repository>
</repositories>

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

<option name="modm:platform:uart:2:buffer.tx">256</option>
<option name="modm:platform:cortex-m:main_stack_size">1024</option>
</options>
<modules>
<module>modm:board:nucleo-l031k6</module>
</modules>
</library>
44 changes: 44 additions & 0 deletions src/modm/board/nucleo_l031k6/module.lb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016-2018, Niklas Hauser
# Copyright (c) 2017, Fabian Greif
# Copyright (c) 2021, Christopher Durand
#
# 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-l031k6"
module.description = """\
# NUCLEO-L031K6
[Nucleo kit for STM32L031K6](https://www.st.com/en/evaluation-tools/nucleo-l031k6.html)
"""

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

module.depends(":platform:core", ":platform:gpio", ":platform:clock", ":platform:uart:2",
":debug", ":architecture:clock", ":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"),
"has_gpio_c14_c15": True
}
env.template("../board.cpp.in", "board.cpp")
env.copy('.')
env.template("../nucleo32_arduino.hpp.in", "nucleo32_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");
11 changes: 11 additions & 0 deletions tools/openocd/modm/st_nucleo_l0.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Should work with all STM32L0 Nucleo Dev Boards.
# http://www.st.com/en/evaluation-tools/stm32-mcu-nucleo.html

source [find interface/stlink.cfg]

transport select hla_swd

source [find target/stm32l0.cfg]

# use hardware reset
reset_config srst_only srst_nogate

0 comments on commit 26d4909

Please sign in to comment.