From 7ba2fbbbe459cc9b0f10be390196becb7c3835ef Mon Sep 17 00:00:00 2001 From: Niklas Hauser Date: Tue, 31 Dec 2024 22:12:15 +0100 Subject: [PATCH] [board] Add WeAct C011 board --- README.md | 2 + src/modm/board/weact_c011f6/board.hpp | 89 +++++++++++++++++++++++++++ src/modm/board/weact_c011f6/board.xml | 15 +++++ src/modm/board/weact_c011f6/module.lb | 42 +++++++++++++ 4 files changed, 148 insertions(+) create mode 100644 src/modm/board/weact_c011f6/board.hpp create mode 100644 src/modm/board/weact_c011f6/board.xml create mode 100644 src/modm/board/weact_c011f6/module.lb diff --git a/README.md b/README.md index 4981c582bc..adb5963097 100644 --- a/README.md +++ b/README.md @@ -738,6 +738,8 @@ We have out-of-box support for many development boards including documentation. STM32-F4VE STM32F030-DEMO THINGPLUS-RP2040 +WEACT-C011F6 + diff --git a/src/modm/board/weact_c011f6/board.hpp b/src/modm/board/weact_c011f6/board.hpp new file mode 100644 index 0000000000..9f5cbb634e --- /dev/null +++ b/src/modm/board/weact_c011f6/board.hpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2016-2018, 2024, Niklas Hauser + * Copyright (c) 2017, Nick Sarten + * Copyright (c) 2017, Sascha Schade + * + * 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 +#include + +using namespace modm::platform; + +namespace Board +{ +/// @ingroup modm_board_nucleo_c011f6 +/// @{ +using namespace modm::literals; + +/// STM32C011F6 running at 48MHz generated from the internal clock +struct SystemClock +{ + static constexpr uint32_t Frequency = Rcc::HsiFrequency; + static constexpr uint32_t Ahb = Frequency; + static constexpr uint32_t Apb = Frequency; + + static constexpr uint32_t Adc1 = Apb; + + static constexpr uint32_t Spi1 = Apb; + + static constexpr uint32_t Usart1 = Apb; + static constexpr uint32_t Usart2 = Apb; + + static constexpr uint32_t I2c1 = Apb; + + static constexpr uint32_t Timer1 = Apb; + static constexpr uint32_t Timer2 = Apb; + static constexpr uint32_t Timer3 = Apb; + static constexpr uint32_t Timer14 = Apb; + static constexpr uint32_t Timer16 = Apb; + static constexpr uint32_t Timer17 = Apb; + static constexpr uint32_t Iwdg = Rcc::LsiFrequency; + static constexpr uint32_t Rtc = 32.768_kHz; + + static bool inline + enable() + { + Rcc::enableLowSpeedExternalCrystal(); + Rcc::enableRealTimeClock(Rcc::RealTimeClockSource::LowSpeedExternalCrystal); + + // 48MHz generated from internal RC + Rcc::enableInternalClock(); + Rcc::setHsiSysDivider(Rcc::HsiSysDivider::Div1); + // set flash latency for 48MHz + Rcc::setFlashLatency(); + // switch system clock to PLL output + Rcc::setAhbPrescaler(Rcc::AhbPrescaler::Div1); + Rcc::setApbPrescaler(Rcc::ApbPrescaler::Div1); + // update frequencies for busy-wait delay functions + Rcc::updateCoreFrequency(); + + return true; + } +}; + +using Button = GpioInputA14; // SWDCLK! +using LedA4 = GpioInverted; + +using Leds = SoftwareGpioPort< LedA4 >; +/// @} + +/// @ingroup modm_board_nucleo_c011f6 +/// @{ + +inline void +initialize() +{ + SystemClock::enable(); + SysTickTimer::initialize(); +} +/// @} + +} diff --git a/src/modm/board/weact_c011f6/board.xml b/src/modm/board/weact_c011f6/board.xml new file mode 100644 index 0000000000..f8403668ab --- /dev/null +++ b/src/modm/board/weact_c011f6/board.xml @@ -0,0 +1,15 @@ + + + + ../../../../repo.lb + + + + + + + + + modm:board:weact-c011f6 + + diff --git a/src/modm/board/weact_c011f6/module.lb b/src/modm/board/weact_c011f6/module.lb new file mode 100644 index 0000000000..1365f8fd8e --- /dev/null +++ b/src/modm/board/weact_c011f6/module.lb @@ -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:weact-c011f6" + module.description = """\ +# WeAct Studio STM32C011F6 Core Board + +[Documentation](https://github.com/WeActStudio/WeActStudio.STM32G0xxC0xxCoreBoard) +""" + +def prepare(module, options): + if not options[":target"].partname.startswith("stm32c011f6p"): + return False + + module.depends(":platform:core", ":platform:gpio", ":platform:clock", + ":architecture:clock", ":architecture:clock") + return True + +def build(env): + env.outbasepath = "modm/src/modm/board" + env.substitutions = { + "with_logger": False, + "with_assert": env.has_module(":architecture:assert") + } + env.template("../board.cpp.in", "board.cpp") + env.copy('.') + + env.outbasepath = "modm/openocd/modm/board/" + env.template(repopath("tools/openocd/modm/stm32_swd.cfg.in"), "board.cfg", + substitutions={"target": "stm32c0x"}) + env.collect(":build:openocd.source", "modm/board/board.cfg")