Skip to content

Commit

Permalink
[board] Add Nucleo-G431RB
Browse files Browse the repository at this point in the history
  • Loading branch information
rleh committed Dec 15, 2020
1 parent 7f93e20 commit 7e01640
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 4 deletions.
3 changes: 1 addition & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ jobs:
name: Examples STM32G4 Series
when: always
command: |
(cd examples && ../tools/scripts/examples_compile.py nucleo_g431kb nucleo_g474re)
(cd examples && ../tools/scripts/examples_compile.py nucleo_g474re nucleo_g431rb nucleo_g431kb)
stm32f4-examples:
docker:
- image: modm/modm-build:cortex-m
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,19 @@ documentation.
</tr><tr>
<td align="center">NUCLEO-G071RB</td>
<td align="center">NUCLEO-G431KB</td>
<td align="center">NUCLEO-G431RB</td>
<td align="center">NUCLEO-G474RE</td>
<td align="center">NUCLEO-L152RE</td>
</tr><tr>
<td align="center">NUCLEO-L152RE</td>
<td align="center">NUCLEO-L432KC</td>
<td align="center">NUCLEO-L476RG</td>
<td align="center">OLIMEXINO-STM32</td>
<td align="center">RASPBERRYPI</td>
</tr><tr>
<td align="center">RASPBERRYPI</td>
<td align="center">SAMD21-MINI</td>
<td align="center">STM32-F4VE</td>
<td align="center">STM32F030F4P6-DEMO</td>
</tr><tr>
</tr>
</table>
<!--/bsptable-->
Expand Down
142 changes: 142 additions & 0 deletions src/modm/board/nucleo_g431rb/board.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
* Copyright (c) 2020, Raphael Lehmann
*
* 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_G431RB_HPP
#define MODM_STM32_NUCLEO_G431RB_HPP

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

using namespace modm::platform;

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

/// STM32G431RB running at 170MHz generated from the internal 16MHz crystal
// Dummy clock for devices
struct SystemClock {
static constexpr uint32_t Frequency = 170_MHz;
static constexpr uint32_t Ahb1 = Frequency;
static constexpr uint32_t Ahb2 = Frequency;
static constexpr uint32_t Apb1 = Frequency;
static constexpr uint32_t Apb2 = Frequency;

static constexpr uint32_t Cordic = Ahb1;
static constexpr uint32_t Crc = Ahb1;
static constexpr uint32_t Dma = Ahb1;
static constexpr uint32_t Dma1 = Dma;
static constexpr uint32_t Dma2 = Dma;
static constexpr uint32_t DmaMux = Dma;
static constexpr uint32_t Fmac = Ahb1;

static constexpr uint32_t Adc = Ahb2;
static constexpr uint32_t Adc1 = Adc;
static constexpr uint32_t Adc2 = Adc;
static constexpr uint32_t Dac = Ahb2;
static constexpr uint32_t Dac1 = Dac;
static constexpr uint32_t Dac3 = Dac;
static constexpr uint32_t Rng = Ahb2;

static constexpr uint32_t Can = Apb1;
static constexpr uint32_t Fdcan1 = Can;
static constexpr uint32_t I2c = Apb1;
static constexpr uint32_t I2c1 = I2c;
static constexpr uint32_t I2c2 = I2c;
static constexpr uint32_t I2c3 = I2c;
static constexpr uint32_t Lpuart = Apb1;
static constexpr uint32_t Rtc = Apb1;
static constexpr uint32_t Spi2 = Apb1;
static constexpr uint32_t Spi3 = Apb1;
static constexpr uint32_t Usart2 = Apb1;
static constexpr uint32_t Usart3 = Apb1;
static constexpr uint32_t Usb = Apb1;
static constexpr uint32_t Apb1Timer = Apb1 * 1;
static constexpr uint32_t Timer2 = Apb1Timer;
static constexpr uint32_t Timer3 = Apb1Timer;
static constexpr uint32_t Timer4 = Apb1Timer;
static constexpr uint32_t Timer6 = Apb1Timer;
static constexpr uint32_t Timer7 = Apb1Timer;

static constexpr uint32_t Sai1 = Apb2;
static constexpr uint32_t Spi1 = Apb2;
static constexpr uint32_t Usart1 = Apb2;
static constexpr uint32_t Apb2Timer = Apb2 * 1;
static constexpr uint32_t Timer1 = Apb2Timer;
static constexpr uint32_t Timer8 = Apb2Timer;
static constexpr uint32_t Timer15 = Apb2Timer;
static constexpr uint32_t Timer16 = Apb2Timer;
static constexpr uint32_t Timer17 = Apb2Timer;

static bool inline
enable()
{
Rcc::enableInternalClock(); // 16MHz
Rcc::PllFactors pllFactors{
.pllM = 4, // 16MHz / M= 4 -> 4MHz
.pllN = 85, // 4MHz * N=85 -> 340MHz
.pllR = 2, // 336MHz / R= 2 -> 170MHz = F_cpu
};
Rcc::enablePll(Rcc::PllSource::InternalClock, pllFactors);
Rcc::setFlashLatency<Frequency>();
// switch system clock to PLL output
Rcc::enableSystemClock(Rcc::SystemClockSource::Pll);
Rcc::setAhbPrescaler(Rcc::AhbPrescaler::Div1);
// APB1 has max. 170MHz
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();
Button::setInputTrigger(Gpio::InputTrigger::RisingEdge);
Button::enableExternalInterrupt();
// Button::enableExternalInterruptVector(12);
}

}

#endif // MODM_STM32_NUCLEO_G431RB_HPP
16 changes: 16 additions & 0 deletions src/modm/board/nucleo_g431rb/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">stm32g431rbt6</option>

<option name="modm:platform:uart:2:buffer.tx">2048</option>
</options>
<modules>
<module>modm:board:nucleo-g431rb</module>
</modules>
</library>
41 changes: 41 additions & 0 deletions src/modm/board/nucleo_g431rb/module.lb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2020, Raphael Lehmann
#
# 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-g431rb"
module.description = """\
# NUCLEO-G431RB
[Nucleo kit for STM32G474RE](https://www.st.com/en/evaluation-tools/nucleo-g431rb.html)
"""

def prepare(module, options):
if not options[":target"].partname.startswith("stm32g431rbt"):
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_g4.cfg"), "st_nucleo_g4.cfg")
env.collect(":build:openocd.source", "modm/board/st_nucleo_g4.cfg")

0 comments on commit 7e01640

Please sign in to comment.