Skip to content

Commit

Permalink
[stm32] Add support for STM32G0 device family
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Mar 6, 2019
1 parent c7b35ca commit 399a533
Show file tree
Hide file tree
Showing 22 changed files with 363 additions and 35 deletions.
23 changes: 23 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ jobs:
name: Examples STM32F7 Series
command: |
(cd examples && ../tools/scripts/examples_compile.py stm32f746g_discovery)
- run:
name: Examples STM32G0 Series
command: |
(cd examples && ../tools/scripts/examples_compile.py nucleo_g071rb)
- run:
name: Examples STM32L4 Series
command: |
Expand Down Expand Up @@ -234,6 +238,20 @@ jobs:
path: test/all/log
destination: log

stm32g0-compile-all:
docker:
- image: modm/modm-build:latest
steps:
- checkout
- run: (git submodule sync && git submodule update --init --jobs 8) & pip3 install -U lbuild & wait
- run:
name: Compile HAL for all STM32G0
command: |
(cd test/all && python3 run_all.py stm32g0)
- store_artifacts:
path: test/all/log
destination: log

build-docs:
docker:
- image: modm/modm-build:latest
Expand Down Expand Up @@ -302,6 +320,10 @@ workflows:
requires:
- unittests
- stm32-examples
- stm32g0-compile-all:
requires:
- unittests
- stm32-examples
- stm32l4-compile-all:
requires:
- unittests
Expand All @@ -315,5 +337,6 @@ workflows:
- stm32f3-compile-all
- stm32f4-compile-all
- stm32f7-compile-all
- stm32g0-compile-all
- stm32l4-compile-all

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ git clone --recurse-submodules https://github.com/modm-io/modm.git

## Targets

modm can generate code for <!--avrcount-->76<!--/avrcount--> AVR and <!--stmcount-->886<!--/stmcount-->
modm can generate code for <!--avrcount-->76<!--/avrcount--> AVR and <!--stmcount-->917<!--/stmcount-->
STM32 devices, however, there are different levels of support and testing.

<center>
Expand Down Expand Up @@ -134,10 +134,11 @@ documentation.
<td align="center">NUCLEO-F411RE</td>
</tr><tr>
<td align="center">NUCLEO-F429ZI</td>
<td align="center">NUCLEO-G071RB</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
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ make gdb

## Interesting Examples

We have a lot of examples, <!--examplecount-->168<!--/examplecount--> to be
We have a lot of examples, <!--examplecount-->169<!--/examplecount--> to be
exact, but here are some of our favorite examples for our supported development
boards:

Expand Down
40 changes: 40 additions & 0 deletions examples/nucleo_g071rb/blink/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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>

using namespace Board;

// ----------------------------------------------------------------------------
int
main()
{
Board::initialize();

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

LedD13::setOutput();
static uint8_t counter{0};

while (true)
{
LedD13::toggle();
modm::delayMilliseconds(Button::read() ? 500 : 1000);

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

return 0;
}
10 changes: 10 additions & 0 deletions examples/nucleo_g071rb/blink/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<library>
<extends>modm:nucleo-g071rb</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_g071rb/blink</option>
</options>
<modules>
<module>modm:platform:gpio</module>
<module>modm:build:scons</module>
</modules>
</library>
2 changes: 1 addition & 1 deletion ext/st/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def common_rcc_map(env):
define = None

content = Path(localpath(folder, family_header)).read_text(encoding="utf-8", errors="replace")
match = re.findall(r"if defined\((?P<define>STM32[F|L].....)\)", content)
match = re.findall(r"if defined\((?P<define>STM32[F|L|G].....)\)", content)
define = getDefineForDevice(device.identifier, match)
if define is None or match is None:
raise ValidateException("No device define found for '{}'!".format(device.partname))
Expand Down
5 changes: 4 additions & 1 deletion repo.lb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ class DevicesCache(dict):

# roughly filter to supported devices
supported = ["stm32f0", "stm32f1", "stm32f2", "stm32f3", "stm32f4", "stm32f7",
"stm32l4", "at90", "attiny", "atmega", "hosted"]
"stm32g0",
"stm32l4",
"at90", "attiny", "atmega",
"hosted"]
device_file_names = [dfn for dfn in device_file_names if any(s in dfn for s in supported)]

# Parse the files and build the :target enumeration
Expand Down
163 changes: 163 additions & 0 deletions src/modm/board/nucleo_g071rb/board.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*
* 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/.
*/

#ifndef MODM_STM32_NUCLEO_G071RB_HPP
#define MODM_STM32_NUCLEO_G071RB_HPP

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

using namespace modm::platform;

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

/// STM32G071RB running at 64MHz generated from the internal 16MHz crystal
// Dummy clock for devices
struct SystemClock {
static constexpr uint32_t Frequency = 64_MHz;
static constexpr uint32_t Ahb = Frequency;
static constexpr uint32_t Apb = Frequency;

static constexpr uint32_t Aes = Ahb;
static constexpr uint32_t Rng = Ahb;
static constexpr uint32_t Crc = Ahb;
static constexpr uint32_t Flash = Ahb;
static constexpr uint32_t Exti = Ahb;
static constexpr uint32_t Rcc = Ahb;
static constexpr uint32_t Dmamux = Ahb;
static constexpr uint32_t Dma = Ahb;

static constexpr uint32_t Dbg = Apb;
static constexpr uint32_t Timer17 = Apb;
static constexpr uint32_t Timer16 = Apb;
static constexpr uint32_t Timer15 = Apb;
static constexpr uint32_t Usart1 = Apb;
static constexpr uint32_t Spi1 = Apb;
static constexpr uint32_t I2s1 = Apb;
static constexpr uint32_t Timer1 = Apb;
static constexpr uint32_t Adc = Apb;
static constexpr uint32_t Comp = Apb;
static constexpr uint32_t ItLine = Apb;
static constexpr uint32_t VrefBuf = Apb;
static constexpr uint32_t SysCfg = Apb;
static constexpr uint32_t Tamp = Apb;
static constexpr uint32_t Bkp = Apb;
static constexpr uint32_t Ucpd2 = Apb;
static constexpr uint32_t Ucpd1 = Apb;
static constexpr uint32_t LpTimer2 = Apb;
static constexpr uint32_t LpUart1 = Apb;
static constexpr uint32_t LpTimer1 = Apb;
static constexpr uint32_t HdmiCec = Apb;
static constexpr uint32_t Dac = Apb;
static constexpr uint32_t Pwr = Apb;
static constexpr uint32_t I2c2 = Apb;
static constexpr uint32_t I2c1 = Apb;
static constexpr uint32_t Usart4 = Apb;
static constexpr uint32_t Usart3 = Apb;
static constexpr uint32_t Usart2 = Apb;
static constexpr uint32_t Spi2 = Apb;
static constexpr uint32_t Iwdg = Apb;
static constexpr uint32_t Wwdg = Apb;
static constexpr uint32_t Rtc = Apb;
static constexpr uint32_t Timer14 = Apb;
static constexpr uint32_t Timer7 = Apb;
static constexpr uint32_t Timer6 = Apb;
static constexpr uint32_t Timer3 = Apb;
static constexpr uint32_t Timer2 = Apb;

static bool inline
enable()
{
Rcc::enableInternalClock(); // 16MHz
// (internal clock / 1_M) * 8_N / 2_R = 128MHz / 2 = 64MHz
Rcc::enablePll(
Rcc::PllSource::InternalClock,
1, // Pll_M
8, // Pll_N
2 // Pll_R
);
// set flash latency for 64MHz
Rcc::setFlashLatency<Frequency>();
// switch system clock to PLL output
Rcc::enableSystemClock(Rcc::SystemClockSource::Pll);
Rcc::setAhbPrescaler(Rcc::AhbPrescaler::Div1);
Rcc::setApbPrescaler(Rcc::ApbPrescaler::Div1);
// update frequencies for busy-wait delay functions
Rcc::updateCoreFrequency<Frequency>();

return true;
}
};

// Arduino Footprint
using A0 = GpioA0;
using A1 = GpioA1;
using A2 = GpioA4;
using A3 = GpioB1;
using A4 = GpioB11;
using A5 = GpioB12;

using D0 = GpioC5;
using D1 = GpioC4;
using D2 = GpioA10;
using D3 = GpioB3;
using D4 = GpioB5;
using D5 = GpioB4;
using D6 = GpioB14;
using D7 = GpioA8;
using D8 = GpioA9;
using D9 = GpioC7;
using D10 = GpioB0;
using D11 = GpioA7;
using D12 = GpioA6;
using D13 = GpioA5;
using D14 = GpioB9;
using D15 = GpioB8;

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_G071RB_HPP
15 changes: 15 additions & 0 deletions src/modm/board/nucleo_g071rb/board.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<library>
<repositories>
<repository>
<path>../../../../repo.lb</path>
</repository>
</repositories>

<options>
<option name="modm:target">stm32g071rbt</option>
<option name="modm:platform:uart:2:buffer.tx">2048</option>
</options>
<modules>
<module>modm:board:nucleo-g071rb</module>
</modules>
</library>
40 changes: 40 additions & 0 deletions src/modm/board/nucleo_g071rb/module.lb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# 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/.
# -----------------------------------------------------------------------------

def init(module):
module.parent = "board"
module.name = "nucleo-g071rb"
module.description = """\
# NUCLEO-G071RB
Nucleo kit for STM32G071RB
http://www.st.com/en/evaluation-tools/nucleo-g071rb.html
"""

def prepare(module, options):
if options[":target"].partname != "stm32g071rbt":
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 = {"board_has_logger": True}
env.template("../board.cpp.in", "board.cpp")
env.copy('.')

# Waiting on this patch to OpenOCD http://openocd.zylin.com/#/c/4807
# env.outbasepath = "modm/openocd/modm/board/"
# env.copy(repopath("tools/openocd/modm/st_nucleo_g0.cfg"), "st_nucleo_g0.cfg")
# env.collect(":build:openocd.source", "modm/board/st_nucleo_g0.cfg")
Loading

0 comments on commit 399a533

Please sign in to comment.