-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cocasema
committed
Aug 18, 2022
1 parent
490e868
commit cb9e297
Showing
4 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* | ||
* Copyright (c) 2022, Andrey Kunitsyn | ||
* Copyright (c) 2022, Nikolay Semenov | ||
* | ||
* 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 <modm/architecture/interface/clock.hpp> | ||
#include <modm/platform.hpp> | ||
|
||
using namespace modm::platform; | ||
|
||
namespace Board | ||
{ | ||
using namespace modm::literals; | ||
|
||
/// RP2040 running at 125MHz generated from the external 12MHz crystal | ||
/// @ingroup modm_board_thingplus_rp2040 | ||
struct SystemClock | ||
{ | ||
static constexpr uint32_t Frequency = 125_MHz; | ||
static constexpr uint32_t XOSCFrequency = 12_MHz; | ||
static constexpr uint32_t PllSysFrequency = Frequency; | ||
static constexpr uint32_t PllUsbFrequency = 48_MHz; | ||
static constexpr uint32_t SysPLLMul = 125; | ||
static constexpr uint32_t UsbPLLMul = 40; | ||
static constexpr uint32_t RefFrequency = XOSCFrequency; | ||
static constexpr uint32_t UsbFrequency = PllUsbFrequency; | ||
static constexpr uint32_t SysFrequency = Frequency; | ||
static constexpr uint32_t PeriFrequency = SysFrequency; | ||
|
||
static bool inline enable() | ||
{ | ||
ClockControl::disableResus(); | ||
ClockControl::enableExternalCrystal(XOSCFrequency); | ||
ClockControl::disableAux<ClockControl::Clock::Sys>(); | ||
ClockControl::disableAux<ClockControl::Clock::Ref>(); | ||
// PLL SYS: 12MHz / 1 = 12MHz * 125 = 1500MHZ / 6 / 2 = 125MHz | ||
ClockControl::initPll<ClockControl::Pll::Sys, 1, SysPLLMul, 6, 2>(); | ||
// PLL USB: 12MHz / 1 = 12MHz * 40 = 480 MHz / 5 / 2 = 48MHz | ||
ClockControl::initPll<ClockControl::Pll::Usb, 1, UsbPLLMul, 5, 2>(); | ||
|
||
// CLK_REF = XOSC (12MHz) / 1 = 12MHz | ||
ClockControl::configureClock<ClockControl::Clock::Ref, ClockControl::ClockSrc::Xosc, | ||
XOSCFrequency, RefFrequency>(); | ||
// CLK SYS = PLL SYS (125MHz) / 1 = 125MHz | ||
ClockControl::configureClock<ClockControl::Clock::Sys, ClockControl::ClockSrc::PllSys, | ||
PllSysFrequency, SysFrequency>(); | ||
// CLK USB = PLL USB (48MHz) / 1 = 48MHz | ||
ClockControl::configureClock<ClockControl::Clock::Usb, ClockControl::ClockSrc::PllUsb, | ||
PllUsbFrequency, UsbFrequency>(); | ||
// CLK PERI = clk_sys. Used as reference clock for Peripherals. No dividers so just select | ||
// and enable Normally choose clk_sys or clk_usb | ||
ClockControl::configureClock<ClockControl::Clock::Peri, ClockControl::ClockSrc::Sys, | ||
SysFrequency, PeriFrequency>(); | ||
|
||
ClockControl::updateCoreFrequency<Frequency>(); | ||
return true; | ||
} | ||
}; | ||
|
||
namespace usb | ||
{ | ||
/// @ingroup modm_board_thingplus_rp2040 | ||
using Device = Usb; | ||
} | ||
|
||
/// @ingroup modm_board_thingplus_rp2040 | ||
/// @{ | ||
// User LED | ||
using LedBlue = GpioOutput25; | ||
using Led = LedBlue; | ||
using Leds = SoftwareGpioPort<Led>; | ||
|
||
using Button = GpioUnused; | ||
|
||
inline void | ||
initialize() | ||
{ | ||
SystemClock::enable(); | ||
SysTickTimer::initialize<SystemClock>(); | ||
|
||
Led::setOutput(); | ||
} | ||
|
||
inline void | ||
initializeUsbFs(uint8_t priority=3) | ||
{ | ||
usb::Device::initialize<SystemClock>(priority); | ||
usb::Device::connect<>(); | ||
} | ||
/// @} | ||
|
||
} // namespace Board |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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">rp2040</option> | ||
<option name="modm:platform:core:boot2">w25q080</option> | ||
<option name="modm:platform:core:boot2_size">16*1024*1024</option> | ||
</options> | ||
<modules> | ||
<module>modm:board:thingplus-rp2040</module> | ||
</modules> | ||
</library> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2022, Andrey Kunitsyn | ||
# Copyright (c) 2022, Nikolay Semenov | ||
# | ||
# 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:thingplus-rp2040" | ||
module.description = """\ | ||
# SparkFun Thing Plus - RP2040 | ||
The SparkFun Thing Plus - RP2040 is a low-cost, high performance board | ||
with flexible digital interfaces featuring the Raspberry Pi Foundation's RP2040 microcontroller. | ||
Besides the Thing Plus or Feather footprint (with 18 GPIO pins), | ||
the board also includes an SD card slot, 16MB (128Mbit) flash memory, | ||
a JST single cell battery connector (with a charging circuit and fuel gauge sensor), | ||
an addressable WS2812 RGB LED, JTAG PTH pins, four (4-40 screw) mounting holes, | ||
and SparkFun's Qwiic connector. | ||
https://www.sparkfun.com/products/17745 | ||
See `modm:rp-pico` for programming instructions. | ||
""" | ||
|
||
def prepare(module, options): | ||
if not options[":target"].partname.startswith("rp2040"): | ||
return False | ||
|
||
module.depends( | ||
":platform:clock", | ||
":platform:core", | ||
":platform:gpio", | ||
":platform:usb", | ||
":platform:clockgen") | ||
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.copy(repopath("tools/openocd/modm/rp2040_picoprobe.cfg"), "rp2040_picoprobe.cfg") | ||
env.collect(":build:openocd.source", "modm/board/rp2040_picoprobe.cfg") |