Skip to content

Commit

Permalink
[board] Add Feather-RP2040 BSP
Browse files Browse the repository at this point in the history
  • Loading branch information
cocasema authored and salkinium committed Aug 17, 2022
1 parent 9cbfc21 commit 3df5231
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 10 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -566,55 +566,56 @@ We have out-of-box support for many development boards including documentation.
<td align="center"><a href="https://modm.io/reference/config/modm-disco-l476vg">DISCO-L476VG</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-feather-m0">FEATHER-M0</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-feather-rp2040">FEATHER-RP2040</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-mega-2560-pro">MEGA-2560-PRO</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f031k6">NUCLEO-F031K6</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f042k6">NUCLEO-F042K6</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f042k6">NUCLEO-F042K6</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f072rb">NUCLEO-F072RB</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f091rc">NUCLEO-F091RC</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f103rb">NUCLEO-F103RB</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f303k8">NUCLEO-F303K8</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f303k8">NUCLEO-F303K8</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f303re">NUCLEO-F303RE</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f334r8">NUCLEO-F334R8</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f401re">NUCLEO-F401RE</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f411re">NUCLEO-F411RE</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f411re">NUCLEO-F411RE</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f429zi">NUCLEO-F429ZI</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f439zi">NUCLEO-F439ZI</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f446re">NUCLEO-F446RE</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f446ze">NUCLEO-F446ZE</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f446ze">NUCLEO-F446ZE</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f746zg">NUCLEO-F746ZG</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-f767zi">NUCLEO-F767ZI</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-g071rb">NUCLEO-G071RB</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-g431kb">NUCLEO-G431KB</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-g431kb">NUCLEO-G431KB</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-g431rb">NUCLEO-G431RB</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-g474re">NUCLEO-G474RE</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-h723zg">NUCLEO-H723ZG</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-h743zi">NUCLEO-H743ZI</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-h743zi">NUCLEO-H743ZI</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l031k6">NUCLEO-L031K6</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l053r8">NUCLEO-L053R8</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l152re">NUCLEO-L152RE</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l432kc">NUCLEO-L432KC</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l432kc">NUCLEO-L432KC</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l452re">NUCLEO-L452RE</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l476rg">NUCLEO-L476RG</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l496zg-p">NUCLEO-L496ZG-P</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l552ze-q">NUCLEO-L552ZE-Q</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-nucleo-l552ze-q">NUCLEO-L552ZE-Q</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-olimexino-stm32">OLIMEXINO-STM32</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-raspberrypi">Raspberry Pi</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-rp-pico">Raspberry Pi Pico</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-samd21-mini">SAMD21-MINI</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-samd21-mini">SAMD21-MINI</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-samg55-xplained-pro">SAMG55-XPLAINED-PRO</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-srxe">Smart Response XE</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-stm32_f4ve">STM32-F4VE</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-stm32f030_demo">STM32F030-DEMO</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-stm32f030_demo">STM32F030-DEMO</a></td>
</tr>
</table>
<!--/bsptable-->
Expand Down
104 changes: 104 additions & 0 deletions src/modm/board/feather_rp2040/board.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
*
* 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_feather_rp2040
struct SystemClock
{
static constexpr uint32_t Frequency = 125_MHz;
static constexpr uint32_t XOSCFrequency = 12_MHz;
// https://github.com/raspberrypi/pico-sdk/pull/457
static constexpr uint16_t XOSCDelayMultiplier = 64;
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, XOSCDelayMultiplier);
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_feather_rp2040
using Device = Usb;
}

/// @ingroup modm_board_feather_rp2040
/// @{
// User LED
using LedRed = GpioOutput13;
using Led = LedRed;
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
16 changes: 16 additions & 0 deletions src/modm/board/feather_rp2040/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">rp2040</option>
<option name="modm:platform:core:boot2">generic_03h</option>
<option name="modm:platform:core:boot2_size">8*1024*1024</option>
</options>
<modules>
<module>modm:board:feather-rp2040</module>
</modules>
</library>
49 changes: 49 additions & 0 deletions src/modm/board/feather_rp2040/module.lb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/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:feather-rp2040"
module.description = """\
# Adafruit Feather RP2040
A board with RP2040 chip and 8MB of flash memory.
https://www.adafruit.com/product/4884
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")

0 comments on commit 3df5231

Please sign in to comment.