1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
"""
Template scripts for generating workspace files:
- c_cpp_properties.json
- tasks.json
- makefile strings/functions
- buildData.json
"""
import os
launchName_Debug = "Cortex debug"
launchName_Python = "Debug current Python file"
taskName_build = "Build project"
taskName_compile = "Compile current file"
taskName_clean = "Delete build folder"
taskName_CPU_buildDownloadRun = "CPU: Build, Download and run"
taskName_CPU_downloadRun = "CPU: Download and run"
taskName_CPU_resetRun = "CPU: Reset and run"
taskName_CPU_halt = "CPU: Halt"
taskName_CPU_run = "CPU: Run"
taskName_Python = "Run Python file"
taskName_OpenCubeMX = "Open CubeMX project"
taskName_updateWorkspace = "Update workspace"
#########################################################################################################
c_cpp_template = """{
"env" : {
"____________________USER_FIELDS_CAN_BE_MODIFIED____________________": "",
"user_cSources": [],
"user_asmSources": [],
"user_ldSources": [],
"user_cIncludes": [],
"user_asmIncludes": [],
"user_ldIncludes": [],
"user_cDefines": [],
"user_asmDefines": [],
"user_cFlags": [],
"user_asmFlags": [],
"user_ldFlags": [],
"____________________DO_NOT_MODIFY_FIELDS_BELOW____________________": "",
"cubemx_sourceFiles": [],
"cubemx_includes": [],
"cubemx_defines": [],
"gccExePath": "",
"gccIncludePath": ""
},
"configurations": [
{
"name": "devTestBoard name of the project?",
"intelliSenseMode": "msvc-x64",
"includePath": [
"${workspaceFolder}",
"${cubemx_includes}",
"${gccIncludePath}",
"${user_cIncludes}",
"${user_asmIncludes}",
"${user_ldIncludes}"
],
"browse": {
"path": [
"${workspaceFolder}",
"${cubemx_includes}",
"${gccIncludePath}",
"${user_cIncludes}",
"${user_asmIncludes}",
"${user_ldIncludes}"
],
"limitSymbolsToIncludedHeaders": true
},
"defines": [
"${cubemx_defines}",
"${user_cDefines}",
"${user_asmDefines}"
],
"forcedInclude": [
],
"compilerPath": "${gccExePath}",
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}
"""
#########################################################################################################
versionString = "Version ***"
lastRunString = "Last run: ***"
#########################################################################################################
makefileHeader = ('#' * 100) + "\n"
makefileHeader += "# Makefile generated by updateMakefile.py\n"
makefileHeader += "# " + versionString + " \n"
makefileHeader += "# " + lastRunString + " \n"
makefileHeader += ('#' * 100) + "\n"
#########################################################################################################
printMakefileVariableFunction = "print-%:"
printMakefileDefaultString = "VARIABLE="
printMakefileVariable = "#######################################\n"
printMakefileVariable += "# Print makefile variables\n"
printMakefileVariable += "#######################################\n"
printMakefileVariable += printMakefileVariableFunction + "\n"
printMakefileVariable += "\t@echo " + printMakefileDefaultString + "$($*)\n"
#########################################################################################################
cleanFunctionNameSearchString = "clean:"
cleanBuildDirFunctionName = "clean-build-dir"
cleanBuildDirFunction = "#######################################\n"
cleanBuildDirFunction += "# Clean build directory content \n"
cleanBuildDirFunction += "#######################################\n"
cleanBuildDirFunction += cleanBuildDirFunctionName + ":\n"
cleanBuildDirFunction += "\t@echo Build folder: '$(BUILD_DIR)' clean request (files with spaces and folders will not be removed):\n"
cleanBuildDirFunction += "\t@$(foreach file, $(wildcard $(BUILD_DIR)/*), rm -f $(file))\n"
cleanBuildDirFunction += "\t@echo OK.\n"
#########################################################################################################
taskTemplate = """{
"label": "Update workspace",
"type": "shell",
"command": "python",
"args": [
"${workspaceFolder}\\\\test.py"
],
"group": "none",
"presentation": {
"reveal": "always",
"panel": "shared"
},
"problemMatcher": {
}
}
"""
tasksFileTemplate = """{
"version": "2.0.0",
"tasks": ["""
tasksFileTemplate += """
]
}
"""
#########################################################################################################
# buildData.json has template with all keys listed, since it is needed for sorting purposes. There
# might be a better way to handle sorting (TODO)
buildDataTemplate = """{
"ABOUT1": "This file holds combined user and CubeMX generated Makefile workspace dependecies.",
"ABOUT2": "User should not edit this fields, instead it should edit 'c_cpp_properties.json'",
"ABOUT3": "This file is regenerated on 'Update workspace' task.",
"VERSION": "",
"LAST_RUN": "",
"cSources": [],
"asmSources": [],
"ldSources": [],
"cIncludes": [],
"asmIncludes": [],
"ldIncludes": [],
"cDefines": [],
"asmDefines": [],
"cFlags" : [],
"asmFlags" : [],
"ldFlags" : [],
"buildDir": "",
"targetExecutablePath": "",
"cubeMxProjectPath": "",
"openOcdConfig": [],
"stm32SvdPath": "",
"ABOUT4": "---- Paths below are fetched from user-specific 'toolsPaths.json'. ----",
"gccExePath": "",
"gccInludePath": "",
"buildToolsPath": "",
"pythonExec": "",
"openOcdPath": "",
"openOcdInterfacePath": ""
}
"""
#########################################################################################################
toolsPathsTemplate = """{
"ABOUT1": "This file store common tools paths, shared by all VS Code ideScripts-based projects.",
"ABOUT2": "Delete/correct this file if paths/folder structure change on system.",
"VERSION": "",
"LAST_RUN": ""
}
"""
#########################################################################################################
launchFileTemplate = """{
"version": "0.2.0",
"configurations": [
]
}
"""
#########################################################################################################
cubeMxTmpFolderName = '_tmpCubeMx'
cubeMxTmpFileName = 'tmpCubeMx.txt'
#########################################################################################################
defaultVsCodeSettingsFolder_WIN = os.path.expandvars("%APPDATA%/Code/User/")
defaultVsCodeSettingsFolder_UNIX = os.path.expandvars("$HOME/.config/Code/User/")
defaultVsCodeSettingsFolder_OSX = os.path.expandvars("$HOME/Library/Application Support/Code/User/")
|