@@ -43,7 +43,8 @@ import {
4343 txt_install_now , txt_yes , view_str$prompt$feedback , rating_text , later_text , sponsor_author_text ,
4444 view_str$prompt$install_dotnet_and_restart_vscode ,
4545 view_str$prompt$install_dotnet_failed ,
46- view_str$prompt$not_found_compiler
46+ view_str$prompt$not_found_compiler , view_str$prompt$debugCfgNotSupported , not_support_no_arm_project ,
47+ view_str$prompt$requireOtherExtension
4748} from './StringTable' ;
4849import { LogDumper } from './LogDumper' ;
4950import { StatusBarManager } from './StatusBarManager' ;
@@ -294,11 +295,17 @@ export async function activate(context: vscode.ExtensionContext) {
294295 subscriptions . push ( vscode . commands . registerCommand ( '_cl.eide.statusbar.build' , ( ) => projectExplorer . BuildSolution ( undefined , { not_rebuild : true } ) ) ) ;
295296 subscriptions . push ( vscode . commands . registerCommand ( '_cl.eide.statusbar.flash' , ( ) => projectExplorer . UploadToDevice ( undefined ) ) ) ;
296297
298+ // debug config providers
299+ vscode . debug . registerDebugConfigurationProvider ( 'cortex-debug' , new ExternalDebugConfigProvider ( 'cortex-debug' ) ,
300+ vscode . DebugConfigurationProviderTriggerKind . Dynamic ) ;
301+ vscode . debug . registerDebugConfigurationProvider ( 'probe-rs-debug' , new ExternalDebugConfigProvider ( 'probe-rs-debug' ) ,
302+ vscode . DebugConfigurationProviderTriggerKind . Dynamic ) ;
303+ // vscode.debug.registerDebugConfigurationProvider('stm8-debug', new ExternalDebugConfigProvider('stm8-debug'),
304+ // vscode.DebugConfigurationProviderTriggerKind.Dynamic);
305+
297306 // others
298307 vscode . workspace . registerTextDocumentContentProvider ( VirtualDocument . scheme , VirtualDocument . instance ( ) ) ;
299308 vscode . workspace . registerTaskProvider ( EideTaskProvider . TASK_TYPE_BASH , new EideTaskProvider ( ) ) ;
300- vscode . debug . registerDebugConfigurationProvider ( 'eide.cortex-debug' , new CortexDebugConfigProvider ( ) ,
301- vscode . DebugConfigurationProviderTriggerKind . Dynamic ) ;
302309
303310 // auto save project
304311 projectExplorer . enableAutoSave ( true ) ;
@@ -1589,7 +1596,10 @@ class EideTerminalProvider implements vscode.TerminalProfileProvider {
15891596
15901597import { FileWatcher } from '../lib/node-utility/FileWatcher' ;
15911598import { ToolchainManager , ToolchainName } from './ToolchainManager' ;
1592- import { JLinkOptions , JLinkProtocolType , OpenOCDFlashOptions , PyOCDFlashOptions , STLinkOptions } from './HexUploader' ;
1599+ import {
1600+ JLinkOptions , JLinkProtocolType , OpenOCDFlashOptions ,
1601+ PyOCDFlashOptions , STLinkOptions , ProbeRSFlashOptions , STVPFlasherOptions
1602+ } from './HexUploader' ;
15931603import { AbstractProject } from './EIDEProject' ;
15941604
15951605type MapViewParserType = 'memap' | 'builtin' ;
@@ -1890,7 +1900,13 @@ class MapViewEditorProvider implements vscode.CustomTextEditorProvider {
18901900//- Debug Config Provider
18911901//------------------------------------------------------------
18921902
1893- class CortexDebugConfigProvider implements vscode . DebugConfigurationProvider {
1903+ class ExternalDebugConfigProvider implements vscode . DebugConfigurationProvider {
1904+
1905+ private debuggerType : string | undefined ;
1906+
1907+ constructor ( debugType ?: string ) {
1908+ this . debuggerType = debugType ;
1909+ }
18941910
18951911 provideDebugConfigurations ( folder : vscode . WorkspaceFolder | undefined ,
18961912 token ?: vscode . CancellationToken ) : vscode . ProviderResult < vscode . DebugConfiguration [ ] > {
@@ -1941,11 +1957,47 @@ class CortexDebugConfigProvider implements vscode.DebugConfigurationProvider {
19411957 return result ;
19421958 }
19431959 break ;
1960+ // case 'IAR_STM8':
1961+ // case 'COSMIC_STM8':
1962+ // case 'SDCC':
1963+ // break;
19441964 default :
19451965 return result ;
19461966 }
19471967
1948- const newDebugCfg = ( prj : AbstractProject ) => {
1968+ const toFmtRelativePath = ( abspath : string ) => {
1969+ let path = prj . ToRelativePath ( abspath ) ;
1970+ if ( path ) {
1971+ path = File . ToLocalPath ( path ) ;
1972+ return path . startsWith ( '.' ) ? path : `.${ File . sep } ${ path } ` ;
1973+ }
1974+ return File . ToLocalPath ( abspath ) ;
1975+ } ;
1976+
1977+ const getSvdFile = ( prj : AbstractProject ) => {
1978+ const device = prj . GetPackManager ( ) . getCurrentDevInfo ( ) ;
1979+ if ( device && device . svdPath ) {
1980+ const svdpath = toFmtRelativePath ( device . svdPath ) ;
1981+ GlobalEvent . log_info ( `[debug config] Use svd file: ${ svdpath } ` ) ;
1982+ return svdpath ;
1983+ } else {
1984+ const searchDirs = [
1985+ prj . getRootDir ( ) ,
1986+ prj . getEideDir ( ) ,
1987+ File . from ( prj . getRootDir ( ) . path , 'tools' )
1988+ ] ;
1989+ for ( const d of searchDirs ) {
1990+ const r = d . GetList ( [ / \. s v d $ / i] , File . EXCLUDE_ALL_FILTER ) ;
1991+ if ( r . length ) {
1992+ const svdpath = toFmtRelativePath ( r [ 0 ] . path ) ;
1993+ GlobalEvent . log_info ( `[debug config] Use svd file: ${ svdpath } ` ) ;
1994+ return svdpath ;
1995+ }
1996+ }
1997+ }
1998+ } ;
1999+
2000+ const newCortexDebugCfg = ( prj : AbstractProject ) => {
19492001
19502002 const dbgCfg : vscode . DebugConfiguration = {
19512003 type : 'cortex-debug' ,
@@ -1970,32 +2022,14 @@ class CortexDebugConfigProvider implements vscode.DebugConfigurationProvider {
19702022 }
19712023
19722024 dbgCfg [ 'cwd' ] = prj . getRootDir ( ) . path ;
1973- dbgCfg [ 'executable' ] = prj . getExecutablePathWithoutSuffix ( ) + '.elf' ;
2025+ dbgCfg [ 'executable' ] = toFmtRelativePath ( prj . getExecutablePathWithoutSuffix ( ) + '.elf' ) ;
19742026 dbgCfg [ 'runToEntryPoint' ] = 'main' ;
19752027 dbgCfg [ 'liveWatch' ] = {
19762028 'enabled' : true ,
19772029 'samplesPerSecond' : 4
19782030 } ;
19792031
1980- const device = prj . GetPackManager ( ) . getCurrentDevInfo ( ) ;
1981- if ( device && device . svdPath ) {
1982- dbgCfg [ 'svdFile' ] = prj . ToRelativePath ( device . svdPath ) || device . svdPath ;
1983- GlobalEvent . log_info ( `[debug config] Use svd file: ${ dbgCfg [ 'svdFile' ] } ` ) ;
1984- } else {
1985- const searchDirs = [
1986- prj . getRootDir ( ) ,
1987- prj . getEideDir ( ) ,
1988- File . from ( prj . getRootDir ( ) . path , 'tools' )
1989- ] ;
1990- for ( const d of searchDirs ) {
1991- const r = d . GetList ( [ / \. s v d $ / i] , File . EXCLUDE_ALL_FILTER ) ;
1992- if ( r . length ) {
1993- dbgCfg [ 'svdFile' ] = prj . ToRelativePath ( r [ 0 ] . path ) || r [ 0 ] . path ;
1994- GlobalEvent . log_info ( `[debug config] Use svd file: ${ dbgCfg [ 'svdFile' ] } ` ) ;
1995- break ;
1996- }
1997- }
1998- }
2032+ dbgCfg [ 'svdFile' ] = getSvdFile ( prj ) ;
19992033
20002034 return dbgCfg ;
20012035 } ;
@@ -2013,7 +2047,7 @@ class CortexDebugConfigProvider implements vscode.DebugConfigurationProvider {
20132047 const flashertype = prj . getUploaderType ( ) ;
20142048
20152049 if ( flashertype == 'JLink' ) {
2016- const dbgCfg = newDebugCfg ( prj ) ;
2050+ const dbgCfg = newCortexDebugCfg ( prj ) ;
20172051 const flasherCfg = ( < JLinkOptions > flasherOpts ) ;
20182052 dbgCfg [ 'name' ] = 'Debug: JLINK' ;
20192053 dbgCfg [ 'servertype' ] = 'jlink' ;
@@ -2035,7 +2069,7 @@ class CortexDebugConfigProvider implements vscode.DebugConfigurationProvider {
20352069 }
20362070
20372071 else if ( flashertype == 'OpenOCD' ) {
2038- const dbgCfg = newDebugCfg ( prj ) ;
2072+ const dbgCfg = newCortexDebugCfg ( prj ) ;
20392073 const flasherCfg = ( < OpenOCDFlashOptions > flasherOpts ) ;
20402074 dbgCfg [ 'name' ] = 'Debug: OpenOCD' ;
20412075 dbgCfg [ 'servertype' ] = 'openocd' ;
@@ -2050,7 +2084,7 @@ class CortexDebugConfigProvider implements vscode.DebugConfigurationProvider {
20502084 }
20512085
20522086 else if ( flashertype == 'pyOCD' ) {
2053- const dbgCfg = newDebugCfg ( prj ) ;
2087+ const dbgCfg = newCortexDebugCfg ( prj ) ;
20542088 const flasherCfg = ( < PyOCDFlashOptions > flasherOpts ) ;
20552089 dbgCfg [ 'name' ] = 'Debug: pyOCD' ;
20562090 dbgCfg [ 'servertype' ] = 'pyocd' ;
@@ -2104,7 +2138,7 @@ class CortexDebugConfigProvider implements vscode.DebugConfigurationProvider {
21042138 if ( p )
21052139 cubeProgramerPath = NodePath . dirname ( p ) ;
21062140 }
2107- const dbgCfg = newDebugCfg ( prj ) ;
2141+ const dbgCfg = newCortexDebugCfg ( prj ) ;
21082142 dbgCfg [ 'name' ] = 'Debug: STLink' ;
21092143 dbgCfg [ 'servertype' ] = 'stlink' ;
21102144 dbgCfg [ 'interface' ] = flasherCfg . proType == 'SWD' ? 'swd' : 'jtag' ;
@@ -2113,13 +2147,79 @@ class CortexDebugConfigProvider implements vscode.DebugConfigurationProvider {
21132147 result . push ( dbgCfg ) ;
21142148 }
21152149
2150+ else if ( flashertype == 'probe-rs' ) {
2151+ const flasherCfg = ( < ProbeRSFlashOptions > flasherOpts ) ;
2152+ const dbgCfg : any = {
2153+ "type" : "probe-rs-debug" ,
2154+ "request" : "launch" ,
2155+ "name" : "Debug: probe-rs" ,
2156+ "cwd" : prj . getRootDir ( ) . path ,
2157+ "connectUnderReset" : false ,
2158+ "chip" : flasherCfg . target ,
2159+ "wireProtocol" : flasherCfg . protocol . toLowerCase ( ) == 'swd' ? 'Swd' : 'Jtag' ,
2160+ "allowEraseAll" : flasherCfg . allowEraseAll ,
2161+ "flashingConfig" : {
2162+ "flashingEnabled" : true ,
2163+ "haltAfterReset" : true
2164+ } ,
2165+ "coreConfigs" : [
2166+ {
2167+ "coreIndex" : 0 ,
2168+ "svdFile" : getSvdFile ( prj ) ,
2169+ "programBinary" : toFmtRelativePath (
2170+ prj . getExecutablePathWithoutSuffix ( ) + '.elf' )
2171+ }
2172+ ]
2173+ } ;
2174+ if ( flasherCfg . speed )
2175+ dbgCfg [ 'speed' ] = flasherCfg . speed ;
2176+ // parse '--probe VID:PID' or '--probe VID:PID:Serial'
2177+ if ( flasherCfg . otherOptions ) {
2178+ let m = / - - p r o b e ( \w + \: \w + (?: \: \w + ) ? ) / . exec ( flasherCfg . otherOptions ) ;
2179+ if ( m && m . length > 1 ) {
2180+ dbgCfg [ 'probe' ] = m [ 1 ] ;
2181+ }
2182+ }
2183+ result . push ( dbgCfg ) ;
2184+ }
2185+
2186+ // else if (flashertype == 'STVP') {
2187+ // const flasherCfg = (<STVPFlasherOptions>flasherOpts);
2188+ // const dbgCfg: any = {
2189+ // "type": "stm8-debug",
2190+ // "request": "launch",
2191+ // "name": "Debug: STM8",
2192+ // "serverType": "st7",
2193+ // "executable": toFmtRelativePath(prj.getExecutablePath()),
2194+ // "cpu": flasherCfg.deviceName
2195+ // };
2196+ // const searchDirs = [
2197+ // prj.getRootDir(),
2198+ // prj.getEideDir(),
2199+ // File.from(prj.getRootDir().path, 'tools')
2200+ // ];
2201+ // for (const d of searchDirs) {
2202+ // const r = d.GetList([/\.svd\.json$/i], File.EXCLUDE_ALL_FILTER);
2203+ // if (r.length) {
2204+ // const svdpath = toFmtRelativePath(r[0].path);
2205+ // GlobalEvent.log_info(`[debug config] Use svd file: ${svdpath}`);
2206+ // dbgCfg['svdFile'] = svdpath;
2207+ // }
2208+ // }
2209+ // }
2210+
21162211 else {
2117- GlobalEvent . emit ( 'msg' , newMessage ( 'Warning' ,
2118- `Only support 'jlink', 'stlink', 'openocd', 'pyocd'. Not support this flasher: '${ flashertype } ' !` ) ) ;
2212+ const supported = [ 'jlink' , 'stlink' , 'openocd' , 'pyocd' , 'probe-rs' ] ;
2213+ const msg = view_str$prompt$debugCfgNotSupported
2214+ . replace ( '{0}' , supported . join ( ',' ) )
2215+ . replace ( '{1}' , flashertype ) ;
2216+ GlobalEvent . show_msgbox ( 'Warning' , msg ) ;
21192217 }
21202218
2121- // GlobalEvent.log_info(`provide Cortex-Debug DebugConfig`);
2122- // GlobalEvent.log_info(yaml.stringify(result));
2219+ // filter by debugType
2220+ if ( this . debuggerType )
2221+ return result . filter ( cfg => cfg . type == this . debuggerType ) ;
2222+
21232223 return result ;
21242224 }
21252225}
@@ -2138,7 +2238,7 @@ async function startDebugging() {
21382238 index : 0
21392239 } ;
21402240
2141- const cfgs = await ( new CortexDebugConfigProvider ( ) )
2241+ const cfgs = await ( new ExternalDebugConfigProvider ( ) )
21422242 . provideDebugConfigurations ( vscWorkspaceFolder ) ;
21432243 if ( cfgs && cfgs . length > 0 ) {
21442244 let cfg = cfgs [ 0 ] ;
0 commit comments