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,107 @@
/*
* Copyright (c) 2021 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _PICO_UNIQUE_ID_H
#define _PICO_UNIQUE_ID_H
#include "pico.h"
#ifdef __cplusplus
extern "C" {
#endif
/** \file pico/unique_id.h
* \defgroup pico_unique_id pico_unique_id
*
* \brief Unique device ID access API
*
* \if rp2040_specific
* RP2040 does not have an on-board unique identifier (all instances of RP2040
* silicon are identical and have no persistent state). However, RP2040 boots
* from serial NOR flash devices which have at least a 64-bit unique ID as a standard
* feature, and there is a 1:1 association between RP2040 and flash, so this
* is suitable for use as a unique identifier for an RP2040-based board.
*
* This library injects a call to the flash_get_unique_id function from the
* hardware_flash library, to run before main, and stores the result in a
* static location which can safely be accessed at any time via
* pico_get_unique_id().
*
* This avoids some pitfalls of the hardware_flash API, which requires any
* flash-resident interrupt routines to be disabled when called into.
* \endif
*
* \if rp2350_specific
* On boards using RP2350, the unique identifier is read from OTP memory on boot.
* \endif
*/
#define PICO_UNIQUE_BOARD_ID_SIZE_BYTES 8
/**
* \brief Unique board identifier
* \ingroup pico_unique_id
*
* This structure contains an array of PICO_UNIQUE_BOARD_ID_SIZE_BYTES identifier bytes suitable for
* holding the unique identifier for the device.
*
* \if rp2040_specific
* On an RP2040-based board, the unique identifier is retrieved from the external NOR flash device at boot,
* or for PICO_NO_FLASH builds the unique identifier is set to all 0xEE.
* \endif
*
* \if rp2350_specific
* On an RP2350-based board, the unique identifier is retrieved from OTP memory at boot.
* \endif
*
*/
typedef struct {
uint8_t id[PICO_UNIQUE_BOARD_ID_SIZE_BYTES];
} pico_unique_board_id_t;
/*! \brief Get unique ID
* \ingroup pico_unique_id
*
* Get the unique 64-bit device identifier.
*
* \if rp2040_specific
* On an RP2040-based board, the unique identifier is retrieved from the external NOR flash device at boot,
* or for PICO_NO_FLASH builds the unique identifier is set to all 0xEE.
* \endif
*
* \if rp2350_specific
* On an RP2350-based board, the unique identifier is retrieved from OTP memory at boot.
* \endif
*
* \param id_out a pointer to a pico_unique_board_id_t struct, to which the identifier will be written
*/
void pico_get_unique_board_id(pico_unique_board_id_t *id_out);
/*! \brief Get unique ID in string format
* \ingroup pico_unique_id
*
* Get the unique 64-bit device identifier formatted as a 0-terminated ASCII hex string.
*
* \if rp2040_specific
* On an RP2040-based board, the unique identifier is retrieved from the external NOR flash device at boot,
* or for PICO_NO_FLASH builds the unique identifier is set to all 0xEE.
* \endif
*
* \if rp2350_specific
* On an RP2350-based board, the unique identifier is retrieved from OTP memory at boot.
* \endif
*
* \param id_out a pointer to a char buffer of size len, to which the identifier will be written
* \param len the size of id_out. For full serial, len >= 2 * PICO_UNIQUE_BOARD_ID_SIZE_BYTES + 1
*/
void pico_get_unique_board_id_string(char *id_out, uint len);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,61 @@
/*
* Copyright (c) 2021 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "hardware/flash.h"
#include "pico/bootrom.h"
#include "pico/unique_id.h"
static_assert(PICO_UNIQUE_BOARD_ID_SIZE_BYTES <= FLASH_UNIQUE_ID_SIZE_BYTES, "Board ID size must at least be the size of flash ID");
static pico_unique_board_id_t retrieved_id;
static void __attribute__((constructor)) _retrieve_unique_id_on_boot(void) {
#if PICO_RP2040
#if PICO_NO_FLASH
// The hardware_flash call will panic() if called directly on a NO_FLASH
// build. Since this constructor is pre-main it would be annoying to
// debug, so just produce something well-defined and obviously wrong.
for (int i = 0; i < PICO_UNIQUE_BOARD_ID_SIZE_BYTES; i++)
retrieved_id.id[i] = 0xee;
#elif (PICO_UNIQUE_BOARD_ID_SIZE_BYTES == FLASH_UNIQUE_ID_SIZE_BYTES)
flash_get_unique_id(retrieved_id.id);
#elif (PICO_UNIQUE_BOARD_ID_SIZE_BYTES < FLASH_UNIQUE_ID_SIZE_BYTES)
// The flash ID is >8 bytes (e.g. IS25LP016D) but we want to keep the
// pico unique board ID as 8 bytes, just use the last 8 bytes which are likely to change
uint8_t flash_id[FLASH_UNIQUE_ID_SIZE_BYTES];
flash_get_unique_id(flash_id);
memcpy(retrieved_id.id, flash_id + FLASH_UNIQUE_ID_SIZE_BYTES - PICO_UNIQUE_BOARD_ID_SIZE_BYTES, PICO_UNIQUE_BOARD_ID_SIZE_BYTES);
#else
#error unique board ID size is greater than flash unique ID size
#endif
#else
rom_get_sys_info_fn func = (rom_get_sys_info_fn) rom_func_lookup(ROM_FUNC_GET_SYS_INFO);
union {
uint32_t words[9];
uint8_t bytes[9 * 4];
} out;
__unused int rc = func(out.words, 9, SYS_INFO_CHIP_INFO);
assert(rc == 4);
for (int i = 0; i < PICO_UNIQUE_BOARD_ID_SIZE_BYTES; i++) {
retrieved_id.id[i] = out.bytes[PICO_UNIQUE_BOARD_ID_SIZE_BYTES - 1 + 2 * 4 - i];
}
#endif
}
void pico_get_unique_board_id(pico_unique_board_id_t *id_out) {
*id_out = retrieved_id;
}
void pico_get_unique_board_id_string(char *id_out, uint len) {
assert(len > 0);
size_t i;
// Generate hex one nibble at a time
for (i = 0; (i < len - 1) && (i < PICO_UNIQUE_BOARD_ID_SIZE_BYTES * 2); i++) {
int nibble = (retrieved_id.id[i/2] >> (4 - 4 * (i&1))) & 0xf;
id_out[i] = (char)(nibble < 10 ? nibble + '0' : nibble + 'A' - 10);
}
id_out[i] = 0;
}