Skip to content

Commit

Permalink
Add Generation of jdebug files
Browse files Browse the repository at this point in the history
export PICO_MAKE_OZONE_PROJECT=1
Run cmake and then if PICO_MAKE_OZONE_PROJECT is defined it should
generate <target>.jdebug
  • Loading branch information
peterharperuk committed Nov 4, 2024
1 parent 3708588 commit 6830af8
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/cmake/on_device.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.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} $<TARGET_FILE:${TARGET}> ${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
Expand Down
70 changes: 70 additions & 0 deletions tools/generate_ozone_project.py
Original file line number Diff line number Diff line change
@@ -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)


0 comments on commit 6830af8

Please sign in to comment.