Skip to main content

embedded_debugger_mcp/tools/
types.rs

1//! Type definitions for embedded debugger MCP tools
2
3use serde::{Deserialize, Serialize};
4use schemars::JsonSchema;
5
6// =============================================================================
7// Debugger Management Types
8// =============================================================================
9
10#[derive(Debug, Deserialize, JsonSchema)]
11pub struct ListProbesArgs {
12    // No parameters needed
13}
14
15#[derive(Debug, Deserialize, JsonSchema)]
16pub struct ConnectArgs {
17    /// Probe selector (serial number, identifier, or "auto" for first available)
18    pub probe_selector: String,
19    /// Target chip name (e.g., "STM32F407VGTx", "nRF52840_xxAA")
20    pub target_chip: String,
21    /// Connection speed in kHz (default: 4000)
22    #[serde(default = "default_speed_khz")]
23    pub speed_khz: u32,
24    /// Whether to connect under reset
25    #[serde(default)]
26    pub connect_under_reset: bool,
27    /// Whether to halt after connecting
28    #[serde(default = "default_true")]
29    pub halt_after_connect: bool,
30}
31
32fn default_speed_khz() -> u32 { 4000 }
33fn default_true() -> bool { true }
34
35#[derive(Debug, Deserialize, JsonSchema)]
36pub struct DisconnectArgs {
37    /// Session ID to disconnect
38    pub session_id: String,
39}
40
41#[derive(Debug, Deserialize, JsonSchema)]
42pub struct ProbeInfoArgs {
43    /// Session ID to get info for
44    pub session_id: String,
45}
46
47// =============================================================================
48// Target Control Types
49// =============================================================================
50
51#[derive(Debug, Deserialize, JsonSchema)]
52pub struct HaltArgs {
53    /// Session ID
54    pub session_id: String,
55}
56
57#[derive(Debug, Deserialize, JsonSchema)]
58pub struct RunArgs {
59    /// Session ID
60    pub session_id: String,
61}
62
63#[derive(Debug, Deserialize, JsonSchema)]
64pub struct ResetArgs {
65    /// Session ID
66    pub session_id: String,
67    /// Reset type: "hardware" or "software"
68    #[serde(default = "default_reset_type")]
69    pub reset_type: String,
70    /// Whether to halt after reset
71    #[serde(default = "default_true")]
72    pub halt_after_reset: bool,
73}
74
75fn default_reset_type() -> String { "hardware".to_string() }
76
77#[derive(Debug, Deserialize, JsonSchema)]
78pub struct StepArgs {
79    /// Session ID
80    pub session_id: String,
81}
82
83#[derive(Debug, Deserialize, JsonSchema)]
84pub struct GetStatusArgs {
85    /// Session ID
86    pub session_id: String,
87}
88
89// =============================================================================
90// Memory Operation Types
91// =============================================================================
92
93#[derive(Debug, Deserialize, JsonSchema)]
94pub struct ReadMemoryArgs {
95    /// Session ID
96    pub session_id: String,
97    /// Memory address (hex string like "0x8000000" or decimal)
98    pub address: String,
99    /// Number of bytes to read
100    pub size: usize,
101    /// Output format: "hex", "binary", "ascii", "words32", "words16"
102    #[serde(default = "default_format")]
103    pub format: String,
104}
105
106fn default_format() -> String { "hex".to_string() }
107
108#[derive(Debug, Deserialize, JsonSchema)]
109pub struct WriteMemoryArgs {
110    /// Session ID
111    pub session_id: String,
112    /// Memory address (hex string like "0x8000000" or decimal)
113    pub address: String,
114    /// Data to write
115    pub data: String,
116    /// Input format: "hex", "binary", "ascii", "words32", "words16"
117    #[serde(default = "default_format")]
118    pub format: String,
119}
120
121
122// =============================================================================
123// Breakpoint Management Types
124// =============================================================================
125
126#[derive(Debug, Deserialize, JsonSchema)]
127pub struct SetBreakpointArgs {
128    /// Session ID
129    pub session_id: String,
130    /// Breakpoint address (hex string like "0x8000000" or decimal)
131    pub address: String,
132    /// Breakpoint type: "hardware" or "software"
133    #[serde(default = "default_breakpoint_type")]
134    pub breakpoint_type: String,
135}
136
137fn default_breakpoint_type() -> String { "hardware".to_string() }
138
139#[derive(Debug, Deserialize, JsonSchema)]
140pub struct ClearBreakpointArgs {
141    /// Session ID
142    pub session_id: String,
143    /// Breakpoint address (hex string like "0x8000000" or decimal)
144    pub address: String,
145}
146
147
148// =============================================================================
149// Flash Programming Types
150// =============================================================================
151
152
153
154// =============================================================================
155// New Flash Programming Types
156// =============================================================================
157
158#[derive(Debug, Deserialize, JsonSchema)]
159pub struct FlashEraseArgs {
160    /// Session ID
161    pub session_id: String,
162    /// Erase type: "all" for full chip, "sectors" for specific sectors
163    #[serde(default = "default_erase_all")]
164    pub erase_type: String,
165    /// Start address for sector erase (hex string like "0x8000000" or decimal)
166    pub address: Option<String>,
167    /// Size in bytes for sector erase
168    pub size: Option<u32>,
169}
170
171fn default_erase_all() -> String { "all".to_string() }
172
173#[derive(Debug, Deserialize, JsonSchema)]
174pub struct FlashProgramArgs {
175    /// Session ID
176    pub session_id: String,
177    /// Path to file to program (ELF, HEX, BIN)
178    pub file_path: String,
179    /// File format: "auto", "elf", "hex", "bin"
180    #[serde(default = "default_auto_format")]
181    pub format: String,
182    /// Base address for BIN files (hex string or decimal)
183    pub base_address: Option<String>,
184    /// Whether to verify after programming
185    #[serde(default = "default_true")]
186    pub verify: bool,
187}
188
189fn default_auto_format() -> String { "auto".to_string() }
190
191#[derive(Debug, Deserialize, JsonSchema)]
192pub struct FlashVerifyArgs {
193    /// Session ID
194    pub session_id: String,
195    /// File path to verify against (optional)
196    pub file_path: Option<String>,
197    /// Hex data to verify against (alternative to file_path)
198    pub data: Option<String>,
199    /// Address to start verification (hex string or decimal)
200    pub address: String,
201    /// Number of bytes to verify
202    pub size: u32,
203}
204
205#[derive(Debug, Deserialize, JsonSchema)]
206pub struct RunFirmwareArgs {
207    /// Session ID
208    pub session_id: String,
209    /// Path to firmware file
210    pub file_path: String,
211    /// File format: "auto", "elf", "hex", "bin"
212    #[serde(default = "default_auto_format")]
213    pub format: String,
214    /// Whether to reset after flashing
215    #[serde(default = "default_true")]
216    pub reset_after_flash: bool,
217    /// Whether to attach RTT after reset
218    #[serde(default = "default_true")]
219    pub attach_rtt: bool,
220    /// RTT attach timeout in milliseconds
221    #[serde(default = "default_rtt_timeout")]
222    pub rtt_timeout_ms: u32,
223}
224
225fn default_rtt_timeout() -> u32 { 3000 }
226
227// =============================================================================
228// RTT Communication Types
229// =============================================================================
230
231#[derive(Debug, Deserialize, JsonSchema)]
232pub struct RttAttachArgs {
233    /// Session ID
234    pub session_id: String,
235    /// RTT control block address (optional, auto-detected if not provided)
236    pub control_block_address: Option<String>,
237    /// Memory ranges to search for RTT control block
238    /// Each range is a tuple of (start_address, end_address)
239    pub memory_ranges: Option<Vec<MemoryRange>>,
240}
241
242#[derive(Debug, Deserialize, JsonSchema)]
243pub struct MemoryRange {
244    pub start: String,
245    pub end: String,
246}
247
248#[derive(Debug, Deserialize, JsonSchema)]
249pub struct RttDetachArgs {
250    /// Session ID
251    pub session_id: String,
252}
253
254#[derive(Debug, Deserialize, JsonSchema)]
255pub struct RttReadArgs {
256    /// Session ID
257    pub session_id: String,
258    /// RTT channel number (usually 0 for default output)
259    #[serde(default)]
260    pub channel: u32,
261    /// Maximum bytes to read
262    #[serde(default = "default_max_bytes")]
263    pub max_bytes: usize,
264    /// Timeout in milliseconds
265    #[serde(default = "default_timeout_ms")]
266    pub timeout_ms: u64,
267}
268
269fn default_max_bytes() -> usize { 1024 }
270fn default_timeout_ms() -> u64 { 1000 }
271
272#[derive(Debug, Deserialize, JsonSchema)]
273pub struct RttWriteArgs {
274    /// Session ID
275    pub session_id: String,
276    /// RTT channel number (usually 0 for default input)
277    #[serde(default)]
278    pub channel: u32,
279    /// Data to write
280    pub data: String,
281    /// Data encoding: "utf8", "hex", "binary"
282    #[serde(default = "default_encoding")]
283    pub encoding: String,
284}
285
286fn default_encoding() -> String { "utf8".to_string() }
287
288#[derive(Debug, Deserialize, JsonSchema)]
289pub struct RttChannelsArgs {
290    /// Session ID
291    pub session_id: String,
292}
293
294// =============================================================================
295// Response Types (for internal use)
296// =============================================================================
297
298#[derive(Debug, Serialize)]
299pub struct ProbeInfo {
300    pub identifier: String,
301    pub vendor_id: u16,
302    pub product_id: u16,
303    pub serial_number: Option<String>,
304    pub probe_type: String,
305    pub speed_khz: u32,
306    pub version: String,
307}
308
309#[derive(Debug, Serialize)]
310pub struct TargetInfo {
311    pub chip_name: String,
312    pub architecture: String,
313    pub core_type: String,
314    pub memory_map: Vec<MemoryRegion>,
315}
316
317#[derive(Debug, Serialize)]
318pub struct MemoryRegion {
319    pub name: String,
320    pub start: u64,
321    pub size: u64,
322    pub access: String,
323}
324
325#[derive(Debug, Serialize)]
326pub struct CoreInfo {
327    pub pc: u64,
328    pub sp: u64,
329    pub state: String,
330    pub halt_reason: Option<String>,
331}
332
333#[derive(Debug, Serialize)]
334pub struct SessionStatus {
335    pub session_id: String,
336    pub connected: bool,
337    pub target_state: String,
338    pub created_at: String,
339    pub last_activity: String,
340}
341
342#[derive(Debug, Serialize)]
343pub struct RegisterValue {
344    pub name: String,
345    pub value: u64,
346    pub description: Option<String>,
347}
348
349#[derive(Debug, Serialize)]
350pub struct Breakpoint {
351    pub id: u32,
352    pub address: u64,
353    pub breakpoint_type: String,
354    pub enabled: bool,
355}
356
357#[derive(Debug, Serialize)]
358pub struct FlashResult {
359    pub bytes_programmed: usize,
360    pub programming_time_ms: u64,
361    pub verification_result: bool,
362}
363
364#[derive(Debug, Serialize)]
365pub struct RttChannelInfo {
366    pub channel: u32,
367    pub name: String,
368    pub direction: String, // "up", "down"
369    pub buffer_size: usize,
370    pub flags: u32,
371}