diff --git a/CMakeLists.txt b/CMakeLists.txt index 92ea05a53..b36d2e79f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,8 @@ cmake_minimum_required(VERSION 3.12) +# build for the Raspberry Pi Debug Probe by default +set(PICO_BOARD debug_probe CACHE STRING "Board type") + set(CMAKE_BUILD_TYPE RelWithDebInfo) include(pico_sdk_import.cmake) @@ -11,10 +14,6 @@ project(debugprobe) pico_sdk_init() -if (${PICO_SDK_VERSION_MAJOR} LESS 2) - message(SEND_ERROR "Version 2 of the Pico SDK is required to compile this project. Please update your installation at ${PICO_SDK_PATH}") -endif () - add_executable(debugprobe src/probe_config.c src/main.c @@ -65,25 +64,12 @@ target_compile_definitions (debugprobe PRIVATE PICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1 ) -option (DEBUG_ON_PICO "Compile firmware for the Pico instead of Debug Probe" OFF) -if (DEBUG_ON_PICO) - target_compile_definitions (debugprobe PRIVATE - DEBUG_ON_PICO=1 +if (NOT PICO_BOARD STREQUAL "debug_probe") + set_target_properties(debugprobe PROPERTIES + OUTPUT_NAME "debugprobe_on_${PICO_BOARD}" ) - if (PICO_BOARD STREQUAL "pico") - set_target_properties(debugprobe PROPERTIES - OUTPUT_NAME "debugprobe_on_pico" - ) - elseif (PICO_BOARD STREQUAL "pico2") - set_target_properties(debugprobe PROPERTIES - OUTPUT_NAME "debugprobe_on_pico2" - ) - else () - message(SEND_ERROR "Unsupported board ${PICO_BOARD}") - endif () endif () - target_link_libraries(debugprobe PRIVATE pico_multicore pico_stdlib diff --git a/README.md b/README.md index 7f3add41d..89526ba61 100644 --- a/README.md +++ b/README.md @@ -41,9 +41,9 @@ Done! You should now have a `debugprobe.uf2` that you can upload to your Debug P ## Building for the Pico 1 -If you want to create the version that runs on the Pico, then you need to invoke `cmake` in the sequence above with the `DEBUG_ON_PICO=ON` option: +If you want to create the version that runs on the Pico, then you need to invoke `cmake` in the sequence above with the `-DPICO_BOARD=pico` option: ``` -cmake -DDEBUG_ON_PICO=ON .. +cmake -DPICO_BOARD=pico .. ``` This will build with the configuration for the Pico and call the output program `debugprobe_on_pico.uf2`, as opposed to `debugprobe.uf2` for the accessory hardware. @@ -61,7 +61,7 @@ git submodule sync git submodule update --init --recursive mkdir build-pico2 cd build-pico2 -cmake -DDEBUG_ON_PICO=1 -DPICO_BOARD=pico2 ../ +cmake -DPICO_BOARD=pico2 ../ ``` This will build with the configuration for the Pico 2 and call the output program `debugprobe_on_pico2.uf2`. diff --git a/include/board_config.h b/include/board_config.h new file mode 100644 index 000000000..d34e854ea --- /dev/null +++ b/include/board_config.h @@ -0,0 +1,39 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2023 Raspberry Pi (Trading) Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +#ifndef BOARD_CONFIG_H_ +#define BOARD_CONFIG_H_ + +#include "pico/stdlib.h" +#if defined(RASPBERRYPI_DEBUG_PROBE) +#include "board_debug_probe_config.h" +#elif defined(RASPBERRYPI_PICO) || defined(RASPBERRYPI_PICO2) +#include "board_pico_config.h" +#else +#error Unsupported board +//#include "board_example_config.h" +#endif + +#endif diff --git a/include/board_debug_probe_config.h b/include/board_debug_probe_config.h index 3e7fc353c..180f3da29 100644 --- a/include/board_debug_probe_config.h +++ b/include/board_debug_probe_config.h @@ -23,8 +23,8 @@ * */ -#ifndef BOARD_DEBUG_PROBE_H_ -#define BOARD_DEBUG_PROBE_H_ +#ifndef BOARD_DEBUG_PROBE_CONFIG_H_ +#define BOARD_DEBUG_PROBE_CONFIG_H_ #define PROBE_IO_SWDI #define PROBE_CDC_UART @@ -44,11 +44,11 @@ #define PROBE_UART_INTERFACE uart1 #define PROBE_UART_BAUDRATE 115200 -#define PROBE_USB_CONNECTED_LED 2 -#define PROBE_DAP_CONNECTED_LED 15 -#define PROBE_DAP_RUNNING_LED 16 -#define PROBE_UART_RX_LED 7 -#define PROBE_UART_TX_LED 8 +#define PROBE_USB_CONNECTED_LED DEBUG_PROBE_USB_CONNECTED_LED_PIN +#define PROBE_DAP_CONNECTED_LED DEBUG_PROBE_DAP_CONNECTED_LED_PIN +#define PROBE_DAP_RUNNING_LED DEBUG_PROBE_DAP_RUNNING_LED_PIN +#define PROBE_UART_RX_LED DEBUG_PROBE_UART_RX_LED_PIN +#define PROBE_UART_TX_LED DEBUG_PROBE_UART_TX_LED_PIN #define PROBE_PRODUCT_STRING "Debug Probe (CMSIS-DAP)" diff --git a/include/board_example_config.h b/include/board_example_config.h index 0e0f13130..2c731d8b1 100644 --- a/include/board_example_config.h +++ b/include/board_example_config.h @@ -23,8 +23,8 @@ * */ -#ifndef BOARD_EXAMPLE_H_ -#define BOARD_EXAMPLE_H_ +#ifndef BOARD_EXAMPLE_CONFIG_H_ +#define BOARD_EXAMPLE_CONFIG_H_ #error "Example board configuration requested - specify PICO_BOARD and re-run CMake." /* Select one of these. */ diff --git a/include/board_pico_config.h b/include/board_pico_config.h index dd22f0a74..f732fb707 100644 --- a/include/board_pico_config.h +++ b/include/board_pico_config.h @@ -23,8 +23,8 @@ * */ -#ifndef BOARD_PICO_H_ -#define BOARD_PICO_H_ +#ifndef BOARD_PICO_CONFIG_H_ +#define BOARD_PICO_CONFIG_H_ #define PROBE_IO_RAW #define PROBE_CDC_UART diff --git a/pico_sdk_import.cmake b/pico_sdk_import.cmake index d4773f8fe..e89be1e5c 100644 --- a/pico_sdk_import.cmake +++ b/pico_sdk_import.cmake @@ -71,4 +71,18 @@ endif () set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) +# We need to include the Pico SDK version file and test the SDK's +# version *before* including the standard SDK init file. If the SDK is +# old and PICO_BOARD is set to "debug_probe" (the default), including +# the standard init file fails because it can't find a board definition +# for "debug_probe" (which doesn't exist prior to SDK version 2.3.0). +if (NOT EXISTS ${PICO_SDK_PATH}/pico_sdk_version.cmake) + message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not contain a Raspberry Pi Pico SDK version file") +endif () + +include(${PICO_SDK_PATH}/pico_sdk_version.cmake) +if (${PICO_SDK_VERSION_STRING} VERSION_LESS "2.3.0") + message(FATAL_ERROR "Version 2.3.0 of the Pico SDK is required to compile this project. Please update your installation at ${PICO_SDK_PATH}") +endif () + include(${PICO_SDK_INIT_CMAKE_FILE}) diff --git a/src/probe_config.h b/src/probe_config.h index 5c5e14909..ff12f0413 100644 --- a/src/probe_config.h +++ b/src/probe_config.h @@ -63,14 +63,7 @@ do { \ #define probe_dump(format,...) ((void)0) #endif -// TODO tie this up with PICO_BOARD defines in the main SDK - -#ifdef DEBUG_ON_PICO -#include "board_pico_config.h" -#else -#include "board_debug_probe_config.h" -#endif -//#include "board_example_config.h" +#include "board_config.h" // Add the configuration to binary information void bi_decl_config();