Skip to content

Conversation

@shengt25
Copy link

Description

Problem

The FreeRTOS kernel RP2040 port attempts to automatically include the Pico SDK for users who haven't done so themselves. However, it doesn't propagate SDK version variables to the parent scope, causing pico_sdk_init() to fail with:

CMake Error at path/to/pico-sdk/tools/CMakeLists.txt:116 (find_package):
  find_package called with invalid argument ".."
Call Stack (most recent call first):
  path/to/pico-sdk/tools/CMakeLists.txt:224 (pico_init_pioasm)
  path/to/pico-sdk/src/rp2_common/pico_cyw43_driver/CMakeLists.txt:51 (pico_generate_pio_header)

Test Steps

Create a CMakeLists.txt like this:

include($ENV{FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake)
# FreeRTOS tries to help by including pico_sdk_import.cmake, but incompletely
project(TestProject C CXX ASM)
pico_sdk_init()  # FAILS

Or

include($ENV{FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake)
include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)  # Too late, the guard prevents re-init
project(TestProject C CXX ASM)
pico_sdk_init()  # FAILS

After this fix

Users can either:

  • Rely on FreeRTOS to include the Pico SDK
  • Include both in any order
# Rely on FreeRTOS
include($ENV{FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake)
project(TestProject C CXX ASM)
pico_sdk_init()  # SUCCESS

# Any include order
include($ENV{FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake)
include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
project(TestProject C CXX ASM)
pico_sdk_init()  # SUCCESS

Cause

When FreeRTOS is included first, it includes pico_sdk_import.cmake for users. However, FreeRTOS_Kernel_import.cmake calls add_subdirectory(), creating a child CMake scope. Inside the child scope, pico_sdk_import.cmake sets the SDK version variables (PICO_SDK_VERSION_MAJOR, PICO_SDK_VERSION_MINOR, PICO_SDK_VERSION_REVISION), but these variables are not propagated to the parent scope.
When users call pico_sdk_init() in their own CMakeLists.txt, the pico_init_pioasm() function tries to construct:

set(pioasm_VERSION_REQUIRED "${PICO_SDK_VERSION_MAJOR}.${PICO_SDK_VERSION_MINOR}.${PICO_SDK_VERSION_REVISION}")

Since these variables are undefined in the parent scope, this becomes "..", causing find_package() to fail at

find_package(pioasm ${pioasm_VERSION_REQUIRED} QUIET CONFIG NO_CMAKE_FIND_ROOT_PATH)

Checklist:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

Related Issue

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant