Skip to content

Commit db9c84c

Browse files
andryblacksalkinium
authored andcommitted
[board] Add RP-PICO board module
1 parent 250da09 commit db9c84c

File tree

3 files changed

+166
-0
lines changed

3 files changed

+166
-0
lines changed

src/modm/board/rp_pico/board.hpp

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
*
3+
* Copyright (c) 2022, Andrey Kunitsyn
4+
*
5+
* This file is part of the modm project.
6+
*
7+
* This Source Code Form is subject to the terms of the Mozilla Public
8+
* License, v. 2.0. If a copy of the MPL was not distributed with this
9+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
10+
*/
11+
// ----------------------------------------------------------------------------
12+
13+
#pragma once
14+
15+
#include <modm/architecture/interface/clock.hpp>
16+
#include <modm/platform.hpp>
17+
18+
using namespace modm::platform;
19+
20+
namespace Board
21+
{
22+
using namespace modm::literals;
23+
24+
/// RP2040 running at 125MHz generated from the external 12MHz crystal
25+
/// @ingroup modm_board_rp_pico
26+
struct SystemClock
27+
{
28+
static constexpr uint32_t Frequency = 125_MHz;
29+
static constexpr uint32_t XOSCFrequency = 12_MHz;
30+
static constexpr uint32_t PllSysFrequency = Frequency;
31+
static constexpr uint32_t PllUsbFrequency = 48_MHz;
32+
static constexpr uint32_t SysPLLMul = 125;
33+
static constexpr uint32_t UsbPLLMul = 40;
34+
static constexpr uint32_t RefFrequency = XOSCFrequency;
35+
static constexpr uint32_t UsbFrequency = PllUsbFrequency;
36+
static constexpr uint32_t SysFrequency = Frequency;
37+
static constexpr uint32_t PeriFrequency = SysFrequency;
38+
39+
static bool inline enable()
40+
{
41+
ClockControl::disableResus();
42+
ClockControl::enableExternalCrystal(XOSCFrequency);
43+
ClockControl::disableAux<ClockControl::Clock::Sys>();
44+
ClockControl::disableAux<ClockControl::Clock::Ref>();
45+
// PLL SYS: 12MHz / 1 = 12MHz * 125 = 1500MHZ / 6 / 2 = 125MHz
46+
ClockControl::initPll<ClockControl::Pll::Sys, 1, SysPLLMul, 6, 2>();
47+
// PLL USB: 12MHz / 1 = 12MHz * 40 = 480 MHz / 5 / 2 = 48MHz
48+
ClockControl::initPll<ClockControl::Pll::Usb, 1, UsbPLLMul, 5, 2>();
49+
50+
// CLK_REF = XOSC (12MHz) / 1 = 12MHz
51+
ClockControl::configureClock<ClockControl::Clock::Ref, ClockControl::ClockSrc::Xosc,
52+
XOSCFrequency, RefFrequency>();
53+
// CLK SYS = PLL SYS (125MHz) / 1 = 125MHz
54+
ClockControl::configureClock<ClockControl::Clock::Sys, ClockControl::ClockSrc::PllSys,
55+
PllSysFrequency, SysFrequency>();
56+
// CLK USB = PLL USB (48MHz) / 1 = 48MHz
57+
ClockControl::configureClock<ClockControl::Clock::Usb, ClockControl::ClockSrc::PllUsb,
58+
PllUsbFrequency, UsbFrequency>();
59+
// CLK PERI = clk_sys. Used as reference clock for Peripherals. No dividers so just select
60+
// and enable Normally choose clk_sys or clk_usb
61+
ClockControl::configureClock<ClockControl::Clock::Peri, ClockControl::ClockSrc::Sys,
62+
SysFrequency, PeriFrequency>();
63+
64+
ClockControl::updateCoreFrequency<Frequency>();
65+
return true;
66+
}
67+
};
68+
69+
namespace usb
70+
{
71+
/// @ingroup modm_board_rp_pico
72+
using Device = Usb;
73+
}
74+
75+
/// @ingroup modm_board_rp_pico
76+
/// @{
77+
// User LED
78+
using LedGreen = GpioOutput25;
79+
using Leds = SoftwareGpioPort<LedGreen>;
80+
81+
using Button = GpioUnused;
82+
83+
inline void
84+
initialize()
85+
{
86+
SystemClock::enable();
87+
SysTickTimer::initialize<SystemClock>();
88+
89+
LedGreen::setOutput();
90+
}
91+
92+
inline void
93+
initializeUsbFs()
94+
{
95+
usb::Device::initialize<SystemClock>();
96+
usb::Device::connect<>();
97+
}
98+
/// @}
99+
100+
} // namespace Board

src/modm/board/rp_pico/board.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<library>
2+
<repositories>
3+
<repository>
4+
<path>../../../../repo.lb</path>
5+
</repository>
6+
</repositories>
7+
8+
<options>
9+
<option name="modm:target">rp2040</option>
10+
<option name="modm:platform:core:boot2">w25q080</option>
11+
</options>
12+
<modules>
13+
<module>modm:board:rp-pico</module>
14+
</modules>
15+
</library>

src/modm/board/rp_pico/module.lb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2022, Andrey Kunitsyn
5+
#
6+
# This file is part of the modm project.
7+
#
8+
# This Source Code Form is subject to the terms of the Mozilla Public
9+
# License, v. 2.0. If a copy of the MPL was not distributed with this
10+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
11+
# -----------------------------------------------------------------------------
12+
13+
def init(module):
14+
module.name = ":board:rp-pico"
15+
module.description = """\
16+
# Raspberry Pi Pico
17+
18+
RP2040 Official System Development Board
19+
See https://www.raspberrypi.com/products/raspberry-pi-pico
20+
21+
22+
## Programming
23+
24+
The RP2040 ships with a [UF2 bootloader in ROM](https://github.com/microsoft/uf2).
25+
26+
To upload your application, connect the RP2040 via USB, convert the ELF to UF2
27+
format by calling `scons uf2` or `make uf2` and copy the generated `.uf2` file
28+
to the mounted virtual disk.
29+
"""
30+
31+
def prepare(module, options):
32+
if not options[":target"].partname.startswith("rp2040"):
33+
return False
34+
35+
module.depends(
36+
":platform:clock",
37+
":platform:core",
38+
":platform:gpio",
39+
":platform:usb",
40+
":platform:clockgen")
41+
return True
42+
43+
def build(env):
44+
env.outbasepath = "modm/src/modm/board"
45+
env.substitutions = {
46+
"with_logger": False,
47+
"with_assert": env.has_module(":architecture:assert")
48+
}
49+
env.template("../board.cpp.in", "board.cpp")
50+
env.copy('.')
51+

0 commit comments

Comments
 (0)