Skip to content

Commit 3df5231

Browse files
cocasemasalkinium
cocasema
authored andcommitted
[board] Add Feather-RP2040 BSP
1 parent 9cbfc21 commit 3df5231

File tree

4 files changed

+180
-10
lines changed

4 files changed

+180
-10
lines changed

README.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -566,55 +566,56 @@ We have out-of-box support for many development boards including documentation.
566566
<td align="center"><a href="https://modm.io/reference/config/modm-disco-l476vg">DISCO-L476VG</a></td>
567567
</tr><tr>
568568
<td align="center"><a href="https://modm.io/reference/config/modm-feather-m0">FEATHER-M0</a></td>
569+
<td align="center"><a href="https://modm.io/reference/config/modm-feather-rp2040">FEATHER-RP2040</a></td>
569570
<td align="center"><a href="https://modm.io/reference/config/modm-mega-2560-pro">MEGA-2560-PRO</a></td>
570571
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f031k6">NUCLEO-F031K6</a></td>
571-
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f042k6">NUCLEO-F042K6</a></td>
572572
</tr><tr>
573+
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f042k6">NUCLEO-F042K6</a></td>
573574
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f072rb">NUCLEO-F072RB</a></td>
574575
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f091rc">NUCLEO-F091RC</a></td>
575576
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f103rb">NUCLEO-F103RB</a></td>
576-
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f303k8">NUCLEO-F303K8</a></td>
577577
</tr><tr>
578+
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f303k8">NUCLEO-F303K8</a></td>
578579
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f303re">NUCLEO-F303RE</a></td>
579580
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f334r8">NUCLEO-F334R8</a></td>
580581
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f401re">NUCLEO-F401RE</a></td>
581-
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f411re">NUCLEO-F411RE</a></td>
582582
</tr><tr>
583+
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f411re">NUCLEO-F411RE</a></td>
583584
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f429zi">NUCLEO-F429ZI</a></td>
584585
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f439zi">NUCLEO-F439ZI</a></td>
585586
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f446re">NUCLEO-F446RE</a></td>
586-
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f446ze">NUCLEO-F446ZE</a></td>
587587
</tr><tr>
588+
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f446ze">NUCLEO-F446ZE</a></td>
588589
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f746zg">NUCLEO-F746ZG</a></td>
589590
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f767zi">NUCLEO-F767ZI</a></td>
590591
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-g071rb">NUCLEO-G071RB</a></td>
591-
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-g431kb">NUCLEO-G431KB</a></td>
592592
</tr><tr>
593+
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-g431kb">NUCLEO-G431KB</a></td>
593594
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-g431rb">NUCLEO-G431RB</a></td>
594595
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-g474re">NUCLEO-G474RE</a></td>
595596
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-h723zg">NUCLEO-H723ZG</a></td>
596-
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-h743zi">NUCLEO-H743ZI</a></td>
597597
</tr><tr>
598+
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-h743zi">NUCLEO-H743ZI</a></td>
598599
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l031k6">NUCLEO-L031K6</a></td>
599600
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l053r8">NUCLEO-L053R8</a></td>
600601
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l152re">NUCLEO-L152RE</a></td>
601-
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l432kc">NUCLEO-L432KC</a></td>
602602
</tr><tr>
603+
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l432kc">NUCLEO-L432KC</a></td>
603604
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l452re">NUCLEO-L452RE</a></td>
604605
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l476rg">NUCLEO-L476RG</a></td>
605606
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l496zg-p">NUCLEO-L496ZG-P</a></td>
606-
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l552ze-q">NUCLEO-L552ZE-Q</a></td>
607607
</tr><tr>
608+
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l552ze-q">NUCLEO-L552ZE-Q</a></td>
608609
<td align="center"><a href="https://modm.io/reference/config/modm-olimexino-stm32">OLIMEXINO-STM32</a></td>
609610
<td align="center"><a href="https://modm.io/reference/config/modm-raspberrypi">Raspberry Pi</a></td>
610611
<td align="center"><a href="https://modm.io/reference/config/modm-rp-pico">Raspberry Pi Pico</a></td>
611-
<td align="center"><a href="https://modm.io/reference/config/modm-samd21-mini">SAMD21-MINI</a></td>
612612
</tr><tr>
613+
<td align="center"><a href="https://modm.io/reference/config/modm-samd21-mini">SAMD21-MINI</a></td>
613614
<td align="center"><a href="https://modm.io/reference/config/modm-samg55-xplained-pro">SAMG55-XPLAINED-PRO</a></td>
614615
<td align="center"><a href="https://modm.io/reference/config/modm-srxe">Smart Response XE</a></td>
615616
<td align="center"><a href="https://modm.io/reference/config/modm-stm32_f4ve">STM32-F4VE</a></td>
616-
<td align="center"><a href="https://modm.io/reference/config/modm-stm32f030_demo">STM32F030-DEMO</a></td>
617617
</tr><tr>
618+
<td align="center"><a href="https://modm.io/reference/config/modm-stm32f030_demo">STM32F030-DEMO</a></td>
618619
</tr>
619620
</table>
620621
<!--/bsptable-->
+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
*
3+
* Copyright (c) 2022, Andrey Kunitsyn
4+
* Copyright (c) 2022, Nikolay Semenov
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+
14+
#pragma once
15+
16+
#include <modm/architecture/interface/clock.hpp>
17+
#include <modm/platform.hpp>
18+
19+
using namespace modm::platform;
20+
21+
namespace Board
22+
{
23+
using namespace modm::literals;
24+
25+
/// RP2040 running at 125MHz generated from the external 12MHz crystal
26+
/// @ingroup modm_board_feather_rp2040
27+
struct SystemClock
28+
{
29+
static constexpr uint32_t Frequency = 125_MHz;
30+
static constexpr uint32_t XOSCFrequency = 12_MHz;
31+
// https://github.com/raspberrypi/pico-sdk/pull/457
32+
static constexpr uint16_t XOSCDelayMultiplier = 64;
33+
static constexpr uint32_t PllSysFrequency = Frequency;
34+
static constexpr uint32_t PllUsbFrequency = 48_MHz;
35+
static constexpr uint32_t SysPLLMul = 125;
36+
static constexpr uint32_t UsbPLLMul = 40;
37+
static constexpr uint32_t RefFrequency = XOSCFrequency;
38+
static constexpr uint32_t UsbFrequency = PllUsbFrequency;
39+
static constexpr uint32_t SysFrequency = Frequency;
40+
static constexpr uint32_t PeriFrequency = SysFrequency;
41+
42+
static bool inline enable()
43+
{
44+
ClockControl::disableResus();
45+
ClockControl::enableExternalCrystal(XOSCFrequency, XOSCDelayMultiplier);
46+
ClockControl::disableAux<ClockControl::Clock::Sys>();
47+
ClockControl::disableAux<ClockControl::Clock::Ref>();
48+
// PLL SYS: 12MHz / 1 = 12MHz * 125 = 1500MHZ / 6 / 2 = 125MHz
49+
ClockControl::initPll<ClockControl::Pll::Sys, 1, SysPLLMul, 6, 2>();
50+
// PLL USB: 12MHz / 1 = 12MHz * 40 = 480 MHz / 5 / 2 = 48MHz
51+
ClockControl::initPll<ClockControl::Pll::Usb, 1, UsbPLLMul, 5, 2>();
52+
53+
// CLK_REF = XOSC (12MHz) / 1 = 12MHz
54+
ClockControl::configureClock<ClockControl::Clock::Ref, ClockControl::ClockSrc::Xosc,
55+
XOSCFrequency, RefFrequency>();
56+
// CLK SYS = PLL SYS (125MHz) / 1 = 125MHz
57+
ClockControl::configureClock<ClockControl::Clock::Sys, ClockControl::ClockSrc::PllSys,
58+
PllSysFrequency, SysFrequency>();
59+
// CLK USB = PLL USB (48MHz) / 1 = 48MHz
60+
ClockControl::configureClock<ClockControl::Clock::Usb, ClockControl::ClockSrc::PllUsb,
61+
PllUsbFrequency, UsbFrequency>();
62+
// CLK PERI = clk_sys. Used as reference clock for Peripherals. No dividers so just select
63+
// and enable Normally choose clk_sys or clk_usb
64+
ClockControl::configureClock<ClockControl::Clock::Peri, ClockControl::ClockSrc::Sys,
65+
SysFrequency, PeriFrequency>();
66+
67+
ClockControl::updateCoreFrequency<Frequency>();
68+
return true;
69+
}
70+
};
71+
72+
namespace usb
73+
{
74+
/// @ingroup modm_board_feather_rp2040
75+
using Device = Usb;
76+
}
77+
78+
/// @ingroup modm_board_feather_rp2040
79+
/// @{
80+
// User LED
81+
using LedRed = GpioOutput13;
82+
using Led = LedRed;
83+
using Leds = SoftwareGpioPort<Led>;
84+
85+
using Button = GpioUnused;
86+
87+
inline void
88+
initialize()
89+
{
90+
SystemClock::enable();
91+
SysTickTimer::initialize<SystemClock>();
92+
93+
Led::setOutput();
94+
}
95+
96+
inline void
97+
initializeUsbFs(uint8_t priority=3)
98+
{
99+
usb::Device::initialize<SystemClock>(priority);
100+
usb::Device::connect<>();
101+
}
102+
/// @}
103+
104+
} // namespace Board
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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">generic_03h</option>
11+
<option name="modm:platform:core:boot2_size">8*1024*1024</option>
12+
</options>
13+
<modules>
14+
<module>modm:board:feather-rp2040</module>
15+
</modules>
16+
</library>
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2022, Andrey Kunitsyn
5+
# Copyright (c) 2022, Nikolay Semenov
6+
#
7+
# This file is part of the modm project.
8+
#
9+
# This Source Code Form is subject to the terms of the Mozilla Public
10+
# License, v. 2.0. If a copy of the MPL was not distributed with this
11+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
12+
# -----------------------------------------------------------------------------
13+
14+
def init(module):
15+
module.name = ":board:feather-rp2040"
16+
module.description = """\
17+
# Adafruit Feather RP2040
18+
19+
A board with RP2040 chip and 8MB of flash memory.
20+
21+
https://www.adafruit.com/product/4884
22+
23+
See `modm:rp-pico` for programming instructions.
24+
"""
25+
26+
def prepare(module, options):
27+
if not options[":target"].partname.startswith("rp2040"):
28+
return False
29+
30+
module.depends(
31+
":platform:clock",
32+
":platform:core",
33+
":platform:gpio",
34+
":platform:usb",
35+
":platform:clockgen")
36+
return True
37+
38+
def build(env):
39+
env.outbasepath = "modm/src/modm/board"
40+
env.substitutions = {
41+
"with_logger": False,
42+
"with_assert": env.has_module(":architecture:assert")
43+
}
44+
env.template("../board.cpp.in", "board.cpp")
45+
env.copy('.')
46+
47+
env.outbasepath = "modm/openocd/modm/board/"
48+
env.copy(repopath("tools/openocd/modm/rp2040_picoprobe.cfg"), "rp2040_picoprobe.cfg")
49+
env.collect(":build:openocd.source", "modm/board/rp2040_picoprobe.cfg")

0 commit comments

Comments
 (0)