1
0
mirror of https://github.com/raspberrypi/pico-sdk.git synced 2025-08-09 04:22:44 +03:00

Misc cleanup (#2569)

* miscellaneous cleanup:

* cleanup some #ifdefs which were slightly hacky when RP2350 was added; use HAS_ flags in preference to PICO_RP2040/RP2350
* make some dependencies more explicit - i.e. compile if the user doesn't want to include certain libraries
* cleanup some directory A -> directory B relative path names in CMakeLists.txt to be SDK root -> directory B
This commit is contained in:
Graham Sanderson
2025-07-18 09:37:21 -05:00
committed by GitHub
parent 4003a64789
commit 4242010f11
34 changed files with 143 additions and 54 deletions

View File

@@ -4,7 +4,7 @@ set(PICO_TOOLCHAIN_PATH "${PICO_TOOLCHAIN_PATH}" CACHE INTERNAL "")
# Set a default build type if none was specified
set(default_build_type "Release")
list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_PREFIX_PATH)
list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_PREFIX_PATH PICO_SDK_PATH)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Defaulting build type to '${default_build_type}' since not specified.")

View File

@@ -1,3 +1,4 @@
if (NOT DEFINED PICO_SDK_VERSION_MAJOR)
# PICO_BUILD_DEFINE: PICO_SDK_VERSION_MAJOR, SDK major version number, type=int, default=Current SDK major version, group=pico_base
# PICO_CMAKE_CONFIG: PICO_SDK_VERSION_MAJOR, SDK major version number, type=int, default=Current SDK major version, group=pico_base
set(PICO_SDK_VERSION_MAJOR 2)
@@ -10,6 +11,7 @@ set(PICO_SDK_VERSION_REVISION 2)
# PICO_BUILD_DEFINE: PICO_SDK_VERSION_PRE_RELEASE_ID, Optional SDK pre-release version identifier, default=Current SDK pre-release identifier, type=string, group=pico_base
# PICO_CMAKE_CONFIG: PICO_SDK_VERSION_PRE_RELEASE_ID, Optional SDK pre-release version identifier, default=Current SDK pre-release identifier, type=string, group=pico_base
set(PICO_SDK_VERSION_PRE_RELEASE_ID develop)
endif()
# PICO_BUILD_DEFINE: PICO_SDK_VERSION_STRING, SDK version string, type=string, default=Current SDK version string, group=pico_base
# PICO_CMAKE_CONFIG: PICO_SDK_VERSION_STRING, SDK version string, type=string, default=Current SDK version string, group=pico_base

View File

@@ -63,14 +63,14 @@ pico_add_subdirectory(rp2_common/hardware_watchdog)
pico_add_subdirectory(rp2_common/hardware_xip_cache)
pico_add_subdirectory(rp2_common/hardware_xosc)
if (PICO_RP2350 OR PICO_COMBINED_DOCS)
if (PICO_COMBINED_DOCS OR NOT PICO_RP2040)
pico_add_subdirectory(rp2_common/hardware_powman)
# Note in spite of the name this is usable on Arm as well as RISC-V:
pico_add_subdirectory(rp2_common/hardware_riscv_platform_timer)
pico_add_subdirectory(rp2_common/hardware_sha256)
endif()
if (PICO_RP2350 OR PICO_COMBINED_DOCS)
if (PICO_COMBINED_DOCS OR NOT PICO_RP2040)
pico_add_subdirectory(rp2_common/hardware_dcp)
pico_add_subdirectory(rp2_common/hardware_rcp)
endif()
@@ -108,7 +108,7 @@ if (NOT PICO_BARE_METAL)
pico_add_subdirectory(rp2_common/pico_printf)
pico_add_subdirectory(rp2_common/pico_rand)
if (PICO_RP2350 OR PICO_COMBINED_DOCS)
if (PICO_COMBINED_DOCS OR NOT PICO_RP2040)
pico_add_subdirectory(rp2_common/pico_sha256)
endif()

View File

@@ -46,6 +46,15 @@
#define HAS_SIO_DIVIDER 1
#define HAS_RP2040_RTC 1
#ifndef FPGA_CLK_SYS_HZ
#define FPGA_CLK_SYS_HZ (48 * MHZ)
#endif
#ifndef FPGA_CLK_REF_HZ
#define FPGA_CLK_REF_HZ (12 * MHZ)
#endif
// PICO_CONFIG: XOSC_HZ, Crystal oscillator frequency in Hz, type=int, default=12000000, advanced=true, group=hardware_base
// NOTE: The system and USB clocks are generated from the frequency using two PLLs.
// If you override this define, or SYS_CLK_HZ/USB_CLK_HZ below, you will *also* need to add your own adjusted PLL set-up defines to

View File

@@ -73,6 +73,16 @@
#define HAS_POWMAN_TIMER 1
#define HAS_RP2350_TRNG 1
#define HAS_HSTX 1
#define HAS_PADS_BANK0_ISOLATION 1
#define __RISCV_PMP_CHECKED 1
#ifndef FPGA_CLK_SYS_HZ
#define FPGA_CLK_SYS_HZ (48 * MHZ)
#endif
#ifndef FPGA_CLK_REF_HZ
#define FPGA_CLK_REF_HZ (12 * MHZ)
#endif
// PICO_CONFIG: XOSC_HZ, Crystal oscillator frequency in Hz, type=int, default=12000000, advanced=true, group=hardware_base
// NOTE: The system and USB clocks are generated from the frequency using two PLLs.

View File

@@ -255,11 +255,11 @@ typedef int (*bootrom_api_callback_generic_t)(uint32_t r0, uint32_t r1, uint32_t
#define BOOTROM_NS_API_get_b_partition 7
#define BOOTROM_NS_API_COUNT 8
#define OTP_CMD_ROW_BITS 0x0000ffffu
#define OTP_CMD_ROW_BITS _u(0x0000ffff)
#define OTP_CMD_ROW_LSB _u(0)
#define OTP_CMD_WRITE_BITS 0x00010000u
#define OTP_CMD_WRITE_BITS _u(0x00010000)
#define OTP_CMD_WRITE_LSB _u(16)
#define OTP_CMD_ECC_BITS 0x00020000u
#define OTP_CMD_ECC_BITS _u(0x00020000)
#define OTP_CMD_ECC_LSB _u(17)
#ifndef __ASSEMBLER__

View File

@@ -270,12 +270,12 @@ static const uint8_t gpin0_src[CLK_COUNT] = {
CLOCKS_CLK_REF_CTRL_AUXSRC_VALUE_CLKSRC_GPIN0, // CLK_REF
CLOCKS_CLK_SYS_CTRL_AUXSRC_VALUE_CLKSRC_GPIN0, // CLK_SYS
CLOCKS_CLK_PERI_CTRL_AUXSRC_VALUE_CLKSRC_GPIN0, // CLK_PERI
#if !PICO_RP2040
#if HAS_HSTX
CLOCKS_CLK_HSTX_CTRL_AUXSRC_VALUE_CLKSRC_GPIN0, // CLK_HSTX
#endif
CLOCKS_CLK_USB_CTRL_AUXSRC_VALUE_CLKSRC_GPIN0, // CLK_USB
CLOCKS_CLK_ADC_CTRL_AUXSRC_VALUE_CLKSRC_GPIN0, // CLK_ADC
#if PICO_RP2040
#if HAS_RP2040_RTC
CLOCKS_CLK_RTC_CTRL_AUXSRC_VALUE_CLKSRC_GPIN0, // CLK_RTC
#endif
};

View File

@@ -46,7 +46,7 @@ void gpio_set_function(uint gpio, gpio_function_t fn) {
// Zero all fields apart from fsel; we want this IO to do what the peripheral tells it.
// This doesn't affect e.g. pullup/pulldown, as these are in pad controls.
io_bank0_hw->io[gpio].ctrl = fn << IO_BANK0_GPIO0_CTRL_FUNCSEL_LSB;
#if !PICO_RP2040
#if HAS_PADS_BANK0_ISOLATION
// Remove pad isolation now that the correct peripheral is in control of the pad
hw_clear_bits(&pads_bank0_hw->io[gpio], PADS_BANK0_GPIO0_ISO_BITS);
#endif

View File

@@ -8,7 +8,9 @@
#define _HARDWARE_RTC_H
#include "pico.h"
#if HAS_RP2040_RTC
#include "hardware/structs/rtc.h"
#endif
/** \file hardware/rtc.h
* \defgroup hardware_rtc hardware_rtc

View File

@@ -19,9 +19,10 @@ if (NOT TARGET pico_bit_ops)
${CMAKE_CURRENT_LIST_DIR}/bit_ops_aeabi.S
)
target_link_libraries(pico_bit_ops_pico INTERFACE pico_bootrom pico_bit_ops_headers)
target_link_libraries(pico_bit_ops_pico INTERFACE pico_bit_ops_headers)
if (NOT PICO_RP2350)
if (PICO_RP2040)
target_link_libraries(pico_bit_ops_pico INTERFACE pico_bootrom)
# gcc
pico_wrap_function(pico_bit_ops_pico __clzsi2)
pico_wrap_function(pico_bit_ops_pico __clzsi2)

View File

@@ -5,7 +5,9 @@
*/
#include "pico/asm_helper.S"
#if PICO_RP2040
#include "pico/bootrom.h"
#endif
#include "pico/runtime_init.h"
pico_default_asm_setup

View File

@@ -113,7 +113,7 @@ int rom_add_flash_runtime_partition(uint32_t start_offset, uint32_t size, uint32
}
int rom_pick_ab_update_partition(uint32_t *workarea_base, uint32_t workarea_size, uint partition_a_num) {
#if PICO_RP2350
#if !PICO_RP2040
// Generated from adding the following code into the bootrom
// scan_workarea_t* scan_workarea = (scan_workarea_t*)workarea;
// printf("VERSION_DOWNGRADE_ERASE_ADDR %08x\n", &(always->zero_init.version_downgrade_erase_flash_addr));

View File

@@ -6,7 +6,7 @@ endif ()
set(BTSTACK_TEST_PATH "src/bluetooth.h")
if (NOT PICO_BTSTACK_PATH)
set(PICO_BTSTACK_PATH ${PROJECT_SOURCE_DIR}/lib/btstack)
set(PICO_BTSTACK_PATH ${PICO_SDK_PATH}/lib/btstack)
if (PICO_CYW43_SUPPORTED AND NOT EXISTS ${PICO_BTSTACK_PATH}/${BTSTACK_TEST_PATH})
message(WARNING "btstack submodule has not been initialized; Pico W BLE support will be unavailable.
hint: try 'git submodule update --init' from your SDK directory (${PICO_SDK_PATH}).")

View File

@@ -5,6 +5,7 @@
*/
#include "pico.h"
#if PICO_RP2040_B0_SUPPORTED || PICO_RP2040_B1_SUPPORTED
#include "pico/time.h"
#include "hardware/structs/usb.h"
#include "hardware/gpio.h"
@@ -17,7 +18,6 @@
#define LS_K 0b10
#define LS_SE1 0b11
#if PICO_RP2040_B0_SUPPORTED || PICO_RP2040_B1_SUPPORTED
static void hw_enumeration_fix_wait_se0(void);
static void hw_enumeration_fix_force_ls_j(void);
static void hw_enumeration_fix_finish(void);

View File

@@ -6,7 +6,7 @@ endif ()
set(LWIP_TEST_PATH "src/Filelists.cmake")
if (NOT PICO_LWIP_PATH)
set(PICO_LWIP_PATH ${PROJECT_SOURCE_DIR}/lib/lwip)
set(PICO_LWIP_PATH ${PICO_SDK_PATH}/lib/lwip)
if (PICO_CYW43_SUPPORTED AND NOT EXISTS ${PICO_LWIP_PATH}/${LWIP_TEST_PATH})
message(WARNING "LWIP submodule has not been initialized; Pico W wireless support will be unavailable
#hint: try 'git submodule update --init' from your SDK directory (${PICO_SDK_PATH}).")

View File

@@ -6,7 +6,7 @@ endif()
set(MBEDTLS_TEST_PATH "library/aes.c")
if (NOT PICO_MBEDTLS_PATH)
set(PICO_MBEDTLS_PATH ${PROJECT_SOURCE_DIR}/lib/mbedtls)
set(PICO_MBEDTLS_PATH ${PICO_SDK_PATH}/lib/mbedtls)
elseif (NOT EXISTS ${PICO_MBEDTLS_PATH}/${MBEDTLS_TEST_PATH})
message(WARNING "PICO_MBEDTLS_PATH specified but content not present.")
endif()

View File

@@ -14,7 +14,7 @@
#include "hardware/structs/scb.h"
#endif
#include "hardware/structs/sio.h"
#include "hardware/regs/psm.h"
#include "hardware/structs/psm.h"
#include "hardware/claim.h"
#if !PICO_RP2040

View File

@@ -5,7 +5,6 @@
*/
#include "pico/asm_helper.S"
#include "pico/bootrom/sf_table.h"
pico_default_asm_setup

View File

@@ -7,8 +7,13 @@ target_sources(pico_rand INTERFACE
target_include_directories(pico_rand_headers SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
pico_mirrored_target_link_libraries(pico_rand INTERFACE
pico_unique_id
hardware_clocks
hardware_timer
hardware_sync
)
if (TARGET pico_unique_id)
pico_mirrored_target_link_libraries(pico_rand INTERFACE
pico_unique_id
)
endif()

View File

@@ -25,11 +25,19 @@
*/
#include "pico/rand.h"
#if PICO_RAND_SEED_ENTROPY_SRC_BOARD_ID
#include "pico/unique_id.h"
#endif
#if PICO_RAND_ENTROPY_SRC_TIME
#include "pico/time.h"
#endif
#include "hardware/clocks.h"
#if PICO_RAND_SEED_ENTROPY_SRC_ROSC || PICO_RAND_ENTROPY_SRC_ROSC
#include "hardware/structs/rosc.h"
#endif
#if PICO_RAND_SEED_ENTROPY_SRC_BUS_PERF_COUNTER || PICO_RAND_ENTROPY_SRC_BUS_PERF_COUNTER
#include "hardware/structs/busctrl.h"
#endif
#include "hardware/sync.h"
static bool rng_initialised = false;

View File

@@ -13,7 +13,13 @@ pico_mirrored_target_link_libraries(pico_runtime_init INTERFACE
)
if (TARGET hardware_clocks)
pico_mirrored_target_link_libraries(pico_runtime_init INTERFACE hardware_clocks hardware_timer hardware_vreg)
pico_mirrored_target_link_libraries(pico_runtime_init INTERFACE hardware_clocks)
endif()
if (TARGET hardware_timer)
pico_mirrored_target_link_libraries(pico_runtime_init INTERFACE hardware_timer)
endif()
if (TARGET hardware_vreg)
pico_mirrored_target_link_libraries(pico_runtime_init INTERFACE hardware_vreg)
endif()
# pico/runtime_init.h includes pico/runtime.h

View File

@@ -41,10 +41,10 @@ void __weak runtime_init_clocks(void) {
// Note: These need setting *before* the ticks are started
if (running_on_fpga()) {
for (uint i = 0; i < CLK_COUNT; i++) {
clock_set_reported_hz(i, 48 * MHZ);
clock_set_reported_hz(i, FPGA_CLK_SYS_HZ);
}
// clk_ref is 12MHz in both RP2040 and RP2350 FPGA
clock_set_reported_hz(clk_ref, 12 * MHZ);
clock_set_reported_hz(clk_ref, FPGA_CLK_REF_HZ);
// RP2040 has an extra clock, the rtc
#if HAS_RP2040_RTC
clock_set_reported_hz(clk_rtc, RTC_CLOCK_FREQ_HZ);

View File

@@ -32,7 +32,7 @@ void runtime_init_per_core_install_stack_guard(void *stack_bottom) {
| 0x10000000; // XN = disable instruction fetch; no other bits means no permissions
#elif defined(__riscv)
#if !PICO_RP2350
#if !__RISCV_PMP_CHECKED
#error "Check PMP configuration for new platform"
#endif
// RISC-V PMP, RP2350 configuration of Hazard3: 8 non-hardwired regions,

View File

@@ -128,13 +128,13 @@ void stdio_uart_deinit_full(struct uart_inst *uart, int tx_pin, int rx_pin) {
uart_instance = uart;
stdio_set_driver_enabled(&stdio_uart, false);
uart_deinit(uart_instance);
#if PICO_RP2040
((void)tx_pin);
((void)rx_pin);
#else
#if HAS_PADS_BANK0_ISOLATION
// Leave pads isolated
if (tx_pin >= 0) hw_set_bits(&pads_bank0_hw->io[tx_pin], PADS_BANK0_GPIO0_ISO_BITS);
if (rx_pin >= 0) hw_set_bits(&pads_bank0_hw->io[rx_pin], PADS_BANK0_GPIO0_ISO_BITS);
#else
((void)tx_pin);
((void)rx_pin);
#endif
}

View File

@@ -4,15 +4,19 @@ if (DEFINED ENV{PICO_TINYUSB_PATH} AND (NOT PICO_TINYUSB_PATH))
message("Using PICO_TINYUSB_PATH from environment ('${PICO_TINYUSB_PATH}')")
endif ()
set(TINYUSB_TEST_PATH "src/portable/raspberrypi/rp2040")
set(TINYUSB_TEST_PATH "hw/bsp/rp2040")
if (NOT PICO_TINYUSB_PATH)
set(PICO_TINYUSB_PATH ${PROJECT_SOURCE_DIR}/lib/tinyusb)
set(PICO_TINYUSB_PATH ${PICO_SDK_PATH}/lib/tinyusb)
if (NOT EXISTS ${PICO_TINYUSB_PATH}/${TINYUSB_TEST_PATH})
if (EXISTS "${PICO_TINYUSB_PATH}/LICENSE")
message(WARNING "TinyUSB submodule has been initialized, but does not contain ${TINYUSB_TEST_PATH}; USB support will be unavailable")
else()
message(WARNING "TinyUSB submodule has not been initialized; USB support will be unavailable
hint: try 'git submodule update --init' from your SDK directory (${PICO_SDK_PATH}).")
endif()
endif()
elseif (NOT EXISTS ${PICO_TINYUSB_PATH}/${TINYUSB_TEST_PATH})
message(WARNING "PICO_TINYUSB_PATH specified but content not present.")
message(WARNING "PICO_TINYUSB_PATH specified, but does not contain ${TINYUSB_TEST_PATH}; USB support will be unavailable")
endif()
if (EXISTS ${PICO_TINYUSB_PATH}/${TINYUSB_TEST_PATH})
@@ -35,14 +39,18 @@ if (EXISTS ${PICO_TINYUSB_PATH}/${TINYUSB_TEST_PATH})
PICO_RP2040_USB_DEVICE_UFRAME_FIX=1
)
if (TARGET tinyusb_device_base)
# unmarked version used by stdio USB
target_link_libraries(tinyusb_device_unmarked INTERFACE tinyusb_common pico_fix_rp2040_usb_device_enumeration tinyusb_device_base)
pico_add_library(tinyusb_device)
target_link_libraries(tinyusb_device INTERFACE tinyusb_device_unmarked)
endif()
if (TARGET tinyusb_host_base)
pico_add_library(tinyusb_host)
target_link_libraries(tinyusb_host INTERFACE tinyusb_host_base tinyusb_common)
endif()
pico_add_library(tinyusb_board)
target_include_directories(tinyusb_board INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)

View File

@@ -1,3 +1,7 @@
if (NOT TARGET cmsis_core)
message("Skipping cmsis_test as cmsis_core is unavailable on this platform")
return()
endif()
# todo remove check
if (NOT PICO_RISCV)
add_executable(cmsis_test cmsis_test.c)

View File

@@ -1,3 +1,7 @@
if (NOT TARGET hardware_dma)
message("Skipping hardware_irq_test as hardware_dma is unavailable on this platform")
return()
endif()
add_executable(hardware_irq_test hardware_irq_test.c)
target_link_libraries(hardware_irq_test PRIVATE pico_test hardware_irq hardware_dma)

View File

@@ -1,3 +1,7 @@
if (NOT TARGET hardware_pwm)
message("Skipping hardware_pwm_test as hardware_pwm is unavailable on this platform")
return()
endif()
add_executable(hardware_pwm_test hardware_pwm_test.c)
target_link_libraries(hardware_pwm_test PRIVATE pico_test hardware_pwm)

View File

@@ -1,3 +1,8 @@
if (NOT TARGET pico_multicore)
message("Skipping hardware_sync_spin_lock_test as pico_multicore is unavailable on this platform")
return()
endif()
add_executable(hardware_sync_spin_lock_test hardware_sync_spin_lock_test.c)
target_link_libraries(hardware_sync_spin_lock_test PRIVATE pico_test hardware_sync pico_multicore)

View File

@@ -1,3 +1,7 @@
if (NOT TARGET pico_divider)
message("Skipping pico_divider_test as pico_divider is unavailable on this platform")
return()
endif()
PROJECT(pico_divider_test)
if (PICO_ON_DEVICE)

View File

@@ -1,3 +1,8 @@
if (NOT TARGET pico_float)
message("Skipping pico_float_test as pico_float is unavailable on this platform")
return()
endif()
PROJECT(pico_float_test)

View File

@@ -1,4 +1,5 @@
if (NOT TARGET hardware_sha256)
if (NOT TARGET pico_sha256)
message("Skipping pico_sha256_test as pico_sha256 is unavailable on this platform")
return()
endif()

View File

@@ -41,8 +41,8 @@ static struct timeout {
alarm_id_t alarm_id;
absolute_time_t target;
absolute_time_t fired_at;
uint pool;
uint fired_count;
uint8_t pool;
bool cancelled;
bool not_cancelled; // tried to cancel but it was done
} timeouts[NUM_TIMEOUTS];

View File

@@ -34,10 +34,20 @@ if (NOT TARGET picotool)
)
endif()
if (NOT PICOTOOL_GIT_REPOSITORY_URL)
set(PICOTOOL_GIT_REPOSITORY_URL https://github.com/raspberrypi/picotool.git)
endif()
if (NOT PICOTOOL_GIT_BRANCH)
if (PICO_SDK_VERSION_PRE_RELEASE_ID)
set(PICOTOOL_GIT_BRANCH ${PICO_SDK_VERSION_PRE_RELEASE_ID})
else()
set(PICOTOOL_GIT_BRANCH ${PICO_SDK_VERSION_STRING})
endif()
endif()
message("Downloading Picotool")
FetchContent_Populate(picotool QUIET
GIT_REPOSITORY https://github.com/raspberrypi/picotool.git
GIT_TAG develop
GIT_REPOSITORY ${PICOTOOL_GIT_REPOSITORY_URL}
GIT_TAG ${PICOTOOL_GIT_BRANCH}
SOURCE_DIR ${picotool_INSTALL_DIR}/picotool-src
BINARY_DIR ${picotool_INSTALL_DIR}/picotool-build