Add CMake function docs

This commit is contained in:
William Vinnicombe 2025-10-08 11:07:30 +01:00
parent 4c3543e4e5
commit 3326a5fb86
3 changed files with 71 additions and 25 deletions

View file

@ -110,6 +110,7 @@ if (NOT PICO_BARE_METAL)
if (PICO_COMBINED_DOCS OR NOT PICO_RP2040)
pico_add_subdirectory(rp2_common/pico_sha256)
pico_add_subdirectory(rp2_common/pico_secure)
endif()
pico_add_subdirectory(rp2_common/pico_stdio_semihosting)
@ -118,7 +119,6 @@ if (NOT PICO_BARE_METAL)
if (NOT PICO_RISCV)
pico_add_subdirectory(rp2_common/cmsis)
pico_add_subdirectory(rp2_common/pico_secure)
endif()
pico_add_subdirectory(rp2_common/tinyusb)
pico_add_subdirectory(rp2_common/pico_stdio_usb)

View file

@ -8,20 +8,32 @@ if (NOT TARGET pico_secure)
pico_mirrored_target_link_libraries(pico_secure INTERFACE
pico_bootrom)
function(pico_set_security_defines SECURE_TARGET NONSECURE_TARGET)
set(options
ALLOW_NONSECURE_STDIO
ALLOW_NONSECURE_RAND
ALLOW_NONSECURE_DMA
ALLOW_NONSECURE_USER_IRQ
ALLOW_NONSECURE_PIO
ALLOW_NONSECURE_GPIO
ALLOW_NONSECURE_USB
ALLOW_NONSECURE_RESETS
)
set(oneValueArgs
ASSIGN_NONSECURE_TIMER
)
# pico_set_security_options(SECURE_TARGET NONSECURE_TARGET <OPTIONS>...)
# \brief_nodesc\ Set matching security options for a secure and non-secure target
#
# Set matching security options for a secure and non-secure target, so they have a compatible set of features.
#
# Also sets PICO_SECURE=1 and PICO_NONSECURE=1 on the secure and non-secure targets respectively, along with
# any other required defines (eg PICO_USE_STACK_GUARDS=1 on the secure target).
#
# The options are:
# - STDIO: Allow non-secure to use secure stdio
# - RAND: Allow non-secure to get random numbers
# - DMA: Allow non-secure to request DMA channels
# - USER_IRQ: Allow non-secure to request user IRQs
# - PIO: Allow non-secure to request PIOs
# - GPIO: Allow non-secure to access GPIOs assigned to non-secure (eg with gpio_assign_to_ns)
# - USB: Allow non-secure to access USB
# - RESETS: Allow non-secure to access resets specified by PICO_ALLOW_NONSECURE_RESETS_MASK (automatically set if USB is set)
# - NONSECURE_TIMER <index>: Assign specified timer to non-secure
#
# \param\ SECURE_TARGET The secure target
# \param\ NONSECURE_TARGET The non-secure target
# \param\ OPTIONS The options to set
function(pico_set_security_options SECURE_TARGET NONSECURE_TARGET)
set(options STDIO RAND DMA USER_IRQ PIO GPIO USB RESETS)
set(oneValueArgs NONSECURE_TIMER)
cmake_parse_arguments(PARSE_ARGV 2 OPTS "${options}" "${oneValueArgs}" "")
target_compile_definitions(${SECURE_TARGET} PRIVATE
@ -36,23 +48,20 @@ if (NOT TARGET pico_secure)
)
# Options that require resets
if ((NOT OPTS_ALLOW_NONSECURE_RESETS) AND OPTS_ALLOW_NONSECURE_USB)
set(OPTS_ALLOW_NONSECURE_RESETS 1)
if ((NOT OPTS_RESETS) AND OPTS_USB)
set(OPTS_RESETS 1)
endif()
foreach(arg IN LISTS options)
if (OPTS_${arg})
target_compile_definitions(${SECURE_TARGET} PRIVATE PICO_${arg}=1)
target_compile_definitions(${NONSECURE_TARGET} PRIVATE PICO_${arg}=1)
target_compile_definitions(${SECURE_TARGET} PRIVATE PICO_ALLOW_NONSECURE_${arg}=1)
target_compile_definitions(${NONSECURE_TARGET} PRIVATE PICO_ALLOW_NONSECURE_${arg}=1)
endif()
endforeach()
if (OPTS_ASSIGN_NONSECURE_TIMER)
target_compile_definitions(${SECURE_TARGET} PRIVATE PICO_ASSIGN_NONSECURE_TIMER=${OPTS_ASSIGN_NONSECURE_TIMER})
target_compile_definitions(${NONSECURE_TARGET} PRIVATE PICO_DEFAULT_TIMER=${OPTS_ASSIGN_NONSECURE_TIMER})
if (OPTS_NONSECURE_TIMER)
target_compile_definitions(${SECURE_TARGET} PRIVATE PICO_ASSIGN_NONSECURE_TIMER=${OPTS_NONSECURE_TIMER})
target_compile_definitions(${NONSECURE_TARGET} PRIVATE PICO_DEFAULT_TIMER=${OPTS_NONSECURE_TIMER})
endif()
endfunction()
endif()

View file

@ -742,3 +742,40 @@ function(picotool_postprocess_binary TARGET)
endif()
endif()
endfunction()
# pico_concatenate_uf2_outputs(COMBINED_TARGET <TARGETS>...)
# \brief_nodesc\ Concatenate UF2 outputs into a single UF2 file
#
# Concatenate UF2 outputs from multiple targets into a single UF2 file, in the order they're passed to the function
#
# This can be used in conjunction with a partition table with no_reboot_on_uf2_download set on some partitions,
# to allow loading multiple partitions with a single UF2 file. For example, with this partition table you could concatenate
# rp2350-arm-ns and rp2350-arm-s binaries into a single UF2 file for loading into the main and owned partitions in one shot:
# ```
# partitions:
# 0(A) uf2 { 'rp2350-arm-s' }
# 1(B w/ 0) uf2 { 'rp2350-arm-s' }
# 2(A ob/ 0) uf2 { 'rp2350-arm-ns' }, no_reboot_on_uf2_download, ab_non_bootable_owner_affinity
# 3(B w/ 2) uf2 { 'rp2350-arm-ns' }, no_reboot_on_uf2_download, ab_non_bootable_owner_affinity
# ```
#
# NOTE: This does not modify the UF2 data structures, so the chip will still see multiple UF2 files,
# this just concatenates them into a single file on the host.
#
# \param\ COMBINED_TARGET The name of the combined UF2 target
# \param\ TARGETS The targets to combine
function(pico_concatenate_uf2_outputs COMBINED_TARGET)
list(TRANSFORM ARGN PREPEND ${CMAKE_CURRENT_BINARY_DIR}/ OUTPUT_VARIABLE UF2S)
list(TRANSFORM UF2S APPEND .uf2)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${COMBINED_TARGET}.uf2
COMMAND ${CMAKE_COMMAND} -E cat
${UF2S}
> ${CMAKE_CURRENT_BINARY_DIR}/${COMBINED_TARGET}.uf2
DEPENDS ${ARGN}
COMMAND_EXPAND_LISTS)
add_custom_target(${COMBINED_TARGET} ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${COMBINED_TARGET}.uf2)
endfunction()