60
60
'div' : ("Low level HW Divider" , "divider.c" , "hardware/divider.h" , "hardware_divider" )
61
61
}
62
62
63
+ debugger_list = ["SWD" , "PicoProbe" ]
64
+ debugger_config_list = ["raspberrypi-swd.cfg" , "picoprobe.cfg" ]
65
+
63
66
DEFINES = 0
64
67
INITIALISERS = 1
65
68
# Could add an extra item that shows how to use some of the available functions for the feature
202
205
isWindows = False
203
206
204
207
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 ):
206
210
self .sdkPath = sdkPath
207
211
self .projectRoot = projectRoot
208
212
self .projectName = projectName
@@ -216,6 +220,10 @@ def __init__(self, sdkPath, projectRoot, projectName, gui, overwrite, build, fea
216
220
self .wantExamples = examples
217
221
self .wantUART = uart
218
222
self .wantUSB = usb
223
+ self .wantCPP = cpp
224
+ self .debugger = debugger
225
+ self .exceptions = exceptions
226
+ self .rtti = rtti
219
227
220
228
def GetBackground ():
221
229
return 'white'
@@ -240,6 +248,8 @@ def RunGUI(sdkpath, args):
240
248
ttk .Style ().configure ("TRadiobutton" , foreground = GetTextColour (), background = GetBackground () )
241
249
ttk .Style ().configure ("TLabelframe" , foreground = GetTextColour (), background = GetBackground () )
242
250
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 () )
243
253
244
254
app = ProjectWindow (root , sdkpath , args )
245
255
@@ -642,7 +652,7 @@ def init_window(self, args):
642
652
643
653
# Code options section
644
654
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 )
646
656
647
657
self .wantExamples = tk .IntVar ()
648
658
self .wantExamples .set (args .examples )
@@ -652,9 +662,21 @@ def init_window(self, args):
652
662
self .wantRunFromRAM .set (args .runFromRAM )
653
663
ttk .Checkbutton (coptionsSubframe , text = "Run from RAM" , variable = self .wantRunFromRAM ).grid (row = 0 , column = 1 , padx = 4 , sticky = tk .W )
654
664
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
+
655
669
ttk .Button (coptionsSubframe , text = "Advanced..." , command = self .config ).grid (row = 0 , column = 4 , sticky = tk .E )
656
670
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
658
680
659
681
# Build Options section
660
682
@@ -663,14 +685,25 @@ def init_window(self, args):
663
685
664
686
self .wantBuild = tk .IntVar ()
665
687
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 )
667
689
668
690
self .wantOverwrite = tk .IntVar ()
669
691
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 )
671
698
672
699
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 )
674
707
675
708
optionsRow += 2
676
709
@@ -712,7 +745,8 @@ def OK(self):
712
745
p = Parameters (sdkPath = self .sdkpath , projectRoot = Path (projectPath ), projectName = self .projectName .get (),
713
746
gui = True , overwrite = self .wantOverwrite .get (), build = self .wantBuild .get (),
714
747
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 )
716
750
717
751
DoEverything (self , p )
718
752
@@ -774,14 +808,22 @@ def ParseCommandLine():
774
808
parser .add_argument ("-p" , "--project" , action = 'append' , help = "Generate projects files for IDE. Options are: vscode" )
775
809
parser .add_argument ("-r" , "--runFromRAM" , action = 'store_true' , help = "Run the program from RAM rather than flash" )
776
810
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" )
777
812
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 )
778
817
779
818
return parser .parse_args ()
780
819
781
820
782
- def GenerateMain (folder , projectName , features ):
821
+ def GenerateMain (folder , projectName , features , cpp ):
783
822
784
- filename = Path (folder ) / (projectName + '.c' )
823
+ if cpp :
824
+ filename = Path (folder ) / (projectName + '.cpp' )
825
+ else :
826
+ filename = Path (folder ) / (projectName + '.c' )
785
827
786
828
file = open (filename , 'w' )
787
829
@@ -853,7 +895,7 @@ def GenerateCMake(folder, params):
853
895
)
854
896
855
897
cmake_header3 = (
856
- "# Initialise the Pico SDK\n "
898
+ "\n # Initialise the Pico SDK\n "
857
899
"pico_sdk_init()\n \n "
858
900
"# Add executable. Default name is the project name, version 0.1\n \n "
859
901
)
@@ -873,7 +915,14 @@ def GenerateCMake(folder, params):
873
915
874
916
file .write ('set(PICO_SDK_PATH ' + p + ')\n \n ' )
875
917
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 ("\n set(PICO_CXX_ENABLE_EXCEPTIONS 1)\n " )
922
+
923
+ if params .rtti :
924
+ file .write ("\n set(PICO_CXX_ENABLE_RTTI 1)\n " )
925
+
877
926
file .write (cmake_header3 )
878
927
879
928
# add the preprocessor defines for overall configuration
@@ -886,7 +935,11 @@ def GenerateCMake(folder, params):
886
935
# No GUI/command line to set a different executable name at this stage
887
936
executableName = params .projectName
888
937
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
+
890
943
file .write ('pico_set_program_name(' + params .projectName + ' "' + executableName + '")\n ' )
891
944
file .write ('pico_set_program_version(' + params .projectName + ' "0.1")\n \n ' )
892
945
@@ -925,12 +978,15 @@ def GenerateCMake(folder, params):
925
978
926
979
927
980
# Generates the requested project files, if any
928
- def generateProjectFiles (projectPath , projectName , sdkPath , projects ):
981
+ def generateProjectFiles (projectPath , projectName , sdkPath , projects , debugger ):
929
982
930
983
oldCWD = os .getcwd ()
931
984
932
985
os .chdir (projectPath )
933
986
987
+ deb = debugger_config_list [debugger ]
988
+
989
+ # if debugger==0 else 'picoprobe.cfg
934
990
for p in projects :
935
991
if p == 'vscode' :
936
992
v1 = ('{\n '
@@ -942,17 +998,23 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects):
942
998
' {\n '
943
999
' "name": "Cortex Debug",\n '
944
1000
' "cwd": "${workspaceRoot}",\n '
945
- ' "executable": "${workspaceRoot}/build/' + projectName + '.elf ",\n '
1001
+ ' "executable": "${command:cmake.launchTargetPath} ",\n '
946
1002
' "request": "launch",\n '
947
1003
' "type": "cortex-debug",\n '
948
1004
' "servertype": "openocd",\n '
949
- ' "device": "Pico2040",\n '
1005
+ ' "gdbPath": "gdb-multiarch",\n '
1006
+ ' "device": "RP2040",\n '
950
1007
' "configFiles": [\n ' + \
951
- ' "interface/raspberrypi-swd.cfg ",\n ' + \
1008
+ ' "interface/' + deb + ' ",\n ' + \
952
1009
' "target/rp2040.cfg"\n ' + \
953
1010
' ],\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 '
955
1012
' "runToMain": true,\n '
1013
+ ' // Give restart the same functionality as runToMain\n '
1014
+ ' "postRestartCommands": [\n '
1015
+ ' "break main",\n '
1016
+ ' "continue"\n '
1017
+ ' ]\n '
956
1018
' }\n '
957
1019
' ]\n '
958
1020
'}\n ' )
@@ -1078,7 +1140,7 @@ def DoEverything(parent, params):
1078
1140
if params .wantExamples :
1079
1141
features_and_examples = list (stdlib_examples_list .keys ()) + features_and_examples
1080
1142
1081
- GenerateMain ('.' , params .projectName , features_and_examples )
1143
+ GenerateMain ('.' , params .projectName , features_and_examples , params . wantCPP )
1082
1144
1083
1145
GenerateCMake ('.' , params )
1084
1146
@@ -1105,7 +1167,7 @@ def DoEverything(parent, params):
1105
1167
os .system (cmakeCmd )
1106
1168
1107
1169
if params .projects :
1108
- generateProjectFiles (projectPath , params .projectName , params .sdkPath , params .projects )
1170
+ generateProjectFiles (projectPath , params .projectName , params .sdkPath , params .projects , params . debugger )
1109
1171
1110
1172
if params .wantBuild :
1111
1173
if params .wantGUI :
@@ -1122,6 +1184,12 @@ def DoEverything(parent, params):
1122
1184
1123
1185
args = ParseCommandLine ()
1124
1186
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
1125
1193
1126
1194
# Check we have everything we need to compile etc
1127
1195
c = CheckPrerequisites ()
@@ -1176,7 +1244,7 @@ def DoEverything(parent, params):
1176
1244
p = Parameters (sdkPath = sdkPath , projectRoot = projectRoot , projectName = args .name ,
1177
1245
gui = False , overwrite = args .overwrite , build = args .build , features = args .feature ,
1178
1246
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 )
1180
1248
1181
1249
DoEverything (None , p )
1182
1250
0 commit comments