From 6830af8b881d275e1dea99e964f90cf03f95ae56 Mon Sep 17 00:00:00 2001 From: Peter Harper Date: Mon, 4 Nov 2024 19:17:41 +0000 Subject: [PATCH] Add Generation of jdebug files export PICO_MAKE_OZONE_PROJECT=1 Run cmake and then if PICO_MAKE_OZONE_PROJECT is defined it should generate .jdebug --- src/cmake/on_device.cmake | 9 +++++ tools/generate_ozone_project.py | 70 +++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100755 tools/generate_ozone_project.py diff --git a/src/cmake/on_device.cmake b/src/cmake/on_device.cmake index 5cabf3cc9..4ca2a4860 100644 --- a/src/cmake/on_device.cmake +++ b/src/cmake/on_device.cmake @@ -85,6 +85,15 @@ function(pico_add_extra_outputs TARGET) if (NOT (PICO_NO_UF2 OR PICO_NO_PICOTOOL)) pico_add_uf2_output(${TARGET}) endif() + + if (DEFINED ENV{PICO_MAKE_OZONE_PROJECT}) + set(OZONE_PROJECT_FILE $>,$,$>.jdebug) + set(OZONE_PROJECT_PY ${PICO_SDK_PATH}/tools/generate_ozone_project.py) + add_custom_command(TARGET ${TARGET} POST_BUILD + COMMAND python ${OZONE_PROJECT_PY} ${PICO_PLATFORM} $ ${OZONE_PROJECT_FILE} + VERBATIM) + endif() + endfunction() # PICO_CMAKE_CONFIG: PICO_NO_HARDWARE, Option as to whether the build is not targeting an RP2040 or RP2350 device, type=bool, default=1 when PICO_PLATFORM is host, 0 otherwise, group=build diff --git a/tools/generate_ozone_project.py b/tools/generate_ozone_project.py new file mode 100755 index 000000000..810843de3 --- /dev/null +++ b/tools/generate_ozone_project.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2024 Raspberry Pi (Trading) Ltd. +# +# SPDX-License-Identifier: BSD-3-Clause +# +# +# Little script to build a header file including every other header file in the SDK! +# (also checks we don't have "conflicting" header-filenames) +# Edit the IGNORE_DIRS variable to filter out which directories get looked in. +# +# Usage: +# +# tools/generate_ozone_project PICO_PLATFORM ELF-File Ozone-Project-File +# +# Example: +# # ./generate_ozone_project 'rp2350-arm-s' '/Users/mringwal/Projects/pico/pico-examples/ninja/pico_w/bt/gatt_counter/picow_bt_example_gatt_counter_poll.elf' 'project.jdebug' + +import sys + +# Inline project template +project_template = \ +''' + +// Stripped down version of generic Ozone project file for pico-sdk + +/********************************************************************* +* +* OnProjectLoad +* +* Function description +* Project load routine. Required. +* +********************************************************************** +*/ +void OnProjectLoad (void) {{ + + Project.SetDevice ("{device_type}"); + Project.SetTargetIF ("SWD"); + Project.SetTIFSpeed ("4 MHz"); + Project.AddSvdFile ("$(InstallDir)/Config/CPU/{cpu_type}.svd"); + + File.Open ("{elf_file}"); +}} +''' + +# Map PICO_PLATFORM to SEGGER Ozone +device_mapping = { + 'rp2040' : ('RP2040_M0_0', 'Cortex-M0' ), + 'rp2350-arm-s' : ('RP2350_M33_0', 'Cortex-M33F'), + 'rp2350-riscv' : ('RP2350_RV32_0', 'RV32IFD' ) +} + +def generate_project(pico_platform, elf_file, out_file): + # Get platform info + device_type, cpu_type = device_mapping[pico_platform] + with open(out_file, 'w') as writer: + writer.write(project_template.format(device_type=device_type, cpu_type=cpu_type, elf_file=elf_file)) + + +# Input from command line +if len(sys.argv) != 4: + print("Usage: {} PICO_PLATFORM ELF-File Ozone-Project-File".format(os.path.basename(sys.argv[0]))) + sys.exit(1) +_, PICO_PLATFORM, ELF_FILE, OUT_FILE = sys.argv + +# generate project +generate_project(PICO_PLATFORM, ELF_FILE, OUT_FILE) + +