Skip to content

Commit 62f360a

Browse files
committed
Add a debugger selection options, some GUI rearrangement. Update readme
1 parent 359769c commit 62f360a

File tree

2 files changed

+55
-14
lines changed

2 files changed

+55
-14
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ optional arguments:
3434
Generate projects files for IDE. Options are: vscode
3535
-r, --runFromRAM Run the program from RAM rather than flash
3636
-uart, --uart Console output to UART (default)
37+
-nouart, --nouart Disable console output to UART
3738
-usb, --usb Console output to USB (disables other USB functionality)
39+
cpp, --cpp Generate C++ code
40+
-d DEBUGGER, --debugger DEBUGGER Select debugger (0 = SWD, 1 = PicoProbe)
3841
```
3942
You can list the features supported by the tools by using `./pico_project --list`. These features can
4043
be added to the project using the `--feature` options, this can be used multiple times.
@@ -47,7 +50,7 @@ The GUI version of the tool, run by adding `--gui` to the command line, uses `tk
4750

4851
You can add specific features to your project by selecting them from the check boxes on the GUI. This will ensure the build system adds the appropriate code to the build, and also adds simple example code to the project showing how to use the feature. There are a number of options available, which provide the following functionality.
4952

50-
Console Options | Description
53+
Console Options | Description
5154
----------------|-----------
5255
Console over UART | Enable a serial console over the UART. This is the default.
5356
Console over USB | Enable a console over the USB. The device will act as a USB serial port. This can be used in addition to or instead of the UART option, but note that when enabled other USB functionality is not possible.
@@ -57,14 +60,20 @@ Code Options | Description
5760
-------------| -----------
5861
Add examples for Pico library | Example code will be generated for some of the standard library features that by default are in the build, for example, UART support and HW dividers.
5962
Run from RAM | Usually, the build creates a binary that will be installed to the flash memory. This forces the binary to work directly from RAM.
63+
Generate C++ | Any generated source files will use the .cpp extension.
6064
Advanced | Brings up a table allowing selection of specific board build options. These options alter the way the features work, and should be used with caution.
6165

6266

6367
Build Options | Description
6468
--------------| -----------
65-
Run Build | Once the project has been created, build it. This will produce files ready for download to the Raspberry Pi Pico.
69+
Run Build | Once the project has been created, build it. This will produce files ready for download to the Raspberry Pi Pico.
6670
Overwrite Project | If a project already exists in the specified folder, overwrite it with the new project. This will overwrite any changes you may have made.
71+
72+
IDE Options | Description
73+
------------| -----------
74+
6775
Create VSCode Project | As well as the CMake files, also create the appropriate Visual Studio Code project files.
76+
Debugger | Use the specified debugger in the IDE
6877

6978

7079

pico_project.py

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
'div' : ("Low level HW Divider", "divider.c", "hardware/divider.h", "hardware_divider")
6161
}
6262

63+
debugger_list = ["SWD", "PicoProbe"]
64+
debugger_config_list = ["raspberrypi-swd.cfg", "picoprobe.cfg"]
65+
6366
DEFINES = 0
6467
INITIALISERS = 1
6568
# Could add an extra item that shows how to use some of the available functions for the feature
@@ -202,7 +205,7 @@
202205
isWindows = False
203206

204207
class Parameters():
205-
def __init__(self, sdkPath, projectRoot, projectName, gui, overwrite, build, features, projects, configs, runFromRAM, examples, uart, usb, cpp):
208+
def __init__(self, sdkPath, projectRoot, projectName, gui, overwrite, build, features, projects, configs, runFromRAM, examples, uart, usb, cpp, debugger):
206209
self.sdkPath = sdkPath
207210
self.projectRoot = projectRoot
208211
self.projectName = projectName
@@ -217,6 +220,7 @@ def __init__(self, sdkPath, projectRoot, projectName, gui, overwrite, build, fea
217220
self.wantUART = uart
218221
self.wantUSB = usb
219222
self.wantCPP = cpp
223+
self.debugger = debugger
220224

221225
def GetBackground():
222226
return 'white'
@@ -241,6 +245,8 @@ def RunGUI(sdkpath, args):
241245
ttk.Style().configure("TRadiobutton", foreground=GetTextColour(), background=GetBackground() )
242246
ttk.Style().configure("TLabelframe", foreground=GetTextColour(), background=GetBackground() )
243247
ttk.Style().configure("TLabelframe.Label", foreground=GetTextColour(), background=GetBackground() )
248+
ttk.Style().configure("TCombobox", foreground=GetTextColour(), background=GetBackground() )
249+
ttk.Style().configure("TListbox", foreground=GetTextColour(), background=GetBackground() )
244250

245251
app = ProjectWindow(root, sdkpath, args)
246252

@@ -668,14 +674,25 @@ def init_window(self, args):
668674

669675
self.wantBuild = tk.IntVar()
670676
self.wantBuild.set(args.build)
671-
ttk.Checkbutton(boptionsSubframe, text="Run build", variable=self.wantBuild).grid(row=0, column=0, padx=4, sticky=tk.W)
677+
ttk.Checkbutton(boptionsSubframe, text="Run build after generation", variable=self.wantBuild).grid(row=0, column=0, padx=4, sticky=tk.W)
672678

673679
self.wantOverwrite = tk.IntVar()
674680
self.wantOverwrite.set(args.overwrite)
675-
ttk.Checkbutton(boptionsSubframe, text="Overwrite project", variable=self.wantOverwrite).grid(row=0, column=1, padx=4, sticky=tk.W)
681+
ttk.Checkbutton(boptionsSubframe, text="Overwrite project if it already exists", variable=self.wantOverwrite).grid(row=0, column=1, padx=4, sticky=tk.W)
682+
683+
optionsRow += 2
684+
685+
vscodeoptionsSubframe = ttk.LabelFrame(mainFrame, relief=tk.RIDGE, borderwidth=2, text="IDE Options")
686+
vscodeoptionsSubframe.grid(row=optionsRow, column=0, columnspan=5, rowspan=2, padx=5, pady=5, ipadx=5, ipady=3, sticky=tk.E+tk.W)
676687

677688
self.wantVSCode = tk.IntVar()
678-
ttk.Checkbutton(boptionsSubframe, text="Create VSCode project", variable=self.wantVSCode).grid(row=0, column=2, padx=4, sticky=tk.W)
689+
ttk.Checkbutton(vscodeoptionsSubframe, text="Create VSCode project", variable=self.wantVSCode).grid(row=0, column=0, padx=4, sticky=tk.W)
690+
691+
ttk.Label(vscodeoptionsSubframe, text = " Debugger:").grid(row=0, column=1, padx=4, sticky=tk.W)
692+
693+
self.debugger = ttk.Combobox(vscodeoptionsSubframe, values=debugger_list, state="readonly")
694+
self.debugger.grid(row=0, column=2, padx=4, sticky=tk.W)
695+
self.debugger.current(args.debugger)
679696

680697
optionsRow += 2
681698

@@ -717,7 +734,8 @@ def OK(self):
717734
p = Parameters(sdkPath=self.sdkpath, projectRoot=Path(projectPath), projectName=self.projectName.get(),
718735
gui=True, overwrite=self.wantOverwrite.get(), build=self.wantBuild.get(),
719736
features=features, projects=projects, configs=self.configs, runFromRAM=self.wantRunFromRAM.get(),
720-
examples=self.wantExamples.get(), uart=self.wantUART.get(), usb=self.wantUSB.get(), cpp=self.wantCPP.get())
737+
examples=self.wantExamples.get(), uart=self.wantUART.get(), usb=self.wantUSB.get(), cpp=self.wantCPP.get(),
738+
debugger=self.debugger.current())
721739

722740
DoEverything(self, p)
723741

@@ -781,6 +799,7 @@ def ParseCommandLine():
781799
parser.add_argument("-nouart", "--nouart", action='store_true', default=0, help="Disable console output to UART")
782800
parser.add_argument("-usb", "--usb", action='store_true', help="Console output to USB (disables other USB functionality")
783801
parser.add_argument("-cpp", "--cpp", action='store_true', default=0, help="Generate C++ code")
802+
parser.add_argument("-d", "--debugger", type=int, help="Select debugger (0 = SWD, 1 = PicoProbe)", default=0)
784803

785804
return parser.parse_args()
786805

@@ -938,12 +957,15 @@ def GenerateCMake(folder, params):
938957

939958

940959
# Generates the requested project files, if any
941-
def generateProjectFiles(projectPath, projectName, sdkPath, projects):
960+
def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger):
942961

943962
oldCWD = os.getcwd()
944963

945964
os.chdir(projectPath)
946965

966+
deb = debugger_config_list[debugger]
967+
968+
# if debugger==0 else 'picoprobe.cfg
947969
for p in projects :
948970
if p == 'vscode':
949971
v1 = ('{\n'
@@ -955,17 +977,23 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects):
955977
' {\n'
956978
' "name": "Cortex Debug",\n'
957979
' "cwd": "${workspaceRoot}",\n'
958-
' "executable": "${workspaceRoot}/build/' + projectName + '.elf",\n'
980+
' "executable": "${command:cmake.launchTargetPath}",\n'
959981
' "request": "launch",\n'
960982
' "type": "cortex-debug",\n'
961983
' "servertype": "openocd",\n'
962-
' "device": "Pico2040",\n'
984+
' "gdbPath": "gdb-multiarch",\n'
985+
' "device": "RP2040",\n'
963986
' "configFiles": [\n' + \
964-
' "interface/raspberrypi-swd.cfg",\n' + \
987+
' "interface/' + deb + '",\n' + \
965988
' "target/rp2040.cfg"\n' + \
966989
' ],\n' + \
967-
' "svdFile": "' + str(sdkPath) + '/src/rp2040/hardware_regs/rp2040.svd",\n'
990+
' "svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd",\n'
968991
' "runToMain": true,\n'
992+
' // Give restart the same functionality as runToMain\n'
993+
' "postRestartCommands": [\n'
994+
' "break main",\n'
995+
' "continue"\n'
996+
' ]\n'
969997
' }\n'
970998
' ]\n'
971999
'}\n')
@@ -1118,7 +1146,7 @@ def DoEverything(parent, params):
11181146
os.system(cmakeCmd)
11191147

11201148
if params.projects:
1121-
generateProjectFiles(projectPath, params.projectName, params.sdkPath, params.projects)
1149+
generateProjectFiles(projectPath, params.projectName, params.sdkPath, params.projects, params.debugger)
11221150

11231151
if params.wantBuild:
11241152
if params.wantGUI:
@@ -1138,6 +1166,10 @@ def DoEverything(parent, params):
11381166
if args.nouart:
11391167
args.uart = False
11401168

1169+
# TODO this could be better, need some constants etc
1170+
if args.debugger > 1:
1171+
args.debugger = 0
1172+
11411173
# Check we have everything we need to compile etc
11421174
c = CheckPrerequisites()
11431175

@@ -1191,7 +1223,7 @@ def DoEverything(parent, params):
11911223
p = Parameters(sdkPath=sdkPath, projectRoot=projectRoot, projectName=args.name,
11921224
gui=False, overwrite=args.overwrite, build=args.build, features=args.feature,
11931225
projects=args.project, configs=(), runFromRAM=args.runFromRAM,
1194-
examples=args.examples, uart=args.uart, usb=args.usb, cpp=args.cpp)
1226+
examples=args.examples, uart=args.uart, usb=args.usb, cpp=args.cpp, debugger=args.debugger)
11951227

11961228
DoEverything(None, p)
11971229

0 commit comments

Comments
 (0)