Skip to content

Commit

Permalink
[stm32] Add support for the STM32G4 family
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Oct 9, 2019
2 parents 5afe95a + 78da525 commit afaea7f
Show file tree
Hide file tree
Showing 22 changed files with 541 additions and 72 deletions.
26 changes: 26 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ jobs:
name: Examples STM32L4 Series
command: |
(cd examples && ../tools/scripts/examples_compile.py stm32l476_discovery nucleo_l476rg nucleo_l432kc)
- run:
name: Examples STM32G4 Series
command: |
(cd examples && ../tools/scripts/examples_compile.py nucleo_g474re)
stm32f4-examples:
docker:
Expand Down Expand Up @@ -305,6 +309,23 @@ jobs:
path: test/all/log
destination: log

stm32g4-compile-all:
docker:
- image: modm/modm-build:latest
steps:
- checkout
- run:
name: Checkout code and update modm tools
command: |
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade modm & wait
- run:
name: Compile HAL for all STM32G4
command: |
(cd test/all && python3 run_all.py stm32g4)
- store_artifacts:
path: test/all/log
destination: log

build-docs:
docker:
- image: modm/modm-build:latest
Expand Down Expand Up @@ -405,6 +426,10 @@ workflows:
requires:
- unittests-linux-generic
- stm32-examples
- stm32g4-compile-all:
requires:
- unittests-linux-generic
- stm32-examples
- upload-docs:
filters:
branches:
Expand All @@ -429,3 +454,4 @@ workflows:
- stm32f2-compile-all
- stm32f3-compile-all
- stm32g0-compile-all
- stm32g4-compile-all
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ git clone --recurse-submodules https://github.com/modm-io/modm.git

## Targets

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

<center>
Expand All @@ -80,7 +80,7 @@ STM32 devices, however, there are different levels of support and testing.
| AVR | ★★★ | STM32F0 | ★★★★ | STM32F1 | ★★★★ |
| STM32F2 | ★★★★ | STM32F3 | ★★★★★ | STM32F4 | ★★★★★ |
| STM32F7 | ★★★★ | STM32L1 | ★★★★ | STM32L4 | ★★★★ |
| STM32L4+ | ★★★★ | STM32G0 | ★★★★ |
| STM32L4+ | ★★★★ | STM32G0 | ★★★★ | STM32G4 | ★★★★ |

</center>

Expand Down Expand Up @@ -141,10 +141,11 @@ documentation.
<td align="center">NUCLEO-F446RE</td>
</tr><tr>
<td align="center">NUCLEO-G071RB</td>
<td align="center">NUCLEO-G474RE</td>
<td align="center">NUCLEO-L152RE</td>
<td align="center">NUCLEO-L432KC</td>
<td align="center">NUCLEO-L476RG</td>
</tr><tr>
<td align="center">NUCLEO-L476RG</td>
<td align="center">OLIMEXINO-STM32</td>
<td align="center">STM32F030F4P6-DEMO</td>
</tr>
Expand Down
39 changes: 39 additions & 0 deletions examples/nucleo_g474re/blink/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2019, 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/.
*/

#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::delayMilliseconds(Button::read() ? 100 : 500);

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

return 0;
}
9 changes: 9 additions & 0 deletions examples/nucleo_g474re/blink/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<library>
<extends>modm:nucleo-g474re</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_g474re/blink</option>
</options>
<modules>
<module>modm:build:scons</module>
</modules>
</library>
2 changes: 1 addition & 1 deletion repo.lb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class DevicesCache(dict):

# roughly filter to supported devices
supported = ["stm32f0", "stm32f1", "stm32f2", "stm32f3", "stm32f4", "stm32f7",
"stm32g0",
"stm32g0", "stm32g4",
"stm32l1", "stm32l4",
"at90", "attiny", "atmega",
"hosted"]
Expand Down
156 changes: 156 additions & 0 deletions src/modm/board/nucleo_g474re/board.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
* Copyright (c) 2019, 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_G474RE_HPP
#define MODM_STM32_NUCLEO_G474RE_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;

/// STM32G474RE 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 Adc3 = Adc;
static constexpr uint32_t Adc4 = Adc;
static constexpr uint32_t Adc5 = Adc;
static constexpr uint32_t Dac = Ahb2;
static constexpr uint32_t Dac1 = Dac;
static constexpr uint32_t Dac2 = Dac;
static constexpr uint32_t Dac3 = Dac;
static constexpr uint32_t Dac4 = Dac;
static constexpr uint32_t Rng = Ahb2;

static constexpr uint32_t Can = Apb1;
static constexpr uint32_t Fdcan1 = Can;
static constexpr uint32_t Fdcan2 = Can;
static constexpr uint32_t Fdcan3 = 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 I2c4 = I2c;
static constexpr uint32_t Lptim = Apb1;
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 Uart4 = Apb1;
static constexpr uint32_t Uart5 = 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 Timer5 = 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 constexpr uint32_t Timer20 = Apb2Timer;

static bool inline
enable()
{
Rcc::enableInternalClock(); // 16MHz
Rcc::enablePll(
Rcc::PllSource::InternalClock,
4, // 16MHz / N= 4 -> 4MHz
85, // 4MHz * M=85 -> 340MHz
2 // 336MHz / P= 2 -> 170MHz = F_cpu
);
// set flash latency for 170MHz
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_G474RE_HPP
16 changes: 16 additions & 0 deletions src/modm/board/nucleo_g474re/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">stm32g474ret</option>

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

def prepare(module, options):
if options[":target"].partname != "stm32g474ret":
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 = {"board_has_logger": True}
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")
Loading

0 comments on commit afaea7f

Please sign in to comment.