Skip to content

Commit 721f7ad

Browse files
committed
update: typo in README
2 parents 5ba387a + f88cf8d commit 721f7ad

File tree

2 files changed

+98
-21
lines changed

2 files changed

+98
-21
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ optional arguments:
3535
Generate projects files for IDE. Options are: vscode
3636
-r, --runFromRAM Run the program from RAM rather than flash
3737
-uart, --uart Console output to UART (default)
38-
-usb, --usb Console output to USB (disables other USB functionality
38+
-nouart, --nouart Disable console output to UART
39+
-usb, --usb Console output to USB (disables other USB functionality)
40+
cpp, --cpp Generate C++ code
41+
-d DEBUGGER, --debugger DEBUGGER Select debugger (0 = SWD, 1 = PicoProbe)
3942
```
4043
You can list the features supported by the tools by using `./pico_project --list`. These features can
4144
be added to the project using the `--feature` options, this can be used multiple times.
@@ -58,14 +61,20 @@ Code Options | Description
5861
-------------| -----------
5962
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.
6063
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.
64+
Generate C++ | Any generated source files will use the .cpp extension.
6165
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.
6266

6367

6468
Build Options | Description
6569
--------------| -----------
6670
Run Build | Once the project has been created, build it. This will produce files ready for download to the Raspberry Pi Pico.
6771
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.
72+
73+
IDE Options | Description
74+
------------| -----------
75+
6876
Create VSCode Project | As well as the CMake files, also create the appropriate Visual Studio Code project files.
77+
Debugger | Use the specified debugger in the IDE
6978

7079

7180

pico_project.py

Lines changed: 88 additions & 20 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,8 @@
202205
isWindows = False
203206

204207
class Parameters():
205-
def __init__(self, sdkPath, projectRoot, projectName, gui, overwrite, build, features, projects, configs, runFromRAM, examples, uart, usb):
208+
def __init__(self, sdkPath, projectRoot, projectName, gui, overwrite, build, features, projects,
209+
configs, runFromRAM, examples, uart, usb, cpp, debugger, exceptions, rtti):
206210
self.sdkPath = sdkPath
207211
self.projectRoot = projectRoot
208212
self.projectName = projectName
@@ -216,6 +220,10 @@ def __init__(self, sdkPath, projectRoot, projectName, gui, overwrite, build, fea
216220
self.wantExamples = examples
217221
self.wantUART = uart
218222
self.wantUSB = usb
223+
self.wantCPP = cpp
224+
self.debugger = debugger
225+
self.exceptions = exceptions
226+
self.rtti = rtti
219227

220228
def GetBackground():
221229
return 'white'
@@ -240,6 +248,8 @@ def RunGUI(sdkpath, args):
240248
ttk.Style().configure("TRadiobutton", foreground=GetTextColour(), background=GetBackground() )
241249
ttk.Style().configure("TLabelframe", foreground=GetTextColour(), background=GetBackground() )
242250
ttk.Style().configure("TLabelframe.Label", foreground=GetTextColour(), background=GetBackground() )
251+
ttk.Style().configure("TCombobox", foreground=GetTextColour(), background=GetBackground() )
252+
ttk.Style().configure("TListbox", foreground=GetTextColour(), background=GetBackground() )
243253

244254
app = ProjectWindow(root, sdkpath, args)
245255

@@ -642,7 +652,7 @@ def init_window(self, args):
642652

643653
# Code options section
644654
coptionsSubframe = ttk.LabelFrame(mainFrame, relief=tk.RIDGE, borderwidth=2, text="Code Options")
645-
coptionsSubframe.grid(row=optionsRow, column=0, columnspan=5, rowspan=2, padx=5, pady=5, ipadx=5, ipady=3, sticky=tk.E+tk.W)
655+
coptionsSubframe.grid(row=optionsRow, column=0, columnspan=5, rowspan=3, padx=5, pady=5, ipadx=5, ipady=3, sticky=tk.E+tk.W)
646656

647657
self.wantExamples = tk.IntVar()
648658
self.wantExamples.set(args.examples)
@@ -652,9 +662,21 @@ def init_window(self, args):
652662
self.wantRunFromRAM.set(args.runFromRAM)
653663
ttk.Checkbutton(coptionsSubframe, text="Run from RAM", variable=self.wantRunFromRAM).grid(row=0, column=1, padx=4, sticky=tk.W)
654664

665+
self.wantCPP = tk.IntVar()
666+
self.wantCPP.set(args.cpp)
667+
ttk.Checkbutton(coptionsSubframe, text="Generate C++", variable=self.wantCPP).grid(row=0, column=3, padx=4, sticky=tk.W)
668+
655669
ttk.Button(coptionsSubframe, text="Advanced...", command=self.config).grid(row=0, column=4, sticky=tk.E)
656670

657-
optionsRow += 2
671+
self.wantCPPExceptions = tk.IntVar()
672+
self.wantCPPExceptions.set(args.cppexceptions)
673+
ttk.Checkbutton(coptionsSubframe, text="Enable C++ exceptions", variable=self.wantCPPExceptions).grid(row=1, column=0, padx=4, sticky=tk.W)
674+
675+
self.wantCPPRTTI = tk.IntVar()
676+
self.wantCPPRTTI.set(args.cpprtti)
677+
ttk.Checkbutton(coptionsSubframe, text="Enable C++ RTTI", variable=self.wantCPPRTTI).grid(row=1, column=1, padx=4, sticky=tk.W)
678+
679+
optionsRow += 3
658680

659681
# Build Options section
660682

@@ -663,14 +685,25 @@ def init_window(self, args):
663685

664686
self.wantBuild = tk.IntVar()
665687
self.wantBuild.set(args.build)
666-
ttk.Checkbutton(boptionsSubframe, text="Run build", variable=self.wantBuild).grid(row=0, column=0, padx=4, sticky=tk.W)
688+
ttk.Checkbutton(boptionsSubframe, text="Run build after generation", variable=self.wantBuild).grid(row=0, column=0, padx=4, sticky=tk.W)
667689

668690
self.wantOverwrite = tk.IntVar()
669691
self.wantOverwrite.set(args.overwrite)
670-
ttk.Checkbutton(boptionsSubframe, text="Overwrite project", variable=self.wantOverwrite).grid(row=0, column=1, padx=4, sticky=tk.W)
692+
ttk.Checkbutton(boptionsSubframe, text="Overwrite project if it already exists", variable=self.wantOverwrite).grid(row=0, column=1, padx=4, sticky=tk.W)
693+
694+
optionsRow += 2
695+
696+
vscodeoptionsSubframe = ttk.LabelFrame(mainFrame, relief=tk.RIDGE, borderwidth=2, text="IDE Options")
697+
vscodeoptionsSubframe.grid(row=optionsRow, column=0, columnspan=5, rowspan=2, padx=5, pady=5, ipadx=5, ipady=3, sticky=tk.E+tk.W)
671698

672699
self.wantVSCode = tk.IntVar()
673-
ttk.Checkbutton(boptionsSubframe, text="Create VSCode project", variable=self.wantVSCode).grid(row=0, column=2, padx=4, sticky=tk.W)
700+
ttk.Checkbutton(vscodeoptionsSubframe, text="Create VSCode project", variable=self.wantVSCode).grid(row=0, column=0, padx=4, sticky=tk.W)
701+
702+
ttk.Label(vscodeoptionsSubframe, text = " Debugger:").grid(row=0, column=1, padx=4, sticky=tk.W)
703+
704+
self.debugger = ttk.Combobox(vscodeoptionsSubframe, values=debugger_list, state="readonly")
705+
self.debugger.grid(row=0, column=2, padx=4, sticky=tk.W)
706+
self.debugger.current(args.debugger)
674707

675708
optionsRow += 2
676709

@@ -712,7 +745,8 @@ def OK(self):
712745
p = Parameters(sdkPath=self.sdkpath, projectRoot=Path(projectPath), projectName=self.projectName.get(),
713746
gui=True, overwrite=self.wantOverwrite.get(), build=self.wantBuild.get(),
714747
features=features, projects=projects, configs=self.configs, runFromRAM=self.wantRunFromRAM.get(),
715-
examples=self.wantExamples.get(), uart=self.wantUART.get(), usb=self.wantUSB.get())
748+
examples=self.wantExamples.get(), uart=self.wantUART.get(), usb=self.wantUSB.get(), cpp=self.wantCPP.get(),
749+
debugger=self.debugger.current(), exceptions=self.wantCPPExceptions, rtti=self.wantCPPRTTI)
716750

717751
DoEverything(self, p)
718752

@@ -774,14 +808,22 @@ def ParseCommandLine():
774808
parser.add_argument("-p", "--project", action='append', help="Generate projects files for IDE. Options are: vscode")
775809
parser.add_argument("-r", "--runFromRAM", action='store_true', help="Run the program from RAM rather than flash")
776810
parser.add_argument("-uart", "--uart", action='store_true', default=1, help="Console output to UART (default)")
811+
parser.add_argument("-nouart", "--nouart", action='store_true', default=0, help="Disable console output to UART")
777812
parser.add_argument("-usb", "--usb", action='store_true', help="Console output to USB (disables other USB functionality")
813+
parser.add_argument("-cpp", "--cpp", action='store_true', default=0, help="Generate C++ code")
814+
parser.add_argument("-cpprtti", "--cpprtti", action='store_true', default=0, help="Enable C++ RTTI (Uses more memory)")
815+
parser.add_argument("-cppex", "--cppexceptions", action='store_true', default=0, help="Enable C++ exceptions (Uses more memory)")
816+
parser.add_argument("-d", "--debugger", type=int, help="Select debugger (0 = SWD, 1 = PicoProbe)", default=0)
778817

779818
return parser.parse_args()
780819

781820

782-
def GenerateMain(folder, projectName, features):
821+
def GenerateMain(folder, projectName, features, cpp):
783822

784-
filename = Path(folder) / (projectName + '.c')
823+
if cpp:
824+
filename = Path(folder) / (projectName + '.cpp')
825+
else:
826+
filename = Path(folder) / (projectName + '.c')
785827

786828
file = open(filename, 'w')
787829

@@ -853,7 +895,7 @@ def GenerateCMake(folder, params):
853895
)
854896

855897
cmake_header3 = (
856-
"# Initialise the Pico SDK\n"
898+
"\n# Initialise the Pico SDK\n"
857899
"pico_sdk_init()\n\n"
858900
"# Add executable. Default name is the project name, version 0.1\n\n"
859901
)
@@ -873,7 +915,14 @@ def GenerateCMake(folder, params):
873915

874916
file.write('set(PICO_SDK_PATH ' + p + ')\n\n')
875917
file.write(cmake_header2)
876-
file.write('project(' + params.projectName + ' C CXX ASM)\n\n')
918+
file.write('project(' + params.projectName + ' C CXX ASM)\n')
919+
920+
if params.exceptions:
921+
file.write("\nset(PICO_CXX_ENABLE_EXCEPTIONS 1)\n")
922+
923+
if params.rtti:
924+
file.write("\nset(PICO_CXX_ENABLE_RTTI 1)\n")
925+
877926
file.write(cmake_header3)
878927

879928
# add the preprocessor defines for overall configuration
@@ -886,7 +935,11 @@ def GenerateCMake(folder, params):
886935
# No GUI/command line to set a different executable name at this stage
887936
executableName = params.projectName
888937

889-
file.write('add_executable(' + params.projectName + ' ' + params.projectName + '.c )\n\n')
938+
if params.wantCPP:
939+
file.write('add_executable(' + params.projectName + ' ' + params.projectName + '.cpp )\n\n')
940+
else:
941+
file.write('add_executable(' + params.projectName + ' ' + params.projectName + '.c )\n\n')
942+
890943
file.write('pico_set_program_name(' + params.projectName + ' "' + executableName + '")\n')
891944
file.write('pico_set_program_version(' + params.projectName + ' "0.1")\n\n')
892945

@@ -925,12 +978,15 @@ def GenerateCMake(folder, params):
925978

926979

927980
# Generates the requested project files, if any
928-
def generateProjectFiles(projectPath, projectName, sdkPath, projects):
981+
def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger):
929982

930983
oldCWD = os.getcwd()
931984

932985
os.chdir(projectPath)
933986

987+
deb = debugger_config_list[debugger]
988+
989+
# if debugger==0 else 'picoprobe.cfg
934990
for p in projects :
935991
if p == 'vscode':
936992
v1 = ('{\n'
@@ -942,17 +998,23 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects):
942998
' {\n'
943999
' "name": "Cortex Debug",\n'
9441000
' "cwd": "${workspaceRoot}",\n'
945-
' "executable": "${workspaceRoot}/build/' + projectName + '.elf",\n'
1001+
' "executable": "${command:cmake.launchTargetPath}",\n'
9461002
' "request": "launch",\n'
9471003
' "type": "cortex-debug",\n'
9481004
' "servertype": "openocd",\n'
949-
' "device": "Pico2040",\n'
1005+
' "gdbPath": "gdb-multiarch",\n'
1006+
' "device": "RP2040",\n'
9501007
' "configFiles": [\n' + \
951-
' "interface/raspberrypi-swd.cfg",\n' + \
1008+
' "interface/' + deb + '",\n' + \
9521009
' "target/rp2040.cfg"\n' + \
9531010
' ],\n' + \
954-
' "svdFile": "' + str(sdkPath) + '/src/rp2040/hardware_regs/rp2040.svd",\n'
1011+
' "svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd",\n'
9551012
' "runToMain": true,\n'
1013+
' // Give restart the same functionality as runToMain\n'
1014+
' "postRestartCommands": [\n'
1015+
' "break main",\n'
1016+
' "continue"\n'
1017+
' ]\n'
9561018
' }\n'
9571019
' ]\n'
9581020
'}\n')
@@ -1078,7 +1140,7 @@ def DoEverything(parent, params):
10781140
if params.wantExamples:
10791141
features_and_examples = list(stdlib_examples_list.keys()) + features_and_examples
10801142

1081-
GenerateMain('.', params.projectName, features_and_examples)
1143+
GenerateMain('.', params.projectName, features_and_examples, params.wantCPP)
10821144

10831145
GenerateCMake('.', params)
10841146

@@ -1105,7 +1167,7 @@ def DoEverything(parent, params):
11051167
os.system(cmakeCmd)
11061168

11071169
if params.projects:
1108-
generateProjectFiles(projectPath, params.projectName, params.sdkPath, params.projects)
1170+
generateProjectFiles(projectPath, params.projectName, params.sdkPath, params.projects, params.debugger)
11091171

11101172
if params.wantBuild:
11111173
if params.wantGUI:
@@ -1122,6 +1184,12 @@ def DoEverything(parent, params):
11221184

11231185
args = ParseCommandLine()
11241186

1187+
if args.nouart:
1188+
args.uart = False
1189+
1190+
# TODO this could be better, need some constants etc
1191+
if args.debugger > 1:
1192+
args.debugger = 0
11251193

11261194
# Check we have everything we need to compile etc
11271195
c = CheckPrerequisites()
@@ -1176,7 +1244,7 @@ def DoEverything(parent, params):
11761244
p = Parameters(sdkPath=sdkPath, projectRoot=projectRoot, projectName=args.name,
11771245
gui=False, overwrite=args.overwrite, build=args.build, features=args.feature,
11781246
projects=args.project, configs=(), runFromRAM=args.runFromRAM,
1179-
examples=args.examples, uart=args.uart, usb=args.usb)
1247+
examples=args.examples, uart=args.uart, usb=args.usb, cpp=args.cpp, debugger=args.debugger, exceptions=args.cppexceptions, rtti=args.cpprtti)
11801248

11811249
DoEverything(None, p)
11821250

0 commit comments

Comments
 (0)