Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustup support #96

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ tmp.py
!scripts/lwipopts.h
!scripts/pico_configs.tsv
!scripts/pico_project.py
!scripts/portable-msvc.py
!scripts/pico-vscode.cmake
!scripts/Pico.code-profile
!scripts/raspberrypi-swd.cfg
!data/**
!scripts/rttDecoder.mjs
!scripts/rttDecoder.js
scripts/*.ps1
scripts/fix_windows_reg.py
scripts/vscodeUninstaller.mjs
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ For optimal functionality, consider enabling:

When prompted, select the `Pico` kit in CMake Tools, and set your build and launch targets accordingly. Use CMake Tools for compilation, but continue using this extension for debugging, as CMake Tools debugging is not compatible with Pico.

## Rust Prerequisites

### Linux

- **GCC** for the host architecture

## VS Code Profiles

If you work with multiple microcontroller toolchains, consider installing this extension into a [VS Code Profile](https://code.visualstudio.com/docs/editor/profiles) to avoid conflicts with other toolchains. Follow these steps:
Expand Down
34 changes: 30 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
},
"activationEvents": [
"workspaceContains:./pico_sdk_import.cmake",
"workspaceContains:./.pico-rs",
"onWebviewPanel:newPicoProject",
"onWebviewPanel:newPicoMicroPythonProject"
],
Expand All @@ -79,20 +80,26 @@
"command": "raspberry-pi-pico.switchSDK",
"title": "Switch Pico SDK",
"category": "Raspberry Pi Pico",
"enablement": "raspberry-pi-pico.isPicoProject"
"enablement": "raspberry-pi-pico.isPicoProject && !raspberry-pi-pico.isRustProject"
},
{
"command": "raspberry-pi-pico.switchBoard",
"title": "Switch Board",
"category": "Raspberry Pi Pico",
"enablement": "raspberry-pi-pico.isPicoProject"
"enablement": "raspberry-pi-pico.isPicoProject && !raspberry-pi-pico.isRustProject"
},
{
"command": "raspberry-pi-pico.launchTargetPath",
"title": "Get path of the project executable",
"category": "Raspberry Pi Pico",
"enablement": "false"
},
{
"command": "raspberry-pi-pico.launchTargetPathRelease",
"title": "Get path of the project release executable (rust only)",
"category": "Raspberry Pi Pico",
"enablement": "false"
},
{
"command": "raspberry-pi-pico.getPythonPath",
"title": "Get python path",
Expand Down Expand Up @@ -141,6 +148,18 @@
"category": "Raspberry Pi Pico",
"enablement": "false"
},
{
"command": "raspberry-pi-pico.getOpenOCDRoot",
"title": "Get OpenOCD root",
"category": "Raspberry Pi Pico",
"enablement": "false"
},
{
"command": "raspberry-pi-pico.getSVDPath",
"title": "Get SVD Path (rust only)",
"category": "Raspberry Pi Pico",
"enablement": "false"
},
{
"command": "raspberry-pi-pico.compileProject",
"title": "Compile Pico Project",
Expand Down Expand Up @@ -179,7 +198,7 @@
"command": "raspberry-pi-pico.configureCmake",
"title": "Configure CMake",
"category": "Raspberry Pi Pico",
"enablement": "raspberry-pi-pico.isPicoProject"
"enablement": "raspberry-pi-pico.isPicoProject && !raspberry-pi-pico.isRustProject"
},
{
"command": "raspberry-pi-pico.importProject",
Expand All @@ -200,7 +219,13 @@
"command": "raspberry-pi-pico.flashProject",
"title": "Flash Pico Project (SWD)",
"category": "Raspberry Pi Pico",
"enablement": "raspberry-pi-pico.isPicoProject"
"enablement": "raspberry-pi-pico.isPicoProject && !raspberry-pi-pico.isRustProject"
},
{
"command": "raspberry-pi-pico.getRTTDecoderPath",
"title": "Get RTT Decoder module path",
"category": "Raspberry Pi Pico",
"enablement": "false"
}
],
"configuration": {
Expand Down Expand Up @@ -307,6 +332,7 @@
"got": "^14.4.2",
"ini": "^4.1.3",
"rimraf": "^5.0.7",
"toml": "^3.0.0",
"undici": "^6.19.7",
"uuid": "^10.0.0",
"which": "^4.0.0"
Expand Down
98 changes: 98 additions & 0 deletions scripts/rttDecoder.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
const { spawn } = require('child_process');

class DefmtDecoder {
constructor() {
this.process = null;
this.elfPath = null;
this.displayOutput = null;
this.graphData = null;
this.ports = [];
}

init(config, displayOutput, graphData) {
// Store the callbacks and elfPath from the config
this.elfPath = config.elfPath;
this.displayOutput = displayOutput;
this.graphData = graphData;
this.ports = config.ports;

const defmtPrintPath = `${process.platform === "win32" ? process.env.USERPROFILE : process.env.HOME}/.cargo/bin/defmt-print${process.platform === "win32" ? ".exe" : ""}`;

// Spawn the defmt-print process with the provided ELF path
this.process = spawn(defmtPrintPath, ['-e', this.elfPath, "stdin"]);

// Handle data from defmt-print stdout and relay it to the displayOutput callback
this.process.stdout.on('data', (data) => {
if (this.displayOutput) {
this.displayOutput(data.toString());
}
});

// Handle errors from defmt-print stderr
this.process.stderr.on('data', (data) => {
if (this.displayOutput) {
this.displayOutput(data.toString());
}
});

// Handle when the process closes
this.process.on('close', (code) => {
if (this.displayOutput) {
this.displayOutput(`Decoding process exited with code: ${code}`);
}
});
}

sendData(input) {
// Write input data to defmt-print's stdin
try {
if (this.process && this.process.stdin.writable) {
this.process.stdin.write(input);
return;
}
} catch { }

throw new Error('Process stdin is not writable.');
}

// Expected methods from the SWODecoder API conforming to the AdvancedDecoder interface

typeName() {
return 'DefmtDecoder';
}

outputLabel() {
return 'RPi Pico';
}

softwareEvent(port, data) {
if (this.ports.indexOf(port) !== -1) {
// Handle the software event, potentially by sending data to defmt-print stdin
this.sendData(data);
}
}

synchronized() {
// Handle the synchronized event
if (this.displayOutput) {
this.displayOutput('Synchronized');
}
}

lostSynchronization() {
// Handle the lost synchronization event
if (this.displayOutput) {
this.displayOutput('Lost synchronization');
}
}

dispose() {
// Clean up the process
if (this.process) {
this.process.kill();
this.process = null;
}
}
}

module.exports = exports = DefmtDecoder;
121 changes: 121 additions & 0 deletions scripts/rttDecoder.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { spawn } from 'child_process';
import EventEmitter from 'events';

/*
interface AdvancedDecoder {
init(
config: SWOAdvancedDecoderConfig,
outputData: (output: string) => void,
graphData: (data: number, id: string) => void
): void;
typeName(): string;
outputLabel(): string;
softwareEvent(port: number, data: Buffer): void;
synchronized(): void;
lostSynchronization(): void;
}*/

class DefmtDecoder extends EventEmitter {
constructor() {
this.process = null;
this.elfPath = null;
this.displayOutput = null;
this.graphData = null;
}

init(config, displayOutput, graphData) {
// Store the callbacks and elfPath from the config
this.elfPath = config.config.elfPath;
this.displayOutput = displayOutput;
this.graphData = graphData;

const defmtPrintPath = `${process.platform === "win32" ? process.env.USERPROFILE : process.env.HOME}/.cargo/bin/defmt-print${process.platform === "win32" ? ".exe" : ""}`;

// Spawn the defmt-print process with the provided ELF path
this.process = spawn(defmtPrintPath, ['-e', this.elfPath, "stdin"]);

// Handle data from defmt-print stdout and relay it to the displayOutput callback
this.process.stdout.on('data', (data) => {
if (this.displayOutput) {
this.displayOutput(data.toString());
}
});

// Handle errors from defmt-print stderr
this.process.stderr.on('data', (data) => {
if (this.displayOutput) {
//this.displayOutput(`Error: ${data.toString()}`);
this.displayOutput(data.toString());
}
});

// Handle when the process closes
this.process.on('close', (code) => {
if (this.displayOutput) {
this.displayOutput(`Decoding process exited with code: ${code}`);
}
});
}

//sendData(input: Buffer): void;
sendData(input) {
// Write input data to defmt-print's stdin
try {
if (this.process && this.process.stdin.writable) {
this.process.stdin.write(input);
return;
}
} catch { }

throw new Error('Process stdin is not writable.');
}

// Expected methods from the SWODecoder API conforming to the AdvancedDecoder interface

//typeName(): string;
typeName() {
return 'DefmtDecoder';
}

//outputLabel(): string;
outputLabel() {
return 'RPi Pico';
}

//softwareEvent(port: number, data: Buffer): void;
softwareEvent(port, data) {
if (this.ports.indexOf(port) !== -1) {
// Handle the software event, potentially by sending data to defmt-print stdin
this.sendData(data);
}
}

//synchronized(): void;
synchronized() {
// Handle the synchronized event
if (this.displayOutput) {
this.displayOutput('Synchronized');
}
}

//lostSynchronization(): void;
lostSynchronization() {
// Handle the lost synchronization event
if (this.displayOutput) {
this.displayOutput('Lost synchronization');
}
}

// own dispose method

dispose() {
// Clean up the process
if (this.process) {
this.process.kill();
this.process = null;
}
this.emit('dispose');
}
}

export default DefmtDecoder;
7 changes: 7 additions & 0 deletions src/commands/compileProject.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { EventEmitter } from "events";
import { CommandWithResult } from "./command.mjs";
import Logger from "../logger.mjs";
import Settings, { SettingsKey } from "../settings.mjs";
import State from "../state.mjs";

export default class CompileProjectCommand extends CommandWithResult<boolean> {
private _logger: Logger = new Logger("CompileProjectCommand");
Expand All @@ -18,9 +19,15 @@ export default class CompileProjectCommand extends CommandWithResult<boolean> {
const task = (await tasks.fetchTasks()).find(
task => task.name === "Compile Project"
);
/*const isRustProject = await commands.executeCommand(
"getContext",
ContextKeys.isRustProject
);*/
const isRustProject = State.getInstance().isRustProject;

const settings = Settings.getInstance();
if (
!isRustProject &&
settings !== undefined &&
settings.getBoolean(SettingsKey.useCmakeTools)
) {
Expand Down
23 changes: 21 additions & 2 deletions src/commands/conditionalDebugging.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Command } from "./command.mjs";
import { Command, extensionName } from "./command.mjs";
import Logger from "../logger.mjs";
import { commands } from "vscode";
import { commands, window, workspace, debug } from "vscode";
import State from "../state.mjs";
import DebugLayoutCommand from "./debugLayout.mjs";

/**
* Relay command for the default buildin debug select and start command.
Expand All @@ -16,6 +18,23 @@ export default class ConditionalDebuggingCommand extends Command {
}

async execute(): Promise<void> {
const isRustProject = State.getInstance().isRustProject;

if (isRustProject) {
const wsFolder = workspace.workspaceFolders?.[0];
if (!wsFolder) {
this._logger.error("No workspace folder found.");
void window.showErrorMessage("No workspace folder found.");

return;
}

void commands.executeCommand(`${extensionName}.${DebugLayoutCommand.id}`);
void debug.startDebugging(wsFolder, "rp2040-project");

return;
}

await commands.executeCommand("workbench.action.debug.selectandstart");
}
}
Loading
Loading