Skip to content

Commit 754bdf1

Browse files
committed
Allow 'host' platform to simulate either RP2040 or RP2350
The 'host' platform only really partially simulates an RP2040 environment, with no way to specify a particular board either, so attempting to build a host version of a existing code that uses an RP2350 or relies on values defined in a board file is either difficult or impossible. Instead of setting PICO_PLATFORM to just 'host', it can now be set to 'host-rp2040' or 'host-rp2350' and PICO_BOARD can be set to any board configuration that is compatible with the given chip type. Platform definitions for the given chip will be fetched, meaning defines such as 'NUM_IRQS' will be set correctly. Fixes #2778
1 parent 52d3592 commit 754bdf1

11 files changed

Lines changed: 101 additions & 92 deletions

File tree

cmake/pico_pre_load_platform.cmake

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ if (DEFINED ENV{PICO_PLATFORM} AND NOT PICO_PLATFORM)
1111
set(PICO_PLATFORM $ENV{PICO_PLATFORM})
1212
message("Initializing PICO_PLATFORM from environment ('${PICO_PLATFORM}')")
1313
endif()
14+
15+
if (${PICO_PLATFORM} STREQUAL "host")
16+
set(PICO_PLATFORM "host-rp2040")
17+
endif()
18+
1419
set(PICO_SAVED_PLATFORM "${PICO_PLATFORM}")
1520

1621
# If PICO_PLATFORM is specified but not PICO_BOARD, we'll make a stab at defaulting
@@ -88,11 +93,12 @@ endif()
8893

8994
if (NOT COMMAND pico_expand_pico_platform)
9095
function(pico_expand_pico_platform FUNC DO_MESSAGE)
91-
if (${FUNC} STREQUAL "rp2350")
96+
if (${FUNC} MATCHES "rp2350$")
97+
string(REGEX REPLACE "rp2350$" "${PICO_DEFAULT_RP2350_PLATFORM}" NEW_PLATFORM ${${FUNC}})
9298
if (DO_MESSAGE)
93-
message("Auto-converting non-specific PICO_PLATFORM='rp2350' to '${PICO_DEFAULT_RP2350_PLATFORM}'")
99+
message("Auto-converting non-specific PICO_PLATFORM='${${FUNC}}' to '${NEW_PLATFORM}'")
94100
endif()
95-
set(${FUNC} "${PICO_DEFAULT_RP2350_PLATFORM}" PARENT_SCOPE)
101+
set(${FUNC} "${NEW_PLATFORM}" PARENT_SCOPE)
96102
endif()
97103
endfunction()
98104
endif()
@@ -105,8 +111,9 @@ else()
105111
pico_expand_pico_platform(PICO_PLATFORM 1)
106112
pico_message("Defaulting platform (PICO_PLATFORM) to '${PICO_PLATFORM}' based on PICO_BOARD setting.")
107113
else()
108-
string(REGEX REPLACE "-.*" "" PICO_PLATFORM_PREFIX ${PICO_PLATFORM})
109-
string(REGEX REPLACE "-.*" "" PICO_SAVED_PLATFORM_PREFIX ${PICO_SAVED_PLATFORM})
114+
string(REGEX REPLACE "((host-)?(rp[0-9]+))(-.*)?" "\\3" PICO_PLATFORM_PREFIX ${PICO_PLATFORM})
115+
string(REGEX REPLACE "((host-)?(rp[0-9]+))(-.*)?" "\\3" PICO_SAVED_PLATFORM_PREFIX ${PICO_SAVED_PLATFORM})
116+
110117
if (PICO_PLATFORM_PREFIX STREQUAL PICO_SAVED_PLATFORM_PREFIX)
111118
# the PICO_PLATFORM specified based on the board is compatible based on the one we were
112119
# already using, so use that

cmake/preload/platforms/host-rp2350-arm-s.cmake

Whitespace-only changes.

cmake/preload/platforms/host-rp2350-riscv.cmake

Whitespace-only changes.

src/CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ macro(pico_simple_hardware_headers_target NAME)
121121

122122
target_include_directories(hardware_${NAME}_headers SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
123123
target_link_libraries(hardware_${NAME}_headers INTERFACE pico_base_headers)
124-
if (NOT PICO_NO_HARDWARE)
125-
target_link_libraries(hardware_${NAME}_headers INTERFACE hardware_structs hardware_claim_headers)
126-
endif()
124+
target_link_libraries(hardware_${NAME}_headers INTERFACE hardware_structs hardware_claim_headers)
127125
endif()
128126
endmacro()
129127

@@ -141,9 +139,7 @@ macro(pico_simple_hardware_headers_only_target NAME)
141139
# a headers only target should still have an explicit _headers library for consistency
142140
target_include_directories(hardware_${NAME}_headers SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
143141
target_link_libraries(hardware_${NAME}_headers INTERFACE pico_base_headers)
144-
if (NOT PICO_NO_HARDWARE)
145-
target_link_libraries(hardware_${NAME}_headers INTERFACE hardware_structs)
146-
endif()
142+
target_link_libraries(hardware_${NAME}_headers INTERFACE hardware_structs)
147143

148144
add_library(hardware_${NAME} INTERFACE)
149145
target_link_libraries(hardware_${NAME} INTERFACE hardware_${NAME}_headers)

src/cmake/no_hardware.cmake

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,43 @@ function(pico_add_extra_outputs TARGET)
2323
endfunction()
2424

2525
set(PICO_NO_HARDWARE "1" CACHE INTERNAL "")
26-
set(PICO_ON_DEVICE "0" CACHE INTERNAL "")
26+
set(PICO_ON_DEVICE "0" CACHE INTERNAL "")
27+
28+
# RP2040/RP2350 specific From standard build variants
29+
pico_add_subdirectory(${RP2_VARIANT_DIR}/hardware_regs)
30+
pico_add_subdirectory(${RP2_VARIANT_DIR}/hardware_structs)
31+
32+
# common
33+
pico_add_subdirectory(${COMMON_DIR}/boot_picobin_headers)
34+
pico_add_subdirectory(${COMMON_DIR}/boot_picoboot_headers)
35+
pico_add_subdirectory(${COMMON_DIR}/boot_uf2_headers)
36+
pico_add_subdirectory(${COMMON_DIR}/hardware_claim)
37+
pico_add_subdirectory(${COMMON_DIR}/pico_base_headers)
38+
pico_add_subdirectory(${COMMON_DIR}/pico_usb_reset_interface_headers)
39+
pico_add_subdirectory(${COMMON_DIR}/pico_bit_ops_headers)
40+
pico_add_subdirectory(${COMMON_DIR}/pico_binary_info)
41+
pico_add_subdirectory(${COMMON_DIR}/pico_divider_headers)
42+
pico_add_subdirectory(${COMMON_DIR}/pico_sync)
43+
pico_add_subdirectory(${COMMON_DIR}/pico_time)
44+
pico_add_subdirectory(${COMMON_DIR}/pico_util)
45+
pico_add_subdirectory(${COMMON_DIR}/pico_stdlib_headers)
46+
47+
# host-specific
48+
pico_add_subdirectory(${HOST_DIR}/hardware_divider)
49+
pico_add_subdirectory(${HOST_DIR}/hardware_gpio)
50+
pico_add_subdirectory(${HOST_DIR}/hardware_irq)
51+
pico_add_subdirectory(${HOST_DIR}/hardware_sync)
52+
pico_add_subdirectory(${HOST_DIR}/hardware_timer)
53+
pico_add_subdirectory(${HOST_DIR}/hardware_uart)
54+
pico_add_subdirectory(${HOST_DIR}/pico_bit_ops)
55+
pico_add_subdirectory(${HOST_DIR}/pico_divider)
56+
pico_add_subdirectory(${HOST_DIR}/pico_multicore)
57+
pico_add_subdirectory(${HOST_DIR}/pico_platform)
58+
pico_add_subdirectory(${HOST_DIR}/pico_rand)
59+
pico_add_subdirectory(${HOST_DIR}/pico_runtime)
60+
pico_add_subdirectory(${HOST_DIR}/pico_printf)
61+
pico_add_subdirectory(${HOST_DIR}/pico_status_led)
62+
pico_add_subdirectory(${HOST_DIR}/pico_stdio)
63+
pico_add_subdirectory(${HOST_DIR}/pico_stdlib)
64+
pico_add_subdirectory(${HOST_DIR}/pico_time_adapter)
65+
pico_add_subdirectory(${HOST_DIR}/pico_unique_id)

src/host-rp2040.cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
set(CMAKE_DIR cmake)
2+
set(COMMON_DIR common)
3+
set(HOST_DIR host)
4+
5+
# include everything needed to build against rp2040
6+
7+
set(PICO_RP2040 "1" CACHE INTERNAL "")
8+
set(PICO_RP2350 "0" CACHE INTERNAL "")
9+
set(PICO_RISCV "0" CACHE INTERNAL "")
10+
set(PICO_ARM "0" CACHE INTERNAL "")
11+
set(RP2_VARIANT_DIR ${CMAKE_CURRENT_LIST_DIR}/rp2040)
12+
set(PICO_CMSIS_DEVICE "RP2040" CACHE INTERNAL "")
13+
set(PICO_DEFAULT_FLASH_SIZE_BYTES "2 * 1024 * 1024")
14+
15+
include (${CMAKE_DIR}/no_hardware.cmake)
16+
17+
unset(CMAKE_DIR)
18+
unset(COMMON_DIR)
19+
unset(HOST_DIR)

src/host-rp2350-arm-s.cmake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
set(CMAKE_DIR cmake)
2+
set(COMMON_DIR common)
3+
set(HOST_DIR host)
4+
5+
# include everything needed to build against rp2350
6+
7+
set(PICO_RP2040 "0" CACHE INTERNAL "")
8+
set(PICO_RP2350 "1" CACHE INTERNAL "")
9+
set(PICO_RISCV "0" CACHE INTERNAL "")
10+
set(PICO_ARM "0" CACHE INTERNAL "")
11+
set(RP2_VARIANT_DIR ${CMAKE_CURRENT_LIST_DIR}/rp2350)
12+
set(PICO_PIO_VERSION "1" CACHE INTERNAL "")
13+
set(PICO_CMSIS_DEVICE "RP2350" CACHE INTERNAL "")
14+
set(PICO_DEFAULT_FLASH_SIZE_BYTES "4 * 1024 * 1024")
15+
16+
include (${CMAKE_DIR}/no_hardware.cmake)
17+
18+
unset(CMAKE_DIR)
19+
unset(COMMON_DIR)
20+
unset(HOST_DIR)

src/host.cmake

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/host/pico_platform/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22

33
if (NOT TARGET pico_platform_headers)
44
add_library(pico_platform_headers INTERFACE)
5-
65
target_compile_definitions(pico_platform_headers INTERFACE
76
PICO_NO_HARDWARE=1
87
PICO_ON_DEVICE=0
98
PICO_BUILD=1
109
)
1110

11+
if (DEFINED PICO_RP2040 AND ${PICO_RP2040})
12+
target_compile_definitions(pico_platform_headers INTERFACE PICO_RP2040=1)
13+
endif()
14+
15+
if (DEFINED PICO_RP2350 AND ${PICO_RP2350})
16+
target_compile_definitions(pico_platform_headers INTERFACE PICO_RP2350=1)
17+
endif()
18+
1219
target_include_directories(pico_platform_headers SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
1320
endif()
1421

0 commit comments

Comments
 (0)