1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-24 16:55:36 +03:00

Adding RP2350 SDK and target framework (#13988)

* Adding RP2350 SDK and target framework

* Spacing

* Removing board definitions
This commit is contained in:
J Blackman 2024-10-23 10:02:48 +11:00 committed by GitHub
parent 462cb05930
commit 2dd6f95aad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
576 changed files with 435012 additions and 0 deletions

View file

@ -0,0 +1,90 @@
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _HARDWARE_PLL_H
#define _HARDWARE_PLL_H
#include "pico.h"
#include "hardware/structs/pll.h"
#ifdef __cplusplus
extern "C" {
#endif
/** \file hardware/pll.h
* \defgroup hardware_pll hardware_pll
*
* \brief Phase Locked Loop control APIs
*
* There are two PLLs in RP2040. They are:
* - pll_sys - Used to generate up to a 133MHz system clock
* - pll_usb - Used to generate a 48MHz USB reference clock
*
* For details on how the PLLs are calculated, please refer to the RP2040 datasheet.
*/
typedef pll_hw_t *PLL;
#define pll_sys pll_sys_hw
#define pll_usb pll_usb_hw
#ifndef PICO_PLL_VCO_MIN_FREQ_HZ
#ifdef PICO_PLL_VCO_MIN_FREQ_MHZ
#define PICO_PLL_VCO_MIN_FREQ_HZ (PICO_PLL_VCO_MIN_FREQ_MHZ * MHZ)
#elif defined(PICO_PLL_VCO_MIN_FREQ_KHZ)
#define PICO_PLL_VCO_MIN_FREQ_HZ (PICO_PLL_VCO_MIN_FREQ_KHZ * KHZ)
#else
#define PICO_PLL_VCO_MIN_FREQ_HZ (750 * MHZ)
#endif
#endif
#ifndef PICO_PLL_VCO_MAX_FREQ_HZ
#ifdef PICO_PLL_VCO_MAX_FREQ_MHZ
#define PICO_PLL_VCO_MAX_FREQ_HZ (PICO_PLL_VCO_MAX_FREQ_MHZ * MHZ)
#elif defined(PICO_PLL_VCO_MAX_FREQ_KHZ)
#define PICO_PLL_VCO_MAX_FREQ_HZ (PICO_PLL_VCO_MAX_FREQ_KHZ * KHZ)
#else
#define PICO_PLL_VCO_MAX_FREQ_HZ (1600 * MHZ)
#endif
#endif
/*! \brief Initialise specified PLL.
* \ingroup hardware_pll
* \param pll pll_sys or pll_usb
* \param ref_div Input clock divider.
* \param vco_freq Requested output from the VCO (voltage controlled oscillator)
* \param post_div1 Post Divider 1 - range 1-7. Must be >= post_div2
* \param post_div2 Post Divider 2 - range 1-7
*/
void pll_init(PLL pll, uint ref_div, uint vco_freq, uint post_div1, uint post_div2);
/*! \brief Release/uninitialise specified PLL.
* \ingroup hardware_pll
*
* This will turn off the power to the specified PLL. Note this function does not currently check if
* the PLL is in use before powering it off so should be used with care.
*
* \param pll pll_sys or pll_usb
*/
void pll_deinit(PLL pll);
/**
* \def PLL_RESET_NUM(pll)
* \ingroup hardware_pll
* \hideinitializer
* \brief Returns the \ref reset_num_t used to reset a given PLL instance
*
* Note this macro is intended to resolve at compile time, and does no parameter checking
*/
#ifndef PLL_RESET_NUM
#define PLL_RESET_NUM(pll) ((pll_usb_hw == (pll)) ? RESET_PLL_USB : RESET_PLL_SYS)
#endif
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,76 @@
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
// For frequency and PLL definitions etc.
#include "hardware/clocks.h"
#include "hardware/pll.h"
#include "hardware/resets.h"
/// \tag::pll_init_calculations[]
void pll_init(PLL pll, uint refdiv, uint vco_freq, uint post_div1, uint post_div2) {
uint32_t ref_freq = XOSC_HZ / refdiv;
// Check vco freq is in an acceptable range
assert(vco_freq >= PICO_PLL_VCO_MIN_FREQ_HZ && vco_freq <= PICO_PLL_VCO_MAX_FREQ_HZ);
// What are we multiplying the reference clock by to get the vco freq
// (The regs are called div, because you divide the vco output and compare it to the refclk)
uint32_t fbdiv = vco_freq / ref_freq;
/// \end::pll_init_calculations[]
// fbdiv
assert(fbdiv >= 16 && fbdiv <= 320);
// Check divider ranges
assert((post_div1 >= 1 && post_div1 <= 7) && (post_div2 >= 1 && post_div2 <= 7));
// post_div1 should be >= post_div2
// from appnote page 11
// postdiv1 is designed to operate with a higher input frequency than postdiv2
// Check that reference frequency is no greater than vco / 16
assert(ref_freq <= (vco_freq / 16));
// div1 feeds into div2 so if div1 is 5 and div2 is 2 then you get a divide by 10
uint32_t pdiv = (post_div1 << PLL_PRIM_POSTDIV1_LSB) |
(post_div2 << PLL_PRIM_POSTDIV2_LSB);
/// \tag::pll_init_finish[]
if ((pll->cs & PLL_CS_LOCK_BITS) &&
(refdiv == (pll->cs & PLL_CS_REFDIV_BITS)) &&
(fbdiv == (pll->fbdiv_int & PLL_FBDIV_INT_BITS)) &&
(pdiv == (pll->prim & (PLL_PRIM_POSTDIV1_BITS | PLL_PRIM_POSTDIV2_BITS)))) {
// do not disrupt PLL that is already correctly configured and operating
return;
}
reset_unreset_block_num_wait_blocking(PLL_RESET_NUM(pll));
// Load VCO-related dividers before starting VCO
pll->cs = refdiv;
pll->fbdiv_int = fbdiv;
// Turn on PLL
uint32_t power = PLL_PWR_PD_BITS | // Main power
PLL_PWR_VCOPD_BITS; // VCO Power
hw_clear_bits(&pll->pwr, power);
// Wait for PLL to lock
while (!(pll->cs & PLL_CS_LOCK_BITS)) tight_loop_contents();
// Set up post dividers
pll->prim = pdiv;
// Turn on post divider
hw_clear_bits(&pll->pwr, PLL_PWR_POSTDIVPD_BITS);
/// \end::pll_init_finish[]
}
void pll_deinit(PLL pll) {
// todo: Make sure there are no sources running from this pll?
pll->pwr = PLL_PWR_BITS;
}